1:pyzbar实现二维码扫面获取信息
import pyzbar.pyzbar as pyzbar
from PIL import Image
image = "test.jpg"
img = Image.open(image)
barcodes = pyzbar.decode(img)
for barcode in barcodes:
barcodeData = barcode.data.decode("utf-8")
print(barcodeData)
2:打开摄像头获取人脸照片并保存
import cv2
cap = cv2.VideoCapture(0)
while(1):
ret, frame = cap.read()
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite("/opt/code/image/fangjian2.jpeg", frame)
break
cap.release()
cv2.destroyAllWindows()
3:对视频截取30张图片
import cv2
import os
cap = cv2.VideoCapture("Test.mp4")
save_path = os.makedirs("tupian")
imgPath = ""
sum = cap.get(7)
time = (int)(sum / 30)
sum = 0
i = 0
while True:
ret, frame = cap.read()
if ret == False:
break
sum += 1
if sum % time == 0 and i < 30:
i += 1
imgPath = "tupian/%s.jpg" % str(i)
cv2.imwrite(imgPath, frame)
print("finish!") # 提取结束,打印finish