It's a very rudimentary story ... Probably the right way to make a surveillance camera with a Raspberry Pi and a genuine camera module, not with a USB camera, but with a Raspberry Pi camera jessie version (motion + v4l2 driver)](https://qiita. If you load the bcm2835-v4l2.ko
kernel module as explained in com / rukihena / items / 95da3860f9ca86c39f8d), you should be able to do it by the following procedure, but I do not have the actual camera for Raspberry Pi, so I have confirmed it. not.
sudo apt-get install usbutils python3-opencv libcanberra-gtk3-module v4l-utils qv4l2
video
group, so use sudo adduser login name video
.qv4l2
to see if you can see the camera image.v4l2-ctl --list-formats-ext
.Make sure that the output of lsusb -t
has Class = Video, Driver = uvcvideo
pi@raspberrypi:~ $ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 3, If 3, Class=Audio, Driver=snd-usb-audio, 480M
|__ Port 2: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
|__ Port 2: Dev 3, If 2, Class=Audio, Driver=snd-usb-audio, 480M
|__ Port 2: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
|__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 4: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 4: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
If you run the following program as python3 capture.py
, the image from the camera will be displayed. If you use Ubuntu Mate Raspberry Pi, you cannot access / dev / video0, so please use sudo chmod a + rw / dev / video0
.
capture.py
import cv2
capture = cv2.VideoCapture(0)
if capture.isOpened() is False:
raise IOError
while(True):
try:
ret, frame = capture.read()
if ret is False:
raise IOError
cv2.imshow('frame',frame)
cv2.waitKey(1)
except KeyboardInterrupt:
#CTRL when finished+Press C
break
capture.release()
cv2.destroyAllWindows()
Recommended Posts