Skip to content

Instantly share code, notes, and snippets.

@alien18331
Last active July 20, 2020 03:25
Show Gist options
  • Save alien18331/d127a3f75833cb3a082f1369bdc9ef1d to your computer and use it in GitHub Desktop.
Save alien18331/d127a3f75833cb3a082f1369bdc9ef1d to your computer and use it in GitHub Desktop.
OpenCV-4.1.1 on RPI4
Step #1: Expand filesystem and reclaim space
The first step is to run, raspi-config and expand your filesystem:
$ sudo raspi-config
“7 Advanced Options” -> “A1 Expand filesystem”
$ sudo reboot
deleting both Wolfram Engine and LibreOffice to reclaim ~1GB of space on your Raspberry Pi:
$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove
Step #2: Install dependencies
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-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 libfontconfig1-dev libcairo2-dev
$ sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
$ sudo apt-get install libgtk2.0-dev libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install python3-dev
Step #4b: Compile OpenCV 4 from source
download opencv & contrib
$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.1.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.1.zip
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ mv opencv-4.1.1 opencv
$ mv opencv_contrib-4.1.1 opencv_contrib
set swap file
$ sudo nano /etc/dphys-swapfile
> CONF_SWAPSIZE=2048
Save and exit via ctrl + x , y , enter .
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
install OpenCV
$ pip3 install numpy
$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D BUILD_EXAMPLES=OFF ..
$ make -j4
$ sudo make install
$ sudo ldconfig
FINISH!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment