Posted on

Before reading this, you may want a simpler installation tutorial, which is here.

To be honest, I failed to write my own tutorial but found a nearly perfect one, click here to view it.

You should follow the tutorial I mentioned to install OpenCV 4 on your Raspberry Pi, but with some warm prompts:

Make Details

$ make -j4

When you run this command, you may find yourself stuck at 99% and it never seems to end, so you may cancel the process and make it again from where you are stuck, but with a single core.

$ make

And more interestingly, although you only have 4 cores on the Raspberry Pi, it is claimed(reference 8) you can actually run

$ make -j5

to obtain a faster make speed.

Run make in the background

When running some command like make, it may take a long time to finish, so running in the background can save you from dilemmas.

$ nohup make &

With this command, all the results will be in nohup.out in the same directory.

One More Thing

If your setup process are in the remote ssh command line, then you should run the following command in Raspberry Pi Command line if you are to use workon cv command in the Pi Graphical Interface.

$ source ~/.profile

Solution Possible Issues

virtualenvwrapper.sh missing (2019.04.29 Update)

An issue only occurs when using Raspbian in Virtual Machine

$ cd /usr/local/bin
$ sudo pip uninstall virtualenvwrapper
$ sudo pip install virtualenvwrapper

cmake fails because of ENABLE_* options (2019.04.29 Update)

An issue only found on Raspbian Virtual Machine

If you don’t notice the failure until make, you will find that make is unable to find the Makefile to continue the process.

Just remove the followin 2 ENABLE options:

ENABLE_NEON=ON
ENABLE_VFPV3=ON

so the cmake should look like this:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D BUILD_EXAMPLES=OFF ..

References:

  1. Book: 《树莓派开始,玩转Linux》( Learning Linux with Raspberry Pi )by Vamei & 周昕梓
  2. https://medium.com/tensorflow/tensorflow-1-9-officially-supports-the-raspberry-pi-b91669b0aa0
  3. https://www.raspberrypi.org/forums/viewtopic.php?t=197824
  4. https://stackoverflow.com/questions/29466663/memory-error-while-using-pip-install-matplotlib
  5. https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
  6. https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/
  7. https://stackoverflow.com/questions/12647266/where-is-virtualenvwrapper-sh-after-pip-install#answer-17897962
  8. https://unix.stackexchange.com/questions/208568/how-to-determine-the-maximum-number-to-pass-to-make-j-option#answer-483306

One Reply to “Install OpenCV 4.0.0 on Raspberry Pi with Python 3”

Leave a Reply

Your email address will not be published. Required fields are marked *