python - VideoCapture 显示“无摄像头访问”占位符图像
问题描述
我正在尝试显示来自相机的实时视频源。当我运行程序时, ret 返回 true 但 cv2.imshow() 显示占位符图像。任何帮助将不胜感激。
import numpy as np
from cv2 import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
#initialize video from the webcam
video = cv2.VideoCapture(0)
print(cv2.VideoCapture(0).isOpened()) # ->returns True
while True:
# ret tells if the camera works properly. Frame is an actual frame from the video feed
ret, frame= video.read()
if ret ==True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
# Draw the rectangle around each face
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
# Display
cv2.imshow('img', frame)
if cv2.waitKey(30) & 0xff==27:
break
video.release()
cv2.destroyAllWindows()
cv2.imshow('img', frame) 打开以下窗口。
所以,我检查了相机权限是否被允许,似乎已经被允许了。我正在使用 MacOS Big Sur(11.6 版)。
解决方案
推荐阅读
- python - 使用 numpy.where 中的多个列时 groupby 不起作用
- java - 如何在java中将Json文件转换为字符串数组
- c++ - code::blocks 不会自动完成来自“cstdlib”的关键字
- c# - MP3 播放器添加歌曲被窃听
- c++ - 教授在 main() 中放了另一个 main()
- python - 将下载的股票数据导出到 Excel 中带有股票代码名称的多个工作表
- hive - 是否可以通过使用 Hive Script SQL 中的分隔符来提取字符串的一部分?
- python - how to change herkou region from us to eu of a pre deployed app withou lossing any app data
- mongodb - 如何将 MongoDB 中的数据库连接到 Dialogflow?
- javascript - WordPress中的币安长空比率图表