gpt4 book ai didi

python - OpenCV Python 错误断言失败(scn == 3 || scn == 4)

转载 作者:太空宇宙 更新时间:2023-11-03 21:27:34 26 4
gpt4 key购买 nike

我刚开始在 Python 中使用 OpenCV 并遇到断言错误。我从 tutorial 中复制了以下代码,但它对我不起作用。

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0) # use first webcam
if not cap.isOpened(): cap.open()

while True:
# capture frame-by-frame
ret, frame = cap.read()

# our operations on the frame come here
gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)

# display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
# when everything is done, release the capture
cap.release()
cv.destroyAllWindows()

运行时,我得到 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor

当从上面打印变量 retframe 时,我得到 (False,None),所以它甚至没有正确捕获帧.

到底是什么问题,我该如何解决?谢谢。

最佳答案

ret, frame = cap.read()之后,添加if not ret: continue

一些凸轮驱动程序返回无效的第一帧。

关于python - OpenCV Python 错误断言失败(scn == 3 || scn == 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22752002/

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