PYTHON+OPENCV read video, call camera

Source: Internet
Author: User
Tags ord

Reference

Import Cv2import NumPy

Create a camera object

Cap = Cv2. Videocapture ("Videotest/test1.mp4") #参数为视频文件目录

Frames-by-frame display for video playback

While 1:    ret, frame = Cap.read () #读取    cv2.imshow ("Capture", frame) #显示    if Cv2.waitkey (100) & 0xff = = Ord (' q '): #按q退出 break        

Releasing Camera objects and windows

Cap.release () cv2.destroyallwindows ()

Full Code

Import Cv2import Numpycap = Cv2. Videocapture (1) #调整参数实现读取视频或调用摄像头while 1:    ret, frame = Cap.read ()    cv2.imshow ("cap", frame)    if Cv2.waitkey & 0xff = = Ord (' q '):        breakcap.release () cv2.destroyallwindows ()

directory Structure

Read Video Run Results

Call the built-in camera

Cap = Cv2. Videocapture (0)    #调用笔记本内置摄像头

call the USB camera

Cap = Cv2. Videocapture (1)

Call Camera Run Results

PYTHON+OPENCV read video, call camera

Related Article

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.