opencv 操作计算机摄像头

2021-01-14 11:43:32 浏览数 (1)

文章目录

  • opencv 操作计算机摄像头

opencv 操作计算机摄像头

代码语言:javascript复制
# -*- coding:utf-8 -*-
# /usr/bin/python
'''
@Describe:  
@Evn     :  
@Date    :  2019-08-14  09:25
'''

import cv2
import numpy as np

# 创建相机
def camera_video(time):
    cap = cv2.VideoCapture(0)
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
    if cap.isOpened() == False:
        cap.open()
    else:
        print('camera is open!')
    while True:
        # capture frame-by-frame
        ret,frame = cap.read()
        if ret == True:
            frame = cv2.flip(frame, 0)
            out.write(frame)

            gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

            cv2.imshow('frame',gray)

            if cv2.waitKey(time):# & oxFF ==ord('q'):
                break
        else:
            break

    cap.release()
    out.release()
    cv2.destroyAllWindows()


time = 10000
camera_video(time)

0 人点赞