我正在使用安装在Windows 10(64位)上的opencv python我正在使用Minoru 3D网络摄像头。我写了一个代码,从双镜头相机上读取视频。我在这里有以下错误:
Traceback (most recent call last):
File "C:/Python27/pythoncode/reading a video from two lens", line 6, in <module>
if(cap & cap1):
TypeError: unsupported operand type(s) for &: 'cv2.VideoCapture' and 'cv2.VideoCapture'
代码:
import numpy as np
import cv2
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
cap1 = cv2.VideoCapture(1)
if(cap & cap1):
while(true):
ret, frame=cap.read()
cv2.imshow('bgr image',frame)
print ret
ret1, frame1=cap1.read()
cv2.imshow('image1',frame1)
print ret1
if cv2.waitKey(30)>=0:
break
cap.release()
cap1.release()
cv2.destroyAllWindows()
您的代码和错误消息非常难以阅读;请在每行代码前放四个空格,或者选择所有代码并按Ctrl+K,转动
Traceback(最后一次调用):文件"C:\Python27/pythoncode/从两个镜头读取视频",第6行,在if(cap&cap1)中:TypeError:不支持&:'的操作数类型cv2.VideoCapture'和'cv2.VideoCapture'导入numpy为np导入cv2导入matplotlib.pyplot为plt cap=cv2。VideoCapture(0)cap1=cv2。视频捕获(1)if(cap&cap1):while(true):ret,frame=cap.red()cv2.imshow('bgr image',frame)print ret ret1,frame1=cap1.read()cv2.imshow('image1',frame1)print ret1 if cv2.waitKey(30)>=0:break cap.release()cap1.release()cv2.destroyAllWindow()
进入
Traceback (most recent call last):
File "C:/Python27/pythoncode/reading a video from two lens", line 6, in <module>
if(cap & cap1):
TypeError: unsupported operand type(s) for &: 'cv2.VideoCapture' and 'cv2.VideoCapture'
import numpy as np
import cv2
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
cap1 = cv2.VideoCapture(1)
if(cap & cap1):
while(true):
ret, frame=cap.read()
cv2.imshow('bgr image',frame)
print ret
ret1, frame1=cap1.read()
cv2.imshow('image1',frame1)
print ret1
if cv2.waitKey(30)>=0:
break
cap.release()
cap1.release()
cv2.destroyAllWindows()
根据错误消息,错误发生在if(cap & cap1):
行,原因是您无法在两个cv2.VideoCapture
对象上使用运算符&
(按位and)。
我假设您正在尝试确保两个变量都不是None
,而这样做的方法是将行更改为:
if (cap != None) and (cap1 != None):