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!

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

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

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

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

What is new features in Javascript ES2020 ECMAScript 2020

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 GUI Programming Projects using Tkinter and Python 3

Python GUI Programming Projects using Tkinter and Python 3

Guide to Python Programming Language

Guide to Python Programming Language