How to show videos frame by frame (with key presses) with python cv2?

How to show videos frame by frame (with key presses) with python cv2?

I am trying to open a video file and play it frame by frame using key presses. So it would open and show a single frame indefinitely until a particular key is pressed and then it would switch to the next frame.

I am trying to open a video file and play it frame by frame using key presses. So it would open and show a single frame indefinitely until a particular key is pressed and then it would switch to the next frame.

I'm using python3 and cv2. This is the first time I am using cv2 so any corrections/recommendations are welcome.

The code below works in the sense that it shows the video one frame at a time but not only when I press k but with any key press and it ignores the q to exit.

import cv2
import os


def play_video(folder): # load video capture from file video = cv2.VideoCapture(os.path.join(folder, "Field.mp4")) # window name and size cv2.namedWindow("video", cv2.WINDOW_AUTOSIZE) while video.isOpened(): # Read video capture ret, frame = video.read() # Display each frame cv2.imshow("video", frame) # show one frame at a time cv2.waitKey(00) == ord('k') # Quit when 'q' is pressed if cv2.waitKey(1) == ord('q'): break # Release capture object video.release() # Exit and distroy all windows cv2.destroyAllWindows()

play_video("bb-eye-s001")

I would like to press a specific key to move forward (one to move back too, but that might be for another question) and be able to press q to quit.

Any suggestions? Thank you in advance!

python video

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.

Standard Data Types in Python - Python Tutorial - Python Training

This video on 'Standard Data Types in Python' will help you establish a foothold on Python by helping you learn basic concepts.

Python Libraries You Must Learn in 2020-Learn Python-Python Training

This LIVE session on 'Python Libraries' will help you understand the topmost trending Python libraries toy must learn.