【问题标题】:cv2 videoCapture has no attributecv2 videoCapture 没有属性
【发布时间】:2020-12-25 05:51:31
【问题描述】:
import cv2

import sys


cpt=0

vidStream=cv2.videoCapture(0)
while True:
    ret,frame=vidStream.read()

    cv2.imshow("test frame",frame)
    cv2.imwrite(r"C:\Users\Abhishek\PycharmProjects\images\0\image%04i.jpg"%cpt,frame)
    cpt +=1

    if cv2.waitKey(10)==ord('q'):
        break

请任何人帮我解决错误 我收到一条错误消息,提示“模块 'cv2.cv2' 没有属性 'videoCapture'”和“无法导入 cv2”

【问题讨论】:

标签: python opencv cv2


【解决方案1】:

请安装

pip install opencv-pythonpip install opencv-contrib-python 然后运行下面的代码....

import cv2
import sys
cpt=0
vidStream=cv2.videoCapture(0)
while True:
    ret,frame=vidStream.read()
    cv2.imshow("test frame",frame)
    cv2.imwrite(r"C:\Users\Abhishek\PycharmProjects\images\0\image%04i.jpg"%cpt,frame)
    cpt +=1
    if cv2.waitKey(10)==ord('q'):
        break

【讨论】:

    【解决方案2】:

    1) 不是 cv2.videoCapture() 而是尝试 cv2.VideoCapture()。

    Python 2.7.18rc1 (default, Apr  7 2020, 12:05:55) 
    [GCC 9.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import cv2
    >>> vid = cv2.videoCapture(0)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'videoCapture'
    >>> vid = cv2.VideoCapture(0) #like that it works fine.
    >>> 
    
    

    尝试使用pip install opencv-pythonpip install opencv-contrib-python命令安装opencv,看看是否仍然出现“无法导入cv2”的错误

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 2021-06-11
      • 2022-06-10
      • 2018-06-21
      • 2020-06-04
      • 2019-08-14
      • 1970-01-01
      • 2020-09-01
      • 2018-04-23
      相关资源
      最近更新 更多