opencv-python 摄像头的简单应用

来源:互联网 发布:it招标 编辑:程序博客网 时间:2024/03/28 19:49

1、安装

下载安装包

pip install opencv_python-2.4.12-cp27-none-win_amd64.whl

2、代码

#coding=utf-8import cv2import timecap=cv2.VideoCapture(0)#读取摄像头,0表示系统默认摄像头while True:    ret,photo=cap.read()    #读取图像    cv2.imshow('Please Take Your Photo!!',photo)    #将图像传送至窗口    key=cv2.waitKey(2)    #设置等待时间,若数字为0则图像定格    if key==ord(" "):    #按空格获取图像        filename = time.strftime('%Y%m%d-%H%M%S') + ".jpg"        #以当前时间存储        cv2.imwrite(filename,photo)        #保存位置    if key==ord("q"):    #按“q”退出程序        break
3、效果如下图:






0 0
原创粉丝点击