cv2.destroyAllWindows()Īnd the above code will destroy all the windows that were created during this process. Whenever we meet this condition we will release the web camera from which we are capturing the frames and destroy the window that is created earlier using the imshow() method. The second part of the above statement specifies that the value captured is compared with the ASCII value of letter ‘q’ using the ord() function. This is the condition we will be using to know when the user wants to stop the video capture. This waitKey() method takes an argument of type integer denoting the number of seconds to wait for the key press. When the user presses a specific key we have to stop displaying the imshow() window and also stop accessing the video capture. To stop displaying a video stream, we use the cv2.waitKey() method which is a method that waits for the user's response through a key press. With this code, we can only capture a single frame, but a video is a stream of frames, hence this whole code should be placed in an indefinite loop like while loop. The imshow() method takes in two arguments, the first one is the Title to be displayed on the window, this argument is a string and the second argument is the frame to be displayed. Now to display this frame on a window we use the opencv library’s imshow() method. The second value is the captured frame, which is basically a numpy array. With this, you can know at the end of a video capture whether all the frames are captured correctly or not. The first value is a Boolean value representing whether a frame is captured correctly or not. The VideoCapture object has a method read(), which when executed starts accessing the camera stream and returns a tuple. Since a video is a stream of picture frames, using this VideoCapture object we will access the camera and retrieve each frame and display it on the screen. Thus the above statement will create a VideoCapture object and will return it, hence we are storing the value in a variable (here our variable name is videoStreamObject). If your desktop/laptop has any other camera connected you can change the value to 1.īasically, it’s an array with indices pointing to the different available cameras. In almost every laptop, the integrated web camera is the first camera and can be accessed by passing the value as 0(zero). This integer value represents the camera connected to the device. You can see in the above code statement that, the VideoCapure() method accepts an integer value as an argument. The VideoCapture() method is accessed using the cv2 namespace as follows: videoStreamObject = cv2.VideoCapture(0) In OpenCV, to capture/create an Image or Video we use the VideoCapture() method which allows us to capture the video stream from our webcam. This statement includes the OpenCV library into our program/script, now we can access all the methods and properties available in this library. Let's begin with a program to access your web camera and displaying it's Live Feed.Īs always import the library using the following statement, import cv2 If you need the information regarding the installations refer to the article Introduction to OpenCV using Python Part-1 In the previous article we covered all the basics, and by the end of this article, you will be able to write Python programs which can Capture Images from your device's webcam and also capture videos. If you are new to OpenCV, learn the basics from the first part of this series here: Introduction to OpenCV using Python Part-1. In our previous article, we have got the basic intuition about Computer Vision and a brief introduction about the OpenCV library.
0 Comments
Leave a Reply. |