Python | cv2 VideoCapture() method

In this tutorial, we will see how to read a video and start a webcam using python open-cv, which exists as cv2 (computer vision) library.

You can use VideoCapture() method of cv2 library to read and start live streaming. To use cv2 library, you need to import cv2 library using import statement.

Now let’s see the syntax and return value of cv2 canny() method first, then we will move on to the examples.

Syntax

Parameters

There is one argument which needs to pass in VideoCapture() class.

video_path: Locationvideo in your system in string form with their extensions like .mp4, .avi, etc.

OR

device index: It is just the number to specify the camera. Its possible values ie either 0 or -1.

Return value

Video capture object.

cv2 VideoCapture() method examples

Now Let’s see the Python code :

Example 1: Run a given video file.

Output :
output1

Example 2: Start a webcam.

Output:
output2

That’s all about Python cv2 VideoCapture() method,

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *