【问题标题】:Raspberry pi 4 with 2 cam USB树莓派 4 带 2 cam USB
【发布时间】: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


    【解决方案1】:

    同时与 X11(或任何其他 UI 后端)交互并不是一个好主意。详情请见here

    专门针对 OpenCV,您可以查看此问题:

    您应该只从“主”线程与 UI 交互。

    https://github.com/opencv/opencv/issues/8407

    因此,解决方法是仅在主线程上使用imshowwaitKey。 (而不是超过两个线程)。换句话说,将三个调用(两个imshows 和一个waitKey)移动到主线程,并同步对两个Mat 对象的访问,您可以用来在主线程和其他两个线程之间共享数据.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      相关资源
      最近更新 更多