简体   繁体   English

在python中使用OpenCV加载视频

[英]load Video Using OpenCV in python

Here is my code which is running...but I didnt understood why we used: 这是我的代码正在运行...但是我不明白为什么要使用:

if cv2.waitKey(1000) & 0xFF == ord('q'):
        break

in the code......under display the resulting frame comment: 在代码中……在下面显示生成的框架注释:

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 displays the image for the specified number of milliseconds. waitkey将图像显示指定的毫秒数。 Without it, you actually wouldn't be able to see anything. 没有它,您实际上将看不到任何东西。 Then 0xFF == ord('q') detects when the keystroke q is pressed on the keyboard. 然后0xFF == ord('q')检测何时在键盘上按下了按键q。

Think of waitkey as a pause function. waitkey视为暂停功能。 After the code has been executed; 执行代码后; at lightning speed :), waitkey says, pause for 1000 milliseconds to display the frame. waitkey以闪电般的速度:)暂停1000毫秒以显示该帧。 Within this, detect if the user pressed q. 在此范围内,检测用户是否按了q。 If q is pressed, then get outside of my infinite while loop. 如果按q,则进入我的无限while循环之外。 When this happens, then the window won't be shown anymore. 发生这种情况时,该窗口将不再显示。

Their documentation is a good resource as well. 他们的文档也是很好的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM