码迷,mamicode.com
首页 > 其他好文 > 详细

opencv

时间:2018-11-18 11:30:34      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:art   ret   break   python   div   sop   import   按键   __name__   

推荐博客:https://blog.csdn.net/wwxy1995/article/details/79735283

import cv2
 
def make_photo():
    """使用opencv拍照"""
    cap = cv2.VideoCapture(0)  # 默认的摄像头
    while True:
        ret, frame = cap.read()
        if ret:
            cv2.imshow("capture", frame)  # 弹窗口
            # 等待按键q操作关闭摄像头
            if cv2.waitKey(1) & 0xFF == ord(‘q‘):
                file_name = "xieyang.jpeg"
                cv2.imwrite(file_name, frame)
                break
        else:
            break
 
    cap.release()
    cv2.destroyAllWindows()
 
 
def make_video():
    """使用opencv录像"""
    cap = cv2.VideoCapture(0)  # 默认的摄像头
    # 指定视频代码
    fourcc = cv2.VideoWriter_fourcc(*"DIVX")
    out = cv2.VideoWriter(‘xieyang.avi‘, fourcc, 20.0, (640,480))
    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret:
            out.write(frame)
            #
            cv2.imshow(‘frame‘,frame)
            # 等待按键q操作关闭摄像头
            if cv2.waitKey(1) & 0xFF == ord(‘q‘):
                break
        else:
            break
    cap.release()
    out.release()
    cv2.destroyAllWindows()
 
if __name__ == ‘__main__‘:
    make_video()

  

opencv

标签:art   ret   break   python   div   sop   import   按键   __name__   

原文地址:https://www.cnblogs.com/perfey/p/9976977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!