Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果我在发布网络视频后再次访问它,OpenCV Python捕获将失败_Python_Opencv_Stream_Webcam - Fatal编程技术网

如果我在发布网络视频后再次访问它,OpenCV Python捕获将失败

如果我在发布网络视频后再次访问它,OpenCV Python捕获将失败,python,opencv,stream,webcam,Python,Opencv,Stream,Webcam,我正在开发一个多线程应用程序,用于从四个USB网络摄像头捕获图像。为了简单和早期开发,我使用Logitech C920,速度为640x480和30fps 我有一个简单的功能,打开一个相机,设置一些参数,然后释放相机。因为这是一个多线程应用程序,当按下按钮时,每个线程有四个线程在运行它。它工作得很好 def camParameter(previewName, camID): #Set camera object and set parameters start_time = tim

我正在开发一个多线程应用程序,用于从四个USB网络摄像头捕获图像。为了简单和早期开发,我使用Logitech C920,速度为640x480和30fps

我有一个简单的功能,打开一个相机,设置一些参数,然后释放相机。因为这是一个多线程应用程序,当按下按钮时,每个线程有四个线程在运行它。它工作得很好

def camParameter(previewName, camID):
    #Set camera object and set parameters
    start_time = time.time()
    cam_test = True
    while cam_test:  
        cam = cv2.VideoCapture(camID)  
        present_time = time.time()
        if present_time - start_time > 2:
            print("Could not open camera ", str(camID))
            break
        if cam.isOpened():
            cam_test=False

    width = 640
    height = 480
    fps = 30
    test_width = cam.get(3)
    test_height = cam.get(4)
    test_fps = cam.get(5)

    if test_width != width:
        cam.set(3,width) 
    if test_height != height:
        cam.set(4,height) 
    if test_fps != fps:
        cam.set(5,fps) 

    print("Parameters set for camera ", str(camID))
    cam.release()
但是,如果我再次调用该函数,或尝试打开摄影机以进行流式处理,则会出现以下错误:

VIDEOIO错误:V4L2:OpenCV不支持传入图像的像素格式 无法停止流:设备或资源正忙

我可以用GUVCviewer打开相机,或者拔下/重新插入相机以重新访问

你知道为什么第二次接触相机会导致这个问题,或者如何修复它吗


我已经核实了摄像机实际上是被释放的。我可以访问摄像头

我用GStreamer重新编译了openCV-它对多线程友好得多。

我已经尝试过了,效果很好。你能试着更新opencv吗?