gpt4 book ai didi

python - 无法使用网络摄像头读取帧。错误-2147483638

转载 作者:行者123 更新时间:2023-12-05 02:56:23 25 4
gpt4 key购买 nike

我想在 python 上使用 help opencv 从网络摄像头读取视频,但我有下一个错误:

'NoneType' object has no attribute 'shape'.

在控制台中我有:[WARN:0] videoio(MSMF):无法抓取帧。错误:-2147483638

print("starting video stream...")
vs = VideoStream(src=0).start()
time.sleep(2.0)

while True:
frame = vs.read()
frame = imutils.resize(frame, width=600) #'NoneType' object has no attribute 'shape'

if W is None or H is None:
(H, W) = frame.shape[:2]

cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF

if key == ord("q"):
break

cv2.destroyAllWindows()
vs.stop()

我能解决这个问题吗?谢谢!

最佳答案

相机的默认 MSMF api 不适用于 opencv 4.2.0.34,但适用于 opencv 3。切换到 DSHOW api 有效

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)

关于python - 无法使用网络摄像头读取帧。错误-2147483638,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60597036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com