Installing OpenCV 3.3.0 on Raspbian
Last updated
Was this helpful?
Last updated
Was this helpful?
In this tutorial we are going no only install opencv algo we are going to optimizing so we could have a great performance on terms of IA.
1. Expand filesystem
Remember that first we need to download and install on our raspberry pi.
The first step is to run, raspi-config and expand your filesystem:
After finish we need to reboot the Raspberry pi. From there we are goint to eliminate package that we are not goint to use, such as Wolfram Engine and LibreOffice so we can get ~ 1GB of space.
2. Install dependecies
This next command allow us to update and upgrade any existing packages, followed by installing dependecies, I/O libraries, and optimization packages for OpenCV
3. Download OpenCV source code
We need to get the OpenCV source code from opencv and opencv_contrib repositories. Following by unarchiving them:
* This tutorial we are mention the version 3.3.0 but with this command we are going to get the latest version of openCV.
4. Create Python virtual enviroment and install NumPY
We need to instal pip, virtualenv and virtualenvwrapper using the next commands:
Once we have virtualenv and virtualenvwrapper installed, we need to open up our ~/.profile and append the following lines to the bottom of the file.
After that we need to reload ~/.profile so the change can be apply to the current bash session.
Remember that is necessary to run source ~/.profile each time that you open a new terminal in your Pi so we can ensure that the system variable have been set properly.
Next we are going to create our Python3 virtual enviroment, for that:
In this line we define that the virtual enviroment it will be call cv and we are going to use python3.
Finally, we need to install NumPy into the Python virtual enviroment
5. Compile and install the optimized OpenCV library for Raspberry Pi
Remember that we are in the cv virtual enviroment, for that we use:
And from there configure your build:
In this part we need to incres the swap spaces. This will enable to compile OpenCV with all four cores of the Raspberry Pi without the compile hanging due to memory exhausting. For that wee need to open _dphys-swapfile _and edit the _CONF_SWAPSIZE _variable:
Notice that you will swap from 100MB to 1024MB. If you do not perform this step it's very likely that Rasp will hang.
From there, restart the swap service:
After updated the swap size, kick off the optimized OpenCV compile using all four cores:
Assuming OpenCV compiled without error, we can install your optimized version of OpenCV:
****Don't forget to go back and restore the value of /dphys-swapfile
Reset CONF_SWAPSIZE to 100MB.
6. Finish installing OpenCV on the Raspberry Pi
To sym-link cv2.so file into the cv virtual enviroment, for that we need to run the following commands:
7. Test OpenCV on Raspberry Pi
Access the cv virutal enviromen, fire up a Python shell and try to import the OpenCV library:
CONGRATULATION NOW YOU HAVE OPEN CV