Linux, OpenCV, Programming, Raspberry Pi

OpenCV 3.4.3 + Raspberry Pi 3B+

Follow these steps to install OpenCV 3.4.3 on a Raspberry Pi 3B+:

1) Install these 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
$ sudo apt-get install python2.7-dev python3-dev

2) Get OpenCV

$ wget https://github.com/opencv/opencv/archive/3.4.3.zip
$ unzip 3.4.3.zip
$ rm 3.4.3.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.4.3.zip
$ unzip 3.4.3.zip

3) Build & Install OpenCV
NOTE 1: In the cmake line there is a path to the opencv_contrib modules folder, please replace this path with the correct one for your system.

NOTE 2: The make step will take like 8-10 hours and it will crash several times due to low virtual memory. Luckily it can resume from where it crashes so I kept repeating the make command until it finished.

sudo apt-get install python-pip
pip install numpy
$ cd ~/opencv-3.4.3/
$ 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=/home/pi/Desktop/OpenCV/opencv_contrib-3.4.3/modules -D BUILD_EXAMPLES=ON ..
$ make -j4
$ sudo make install
$ sudo ldconfig

4) Confirm OpenCV installation

$ python
>>> import cv2
>>> cv2.__version__
'3.4.3'

5) Voila!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s