[英]load Video Using OpenCV in python
这是我的代码正在运行...但是我不明白为什么要使用:
if cv2.waitKey(1000) & 0xFF == ord('q'):
break
在代码中……在下面显示生成的框架注释:
import numpy as np
import cv2
cap = cv2.VideoCapture('C:\\Users\\KRK\\Desktop\\Dec17thVideo.mp4')
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1000) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
waitkey
将图像显示指定的毫秒数。 没有它,您实际上将看不到任何东西。 然后0xFF == ord('q')
检测何时在键盘上按下了按键q。
将waitkey
视为暂停功能。 执行代码后; waitkey
以闪电般的速度:)暂停1000毫秒以显示该帧。 在此范围内,检测用户是否按了q。 如果按q,则进入我的无限while循环之外。 发生这种情况时,该窗口将不再显示。
他们的文档也是很好的资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.