简体   繁体   English

OpenCV 找不到用于网络摄像头的 VideoCapture 或在 Windows 10 上显示

[英]OpenCV does not find VideoCapture for webcam or show on Windows 10

Webcam capture does not show when the data is read读取数据时不显示网络摄像头捕获

I tried video_capture= cv2.VideoCapture() method for both, 0 and 700 as argument, because of suggestions and this happened:由于建议,我尝试将video_capture= cv2.VideoCapture()方法作为参数 0 和 700 作为参数,结果发生了:

  • 0 gives out the error; 0 给出错误; CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. CvCapture_MSMF::grabFrame videoio(MSMF):无法抓取帧。
  • 700 gives out a blank screen only first row of pixels are filled; 700 显示空白屏幕,仅填充第一行像素;
  • video_capture = cv2.VideoCapture(700) works only when I debug and breakpoint at cv2.imshow("Capturing", gray). video_capture = cv2.VideoCapture(700)仅当我在 cv2.imshow("Capturing", gray) 处调试和断点时才有效。 Screen shows a snapshot of a webcam video, however runtime shows the following image;屏幕显示网络摄像头视频的快照,但运行时显示以下图像;
  • Video screen视频画面
  • I have tried on my mac with the same python file, it worked perfectly fine.我已经在我的 mac 上尝试过使用相同的 python 文件,它运行得非常好。 There is something wrong with Windows 10 that I can't figure out.我无法弄清楚 Windows 10 有什么问题。

======= ========

import cv2

# Create an object. 700 for my external camera
video_capture = cv2.VideoCapture(700)
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH,640)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT,480)

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')


while True:

    ret, frame = video_capture.read()

    #Check if the video is being read
    if ret == False:
        print("Connection Failed!")
    else:

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.1,
            minNeighbors=5,
            minSize=(30, 30),
            flags=cv2.CASCADE_SCALE_IMAGE
        )

        # Draw a rectangle around the faces
        for (x, y, w, h) in faces:
            cv2.rectangle(gray, (x, y), (x+w, y+h), (0, 255, 0), 2)

        # Display the resulting frame
        cv2.imshow('Video', gray)
        
        if cv2.waitKey(1)==ord('e'):
            break

video_capture.release()
cv2.destroyAllWindows()

Kaspersky seemed to block my live webcam capture on terminal running code so on pycharm I have enabled, Run with Python Console.卡巴斯基似乎在终端运行代码上阻止了我的实时网络摄像头捕获,因此在我启用的 pycharm 上,使用 Python 控制台运行。 Everything is working fine now.现在一切正常。 Pycharm Console Config Pycharm 控制台配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python OpenCV VideoCapture将不会显示网络摄像头图像 - Python OpenCV VideoCapture won't show webcam images OpenCV cv2.VideoCapture(0)与网络摄像头无法正常工作 - OpenCV cv2.VideoCapture(0) is not working well with webcam Python - OpenCV VideoCapture = False(Windows) - Python - OpenCV VideoCapture = False (Windows) OpenCV 2.4 VideoCapture在Windows上不起作用 - OpenCV 2.4 VideoCapture not working on Windows (使用 Python 的 OpenCV)使用 VideoCapture(1)/外部网络摄像头时出现不希望的自动旋转行为 - (OpenCV with Python) Undesired autorotation behaviour when using VideoCapture(1) / External webcam OpenCV(3.3.0)在带有视频的VideoCapture上返回失败,但可用于网络摄像头[OS X] - OpenCV (3.3.0) returns fail on VideoCapture with Video but works with Webcam [OS X] 使用 python 和 OpenCV 与 VideoCapture 深入了解多个网络摄像头捕获 - Insight on Multiple Webcam Capture with python and OpenCV vs VideoCapture OpenCV Python:cv2.VideoCapture只能找到3个摄像头中的2个,Windows Camera app找到全部 - OpenCV Python: cv2.VideoCapture can only find 2 of 3 cameras, Windows Camera app finds all OpenCV - VideoCapture(filename) 适用于 Java,但不适用于 Python (Windows 7) - OpenCV - VideoCapture(filename) works in Java but not in Python (Windows 7) OpenCV VideoCapture(FILE)不起作用WINDOWS - OpenCV VideoCapture(FILE) don't work WINDOWS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM