Raspberry Pi 3 and Opencv 3 Installation Tutorial
We’re going to see today how to install opencv on the raspberry pi 3 Model b+ (with camera).
1) Update os system:
sudo apt-get update sudo apt-get upgrade
2) Install dependencies:
3) Install Python 3 and Pip3:
sudo apt-get install python3-dev sudo apt-get install python3-pip
4) Install Opencv:
pip3 install opencv-python
5) Extra depencies for Opencv and the Camera:
sudo apt-get install libqtgui4 sudo modprobe bcm2835-v4l2 sudo apt-get install libqt4-test
14 Comments
-
- sittikorn April 21, 2019 at 6:53 pm
Please add last step:
sudo apt install libqt4-test
- Sergio Canu April 26, 2019 at 6:07 pm
Thanks, I forgot about it.
- Andre Yoshimura May 12, 2019 at 1:37 pm
Thank U, Amazing code!!1
- Mgilraj May 23, 2019 at 12:18 pm
Hello sir ,
I’m trying to install opencv on rpi 3 b+. while putting “pip3 install opencv-python” it shows like this
[
Collecting opencv-python
Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
]
what should i do?
Thanks,
Mugil
- Sergio Canu June 1, 2019 at 9:47 pm
It could be that raspberry is not able to connect to the server to download an opencv version compatible.
I found that a problem can be that the time of your raspberry pi isn’t synchronized with the real time and the server refuses the connection.
- Bao Pham July 11, 2019 at 4:26 am
I can’t fix it.
- Bao July 11, 2019 at 5:04 am
Hi guy, Please help me if you fixed it. [email protected]
- Craig June 10, 2019 at 3:00 am
Hi Sergio, thanks for this tutorial.
I’m also installing on a Pi 3 B+, and the dependency steps took me around the same time as yours did on the video.
I started step 4 and it has proceeded to the point that you paused the video. So I’m wondering how long your step 4 took?
My Pi has been running for several hours with no change to the screen, and I’m wondering if I should be leaving it running? The Pi is clearly doing something as even moving the mouse cursor takes a while to respond.
Thanks.
- Craig June 10, 2019 at 3:34 am
Hi Sergio,
Ignore that last comment. I powered the Pi off and back up, repeated the steps to make sure I hadn’t mistyped anything and this time it worked! And that step 4 only took a few minutes this time.
I am now happily detecting faces and eyes, and just need to work out why I can’t detect smiles and I’ll be happy. Perhaps it doesn’t like my face *grin*.
Thanks.
- Naseeb Gill June 11, 2019 at 10:40 am
Hi Sergio,
I installed opencv using your tutorial and it installed correctly as I am able to import cv2 in python idle 3 as well as in terminal.
But, my problem is little bit different. When I run below code it shows error.
import cv2
import numpy as np
import imutils
from imutils.video import WebcamVideoStream
from imutils.video import VideoStream
cam1 = WebcamVideoStream(src=0).start()
cam2 = WebcamVideoStream(src=2).start()
while (1):
frame1 = cam1.read()
cv2.imshow(“frame1”,frame1)
frame2 = cam2.read()
cv2.imshow(“frame2”,frame2)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cam1.release()
cam2.release()
cv2.destroyAllWindows()
It shows error :
VIDIOC_QBUF: Invalid argument
VIDIOC_QBUF: Invalid argument
Traceback (most recent call last):
VIDIOC_QBUF: Invalid argument
File “camm11.py”, line 14, in
cv2.imshow(“frame1”,frame1)
cv2.error: OpenCV(3.4.4) /home/pi/packaging/opencv-python/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’
I am trying to run two webcams using raspberry pi 3 B+. I am using USB power hub to connect webcams.
Please help me how to solve this error.
Thank you.
- Luis G June 16, 2019 at 10:39 am
Hi, nice code! but in my raspberry pi 3 plus i recive this message when i put (pip3 install opencv-python)
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permiso denegado: ‘/usr/local/lib/python3.5/dist-packages/cv2’
Consider using the `–user` option or check the permissions.
Any body can i help me?
Thanks
- Sergio Canu June 16, 2019 at 11:51 am
You need administrator permissions tu install opencv.
so instead of pip3 install opencv-python, type:
sudo pip3 install opencv-python
- Jairo Reyes June 22, 2019 at 5:38 pm
Hi Sergio, thanks for this amazing tutorial. I have just one error when i run the command ” sudo modprobe bcm2835-v4l2 ” it tells me
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file ‘/lib/modules/4.14.98-v7+/modules.dep.bin’
modprobe: FATAL: Module bcm2835-v4l2 not found in directory /lib/modules/4.14.98-v7+
I’ll use OpenCV to recognize a circle taking the Raspberry Pi Camera as input. ¿Do I really need this command to my purpose? tried to install open cv in my raspberry pi using your commands but I’m getting errors pls help me to install open cv and other packages open cv was installed in my pi but getting an error while importing cv2, and imutils, I trayed the code
sudo apt-get install libqtgui4 install open cv still its showing error pls help me it install open cv and other packages imutils , requests , json , base64