如何在OpenCV Python中阅读Minoru 3d网络摄像头的视频?

时间:2016-07-17 10:47:48

标签: java python c opencv video

我正在开发安装在Windows 10(64位)上的opencv python 我正在使用Minoru 3D网络摄像头。我写了一个代码,从2镜头相机读取视频。我在这里有以下错误:

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()

1 个答案:

答案 0 :(得分:0)

您的代码和错误消息非常难以阅读;请在每行代码前放置四个空格,或选择所有代码并按Ctrl + K,转动

回溯(最近一次调用最后一次):文件&#34; C:/ Python27 / pythoncode /从两个镜头&#34;,第6行读取视频,在if(cap&amp; cap1)中:TypeError:不支持的操作数类型(s)for&amp;:&#39; cv2.VideoCapture&#39;和&#39; cv2.VideoCapture&#39; import numpy as np import cv2 import matplotlib.pyplot as plt cap = cv2.VideoCapture(0)cap1 = cv2.VideoCapture(1)if(cap&amp; cap1):while(true):ret,frame = cap.read() cv2.imshow(&#39; bgr图像&#39;,框架)print ret ret1,frame1 = cap1.read()cv2.imshow(&#39; image1&#39;,frame1)如果cv2.waitKey(30,则打印ret1) )&gt; = 0:break cap.release()cap1.release()cv2.destroyAllWindows()

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):
相关问题