Skip to content

Latest commit

 

History

History
83 lines (74 loc) · 2.11 KB

OpenCV_Installation_Guide.md

File metadata and controls

83 lines (74 loc) · 2.11 KB

OpenCV Installation Guide

This guide will show you how to install the latest version of OpenCV from source at Raspberry Pi platform.

Preparation for install

First of all, try sudo raspi-config and expand your file system.
After this please reboot your raspi. You just need to input sudo reboot on terminal.
(If you are using USB memory instead of SD card, you cannot expand file system, but it's ok.
Please go to next step.)

Uninstall unneeded packages.

sudo apt-get purge wolfram-engine
sudo apt-get purge libreoffice*
sudo apt-get clean
sudo apt-get autoremove

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 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  
sudo apt-get install libcanberra-gtk*  
sudo apt-get install libatlas-base-dev gfortran  
sudo apt-get install python2.7-dev  

Install OpenCV-4.0.0

cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.0.zip
unzip opencv.zip
rm opencv.zip

OK, you've downloaded OpenCV. This directory's size is around 1.8GB.

wget https://bootstrap.pypa.io/get-pip.py  
sudo python get-pip.py  
sudo rm -rf ~/.cache/pip  
pip install numpy  

Now, we build it.

cd ~/opencv-3.4.0/  
mkdir build  
cd build  
cmake -D CMAKE_BUILD_TYPE=RELEASE \  
    -D CMAKE_INSTALL_PREFIX=/usr/local \  
    -D ENABLE_NEON=ON \  
    -D ENABLE_VFPV3=ON \  
    -D BUILD_TESTS=OFF \  
    -D INSTALL_PYTHON_EXAMPLES=OFF \  
    -D BUILD_EXAMPLES=OFF ..  

And install.

make -j4  

The last commands.

sudo make install
sudo ldconfig

Check

make sure OpenCV is installed correctly by this command.

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

Reference

Optimizing OpenCV on the Raspberry Pi:
https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/