To capture a video, you first create a Videocapture object.
The parameter can be the index number of the device, or a video file.
#-*-coding:utf-8-*-ImportNumPy as NPImportCv2cap=Cv2. Videocapture (0) whileTrue:ret, Frame=Cap.read () Gray=Cv2.cvtcolor (frame, cv2. Color_bgr2gray) Cv2.imshow ('Frame', Gray)ifCv2.waitkey (1) & 0xff = = Ord ('Q'): Breakcap.release () cv2.destroyallwindows ( )
Cap.read () returns a Boolean value. If the frame reads correctly, it is ture. Finally, you can check the return value to see if it has reached the end.
Sometimes the cap may not be initialized successfully, so you can use cap.isopened () to check if it has been initialized successfully.
If the return value is true, there is no problem, otherwise call Cap.open ()
You can use Cap.get (ID) to get some parameter information for the video, which can be any integer between 0-18.
Each number represents a property of the video,
Some of these values can be modified using Cap.set (ID, value).
Python OpenCV video capture with camera