Installing OpenCV4 on Raspberry Pi

As a beginner, I want to install OpenCV4 on my new Pi 3B+, and tried to install with pip as follows: (based on https://www.pantechsolutions.net/blog/installing-library-packages-in-raspberry-pi/)
sudo apt install libqtgui4
sudo apt install libqt4-test
sudo pip3 install opencv-contrib-python
Although I get a message “Successfully installed opencv-contrib-python-3.4.4.19”, when I import cv2 in Thonny, I get messages like “ImportError:Libhdf5_serial.so.100: cannot open shared object file: No such file or directory” I then Googled a fix, but other similar errors occur like “ImportError: libjasper.so.1: cannot open file …” keep occuring.
I’m out of my depth here; is there an easy solution or an alternative approach to installing OpenCV4 on a Raspberry Pi?
Richard

1 Like

Hi Richard,

OpenCV4 has many dependent libraries and modules that you will need to install along side it. Those errors are just identifying those missing parts. There is not an easier way to install it unfortunately. First off start with a clean image, then follow this guide:
https://www.learnopencv.com/install-opencv-4-on-raspberry-pi/

1 Like

Thanks Stephen.

2 Likes

I managed to (pip) install OpenCV 3.4.4 on my Pi, and run a MOSSE tracker (https://www.learnopencv.com/object-tracking-using-opencv-cpp-python/) with the Picam at 100 fps. My next challenge is to use this tracker’s bounding box coordinates as input to drive a dc motor (not a servo) for x axis pan. Despite many google searches, I have not been able to make progress with the code. Any suggestions?

Hi Richard,

I’m not sure how you would go about that, maybe someone in the community had used OpenCV before and can help!