环境:
- python 3.7
- Win7
依赖包安装:
pip install pillow
pip install opencv-python
pip install opencv-contrib-python
pip install numpy
pip instal pyzbar
首先使用cv2打开摄像头进行测试
import numpy as np
import cv2
capture = cv2.VideoCapture(0,cv2.CAP_DSHOW)
capture.set(3,640)
capture.set(4,480)
while True:
# 读取摄像头中的图像,ok为是否读取成功的判断参数
ret,img = capture.read()
cv2.imshow('frame', img)
k = cv2.waitKey(1)
if k == 27: # 'ESC'关闭
break
如果看到屏幕出现一个窗口,上面显示着你的摄像头所拍摄到的画面说明测试成功
然后就直接上代码:
#written by DY
#http://dyblog.tk
#e-mail:duyun888888@qq.com
import cv2
from PIL import Image, ImageDraw, ImageFont
import csv
import pyzbar.pyzbar as pyzbar
import numpy
import time
#-----------------time----------
time1 = (time.strftime("%Y!%m@%d(%H*%M)%S`", time.localtim