Install Necessary Packages in ROS
Install raspicam_node
Detailed procedure can be found here
Installation
Detailed procedure can be found here
Add source to apt lists
sudo sh -c 'echo "deb https://packages.ubiquityrobotics.com/ubuntu/ubiquity xenial main" > /etc/apt/sources.list.d/ubiquity-latest.list'
Add signing key to trusted list
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C3032ED8
Run
sudo apt-get update
Build catkin_ws
Detailed procedure can be found here
Jump to next session if you have already installed catkin_ws
Install pre-built package
sudo apt-get install ros-kinetic-catkin
Source your environment
source /opt/ros/kinetic/setup.bash
Create a catkin workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
Source your workspace
nano ~/.bashrc
Add source ~/catkin_ws/devel/setup.bash
at the bottom of file.
OR
Run source devel/setup.bash
in terminal everytime before running any package in catkin_ws.
Build from Source
Go to your catkin_ws
cd ~/catkin_ws/src
Download the source for raspicam_node
git clone https://github.com/UbiquityRobotics/raspicam_node.git
Create recognizable file for ROS dependencies
sudo touch /etc/ros/rosdep/sources.list.d/30-ubiquity.list
sudo nano /etc/ros/rosdep/sources.list.d/30-ubiquity.list
Add the following line to the file
yaml https://raw.githubusercontent.com/UbiquityRobotics/rosdep/master/raspberry-pi.yaml
Run rosdep update
Install the ros dependencies
cd ~/catkin_ws
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y
Compile the code
catkin_make
Run the Node to Confirm Success Installation
Most of the camera in the current market shoud be Pi Camera v2
For a V2.x camera, run roslaunch raspicam_node camerav2_1280x960.launch
For a V1.x camera, run roslaunch raspicam_node camerav1_1280x720.launch
Install OpenCV
Detailed procedure can be found here. You may check the time estimation for each procedure in the link.
This part is tested workable on 3B and 3B+ only.
Warning: Compiling OpenCV is a CPU-intensive task. Make sure your Raspberry Pi has radiators and a fan (or place a powerful external fan next to it) in order to avoid overheating. The Raspberry Pi would not die from overheating, but overheating will throttle its CPU performance, potentially increasing build time.
Raspberry Pi will stop responding for several times. Reboot the Pi to continue its work.
Make sure you have enough time to stick with the Raspberry Pi.
Confirm OS is up-to-date
sudo apt-get update
sudo apt-get upgrade
Install useful utilities
sudo apt-get install screen
sudo apt-get install htop
Install dependencies
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
Install Python 3
sudo apt-get install python3-dev
Install pip3
sudo apt-get install python3-pip
Get OpenCV 3.2.0 source code
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.2.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
Install Numpy, Scipy
sudo pip3 install numpy scipy
Compile OpenCV
cd ~/opencv-3.2.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D BUILD_EXAMPLES=ON ..
Build OpenCV
The Raspberry Pi will overheat if there is no proper cooling. Reboot the Pi and run the command again if it overheated. The progress will be keep after reboot.
Use all 4 cores to build
make -j4
Once OpenCV builds successfully, continue the installation:
sudo make install
sudo ldconfig
sudo apt-get update
Reboot the Raspberry Pi after installation
sudo reboot
Confirm Success Installation
Open a terminal, type:
python3
Then run import cv2
and cv2.__version__
. The version of OpenCV will be shown.
Install aruco_gridboard
Detailed procedure can be found here
If OpenCV extra module failed to build, rebuild them with the following codes:
cd <opencv_build_directory>
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
make -j4
Rebuild vision_opencv
from source
Clone vision_opencv
in your catkin_ws/scr
and rebuild everything
cd ~/catkin_ws/src
git clone https://github.com/ros-perception/vision_opencv.git
cd ..
catkin_make -DOpenCV_DIR=/path-to-build-opencv-3.2
If building failed, try
catkin_make -DOpenCV_DIR=/path-to-build-opencv-3.2 -DENABLE_PRECOMPILED_HEADERS=OFF
Install dependancies if any of them is missing during the build
sudo apt-get install ros-kinetic-cv-bridge
sudo apt-get install ros-kinetic-vision-opencv
Check cv_bridge
version
Open a terminal and type:
cd ~/catkin_ws/devel/lib
ldd libcv_bridge.so | grep opencv
The following result should be shown:
libopencv_core.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_core.so.3.2 (0x00007f7acb240000)
libopencv_imgcodecs.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_imgcodecs.so.3.2 (0x00007f7acaffe000)
libopencv_imgproc.so.3.2 => /home/jokla/Software/opencv-3.2.0/build/lib/libopencv_imgproc.so.3.2 (0x00007f7ac97ca000)
Clone aruco_gridboard
I modify a lot of things start from here. If you want to know what have I done, following my instructions. If you just want it to work on your system, clone my fork for simplicity.
Simple build:
cd ~/catkin_ws/src
git clone https://github.com/AlphenLai/aruco_gridboard.git
cd ..
catkin_make
source devel/setup.bash
Then skip to the next session.
Detailed build:
Clone it into your catkin_ws and build with catkin_make
cd ~/catkin_ws/src
git clone https://github.com/jokla/aruco_gridboard.git
cd ..
catkin_make
source devel/setup.bash
The catkin_make should failed at this point.
Go to ~/catkin_ws/src/aruco_gridboard/data/detector_params.yml
and ~/catkin_ws/src/aruco_gridboard/src/node.cpp
Open them with text editor and replace cornerRefinementMethod
with doCornerRefinement
Confirm Success Installation
Add the new OpenCV to the path
cd ~/catkin_ws
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jokla/Software/opencv-3.2.0/build/lib/
Launch the detection node
roslaunch aruco_gridboard detection.launch