import os import face_recognition as face from PIL import Image import datetime import time def encodingImg(img): image_to_be_matched = face.load_image_file(img) # 将加载的图像编码为特征向量 return face.face_encodings(image_to_be_matched)[0] def face_distancesrc(img,img2): return face.face_distance([encodingImg(img)], encodingImg(img2))[0] def face_distance(codeImg, codimg3): return face.face_distance([codeImg], codimg3)[0] def gain_face(imgSrc): encode = face.load_image_file(imgSrc) location = face.face_locations(encode) for face_location in location: # 打印每张脸的位置信息 top, right, bottom, left = face_location face_image = encode[top:bottom, left:right] pil_image = Image.fromarray(face_image) file = 'F:\\faceai\\face\\' + str(time_format()) + '.jpg' pil_image.save(file) print(pil_image) # pil_image.show() print(location) def time_format(): dt_ms = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') # 含微秒的日期时间,来源 比特量化 print(dt_ms) return dt_ms if __name__ == '__main__': # time_format() gain_face("F:\\faceai\\orgin\\4.jpg") # print(face_distancesrc("E:\home\data\picdata\history\\2020-11-05\\1.jpg","E:\home\data\picdata\history\\2020-11-05\\2.jpg"))
最后修改于 2020-11-10 14:03:57
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

