Python OpenCV video capture with camera

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.