Python Opencv双摄像机源
我和opencv一起工作,有两个视频源。我正在使用以下代码。代码有时工作,有时不工作。我的代码有问题吗。我怎样才能弥补Python Opencv双摄像机源,python,python-3.x,Python,Python 3.x,我和opencv一起工作,有两个视频源。我正在使用以下代码。代码有时工作,有时不工作。我的代码有问题吗。我怎样才能弥补 import cv2 Channel0 = cv2.VideoCapture(0) IsOpen0, Image0 = Channel0.read() Channel1 = cv2.VideoCapture(1) IsOpen1, Image1 = Channel1.read() while IsOpen0 and IsOpen1: IsOpen0, Image0
import cv2
Channel0 = cv2.VideoCapture(0)
IsOpen0, Image0 = Channel0.read()
Channel1 = cv2.VideoCapture(1)
IsOpen1, Image1 = Channel1.read()
while IsOpen0 and IsOpen1:
IsOpen0, Image0 = Channel0.read()
IsOpen1, Image1 = Channel1.read()
cv2.imshow("Webcamera",Image0)
cv2.imshow("Panasonic",Image1)
cv2.waitKey(10)
PS当我只使用一个视频源时,它总是起作用。我想我发现了我的错误。出于某种原因,下面的代码可以工作。一定是线程问题
你能解释一下当它不起作用时它会做什么吗?
import thread
import time
import cv2
def Webcamera():
Channel0 = cv2.VideoCapture(0)
IsOpen0, Image0 = Channel0.read()
while IsOpen0:
IsOpen0, Image0 = Channel0.read()
cv2.imshow("Webcamera",Image0)
cv2.waitKey(10)
if not IsOpen0:
time.delay(0.5)
print "Error opening Web camera"
def Panasonic():
Channel1 = cv2.VideoCapture(1)
IsOpen1, Image1 = Channel1.read()
while IsOpen1:
IsOpen1, Image1 = Channel1.read()
cv2.imshow("Panasonic",Image1)
cv2.waitKey(10)
if not IsOpen1:
time.sleep(0.5)
print "Error opening Panasonic"
try:
thread.start_new_thread(Webcamera,())
thread.start_new_thread(Panasonic,())
except:
print "Error: unable to start thread"
while 1:
pass