# version: Python3
from DobotEDU import *
#导入包
import base64
import os
import cv2
import time
def get_image(file_name,timeout,port,flip = False):
pic = util.get_image(timeout,port,flip)
cv2.imwrite(file_name,pic)
base64_image = to_base64(file_name)
cv2.destroyAllWindows()
return base64_image
def to_base64(file_name): #转化为Base64格式
with open(file_name,'rb') as f:
base64_data = base64.b64encode(f.read())
return base64_data
#开始人脸注册
j = 2
path = 'D:/workspace/dobotlab/face'
for i in range(j): #range(2),注册人脸数量
name = input("请输入你的名字:")
print('请面对摄像头')
get_image(path+name+'.jpg', 3, 0 ) #命名为1.jpg、2.jpg...
if i < j:
print('注册成功,下一位')
time.sleep(3)
else :
print('注册成功,结束')
心得:这节课所学