![]() |
VOOZH | about |
OpenCV is a computer vision library that contains various functions to perform operations on Images or videos. OpenCV library can be used to perform multiple operations on videos.
In this article, we will create a program with a click response on video output using events in OpenCV Python library. We will be using “cv2.EVENT_LBUTTONDOWN” in case whenever the left mouse button is clicked and “cv2.EVENT_RBUTTONDOWN” in case whenever the Right mouse button is clicked.
To use the OpenCV library in python, we need to install these libraries as a prerequisite:
To install these libraries, we need to run these pip commands in cmd:
pip install opencv-python pip install numpy
cv2.VideoCapture(0): For the first camera or webcam. cv2.VideoCapture(1): For the second camera or webcam. cv2.VideoCapture(“file name.mp4”): For video file
: It returns True or False based on whether or not our cap object has started capturing the frames.
cv2.waitkey(): This function of OpenCV allows users to display a window for given milliseconds or until any key is pressed. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed.
cap.read(): This function returns 2 values:-
A string representing the name of the window in which image to be displayed.
: It is the image or frame that is to be displayed.
: It doesn’t returns anything.