【发布时间】:2020-09-16 05:04:03
【问题描述】:
我正在尝试在我的 Raspberry pi 中使用我的代码,但我只能在计算机上看到摄像头的图像我已经可以看到两个 USB 摄像头的图像有人知道发生了什么,你能帮忙吗我?
import threading
class camThread(threading.Thread):
def __init__(self, previewName, camID):
threading.Thread.__init__(self)
self.previewName = previewName
self.camID = camID
def run(self):
print ("Starting " + self.previewName)
camPreview(self.previewName, self.camID)
def camPreview(previewName, camID):
cv2.namedWindow(previewName)
cam = cv2.VideoCapture(camID)
if cam.isOpened(): # try to get the first frame
rval, frame = cam.read()
else:
rval = False
while rval:
cv2.imshow(previewName, frame)
rval, frame = cam.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow(previewName)
thread1 = camThread("Camera 1", 0)
thread2 = camThread("Camera 2", 1)
thread1.start()
thread2.start()
外壳:
Python 3.7.3 (/usr/bin/python3)
>>> %Run cameraa.py
Starting Camera 1Starting Camera 2
/*error*/
>>> Xlib: charsets ISO8859-1:GR and ISO8859-1:GR have the same CT sequence
Xlib: charsets JISX0201.1976-0:GR and JISX0201.1976-0:GR have the same CT sequence
Xlib: charsets JISX0212.1990-0:GL and JISX0212.1990-0:GL have the same CT sequence
Xlib: charsets CNS11643.1986-1:GR and CNS11643.1986-1:GR have the same CT sequence
Xlib: charsets CNS11643.1992-3:GR and CNS11643.1992-3:GR have the same CT sequence
Xlib: charsets CNS11643.1992-5:GR and CNS11643.1992-5:GR have the same CT sequence
Xlib: charsets CNS11643.1992-7:GR and CNS11643.1992-7:GR have the same CT sequence
Xlib: charsets BIG5-E0:GL and BIG5-E0:GL have the same CT sequence
[ WARN:0] global /home/pi/opencv_build/opencv/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video1): can't open camera by index
【问题讨论】:
标签: python python-3.x raspberry-pi raspbian raspberry-pi4