Python_opencv_ Read Video _ Webcam

Source: Internet
Author: User

Goal
• Learn to read video files, display videos, save video files
• Learn to get and display video from the camera
• You will learn these functions: Cv2. Videocapture (), Cv2. Videowrite ()
Capturing video with the camera

    • Use the camera to capture a video and convert it into grayscale video.
    • You should first create a Videocapture object, which can be the index number of the device, or a video file.
    • The device index number is the camera that you specify to use. Typical laptops have built-in cameras. So the parameter is 0. You can choose a different camera by setting it to 1 or something else.
    • After that, you can capture the video in one frame at a frame. But finally, don't forget to stop capturing the video.

On the code:

1 #-*-coding:utf-8-*-2 3 ImportNumPy as NP4 ImportCv25 6Cap = Cv2. Videocapture (0)#Create a Videocapture object7  while(True):8    9RET, frame = Cap.read ()#read a video frame at one frameTenGray = Cv2.cvtcolor (frame, cv2. Color_bgr2gray)#processing each frame, set to grayscale OneCv2.imshow ('Frame', Gray)#Show Results A     ifCv2.waitkey (1) & 0xFF = = Ord ('Q'):#Press Q to stop -          Break -      theCap.release ()#release cap, destroy window -Cv2.destroyallwindows ()
View Code
    • Run to see the camera open, and display a grayscale image, press Q to exit

Python_opencv_ Read Video _ Webcam

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.