-
1Building OpenCV from source for Raspberry Pi
1. Downloading pre-built OpenCV4
wget https://github.com/sol-prog/raspberry-pi-opencv/releases/download/opencv4rpi2.1/opencv-4.1.0-armhf.tar.bz2
2. Extract the archive
tar xvf opencv-4.1.0-armhf.tar.bz2
3. Move the extracted archive to the /opt folder
sudo mv opencv-4.1.0 /opt
4. Remove the archive (optional)
rm opencv-4.1.0-armhf.tar.bz2
5. Install video and image support packages
sudo apt install libjpeg-dev libtiff-dev libjasper-dev libpng-dev libwebp-dev libopenexr-dev sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libdc1394-22-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
6. Install packages needed for OpenCV's interface
sudo apt install libgtk-3-dev libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
7. Install other OpenCV related packages
sudo apt install libatlas-base-dev liblapacke-dev gfortran
8. Add OpenCV to the system path
cd ~ echo 'export LD_LIBRARY_PATH=/opt/opencv-4.1.0/lib:$LD_LIBRARY_PATH' >> .bashrc . .bashrc
9. Restart the terminal or log back into the RPi if using a SSH
10. Install git if necessary
sudo apt-get install git
11. Clone a config file to use OpenCV for C++
git clone https://gist.github.com/sol-prog/ed383474872958081985de733eaf352d opencv_cpp_compile_settings cd opencv_cpp_compile_settings/ sudo cp opencv.pc /usr/lib/arm-linux-gnueabihf/pkgconfig cd ~ rm -rf opencv_cpp_compile_settings/
12. Check OpenCV has installed and been correctly added to the system path
pkg-config --modversion opencv
-
2Building an OpenCV Project In C++
1. Install CMake on the Raspberry Pi
sudo apt-get -y install cmake
2. Save the following under CMakeLists.txt (within the same directory as the project)
cmake_minimum_required(VERSION 2.8) project( Project ) find_package( OpenCV REQUIRED ) include_directories( ${OpenCV_INCLUDE_DIRS} ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") add_executable( Project main.cpp ) target_link_libraries( Project ${OpenCV_LIBS} )
3. Run cmake then make, and finally the output file
$ cmake . .... $ make ... $ ./Project
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.