我正在开发一个多线程应用程序来捕捉来自四个USB摄像头的图像。为了简单和早期开发,我在640x480和30fps上使用罗技C920。
我有一个简单的函数,打开相机,设置一些参数,然后释放相机。因为这是一个多线程应用程序,当按下一个按钮时,每个线程都在运行这个程序。效果很好。
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打开相机,也可以拔掉/复制相机以获得访问权限。
有什么想法,为什么第二次访问相机会导致这个问题,或如何解决它?
我已经证实相机是事实发布的。我可以接触到摄像机
发布于 2018-10-10 14:47:01
我用GStreamer重新编译了GStreamer--它对多线程更加友好。
https://stackoverflow.com/questions/52083714
复制相似问题