You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: OPENCV_EXTRA_MODULES_PATH is a full path to the opencv_contrib directory (plus /modules) that you created in a previous step.
Note this disclaimer from OpenCV:
Update 2018-11-27: Notice the -D OPENCV_ENABLE_NONFREE=ON flag. Setting this flag with OpenCV 4 ensures that you’ll have access to SIFT/SURF and other patented algorithms.
Verify Python 3 interpreter and numpy library are coming from the pipenv virtual env location
e.g. for Python 3: /home/pi/.local/share/virtualenvs/cv-lRcGL5pf/bin/python
Backup Image File
TODO: This may be a good time to backup the .img file to have a stored starting point.
Increase Swap File Size
Edit the swap file config:
sudo nano /etc/dphys-swapfile
Change:
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
* Increases the swap file size to 2048MB
* The latest PyImageSearch instructions use a `CONF_SWAPSIZE` of 1024. But, I've kept it at 2048.
Restart swap service:
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
Build
Run the make command across 4 cores:
make -j4
If this is unsuccessful, you can run make (wihthout -j4) to run single threaded. I was able to run this with multiple cores (with -j4)
Install library:
sudo make install
sudo ldconfig
Undo Swap File Changes
Set swap file back to its previous configuration settings
Restart swap service
Link OpenCV Into Your Virtual Environment
This step must be repeated for each Python virtual environment (which you create with pipenv) that you'd like to use import cv2
Go to the virtual environment location:
e.g. cd ~/.local/share/virtualenvs/cv-lRcGL5pf/lib/python3.7/site-packages
link to the library:
e.g. ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so cv2.so
The first argument after ln -s is the location of the OpenCV library which we just built. Make sure the path is correct.
Test the Install
Go to your virtual environment, if you're not already there, and activate it
e.g. cd ~/work/cv
pipenv shell
Start a Python console: python
Import OpenCV: import cv2
There should be no errors, you should see the prompt (after a wait): >>>
Verify the OpenCV version: cv2.__version__
You should see the version we build: 4.1.1
Viewing GUI Via SSH
On Mac, use XQuartz to view images via SSH connection