cv2.imshow 不显示网络摄像头视频并且不打开任何 window

The cv2.imshow not showing webcam video and not opening any window

我在使用 OpenCV

显示 window 和 cam 捕获时遇到问题

当我 运行 脚本时,我看到摄像头正在工作,但是带有此摄像头的 window 没有显示在任何地方,我只有 Python 图标出现了,但它甚至无法点击。

设置:

我试过:

import cv2
import sys
import logging as log
import datetime as dt
from time import sleep

faceCascade = cv2.CascadeClassifier('/Users/***/Documents/GitHub/FaceAuth/haarcascade_frontalface_default.xml')
log.basicConfig(filename='webcam.log', level=log.INFO)

video_capture = cv2.VideoCapture(0)  # 0 for phone cam, 1 for pc cam
anterior = 0

while True:
    if not video_capture.isOpened():
        print('Unable to load camera.')
        sleep(5)
        pass

    # Capture frame-by-frame
    ret, frame = video_capture.read()

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

    faces = faceCascade.detectMultiScale(gray, 1.1, 4)

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

    if anterior != len(faces):
        anterior = len(faces)
        log.info("faces: " + str(len(faces)) + " at " + str(dt.datetime.now()))

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    # Display the resulting frame
    cv2.imshow('Video', frame)

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

这是我在调试断点中的变量,在 cv2.imshow('Video', frame)

之前

来自评论区@idonthaveaname:

Have you tried upgrading opencv to 4.4.0? Maybe it should work, 4.4.0 is the latest version.