OpenCV视频采集结果
OpenCV video capture results
我正在学习有关 OpenCV 视频捕获的教程,但返回了我不理解的值。这是我的脚本:
import cv2, time
video=cv2.VideoCapture(0)
check, frame = video.read()
print(check)
print(frame)
time.sleep(3)
cv2.imshow("Capturing", frame)
cvw.waitKey(0)
video.release()
cv2.destroyAllWindows
当我 运行 脚本时,这些是我的结果:
False
None
Traceback (most recent call last):
File "capture.py", line 11, in <module>
cv2.imshow("Capturing", frame)
cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
我不知道为什么要返回“False”和“None”。
感谢您的帮助
第一次阅读之前需要一些延迟。
像这样插入延迟代码
import time
#if you use camera
#video=cv2.VideoCapture(0)
#if you use video file
video=cv2.VideoCapture('c:/1.avi')
time.sleep(3)
check, frame = video.read()
print(check)
print(frame)
使用以下代码连续读取相机的帧。
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
if frame.size != 0:
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
我正在学习有关 OpenCV 视频捕获的教程,但返回了我不理解的值。这是我的脚本:
import cv2, time
video=cv2.VideoCapture(0)
check, frame = video.read()
print(check)
print(frame)
time.sleep(3)
cv2.imshow("Capturing", frame)
cvw.waitKey(0)
video.release()
cv2.destroyAllWindows
当我 运行 脚本时,这些是我的结果:
False
None
Traceback (most recent call last):
File "capture.py", line 11, in <module>
cv2.imshow("Capturing", frame)
cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
我不知道为什么要返回“False”和“None”。
感谢您的帮助
第一次阅读之前需要一些延迟。 像这样插入延迟代码
import time
#if you use camera
#video=cv2.VideoCapture(0)
#if you use video file
video=cv2.VideoCapture('c:/1.avi')
time.sleep(3)
check, frame = video.read()
print(check)
print(frame)
使用以下代码连续读取相机的帧。
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
if frame.size != 0:
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()