短视频直播源码,自动对上传的图片进行识别
作者:互联网
短视频直播源码,自动对上传的图片进行识别实现的相关代码
import face_recognition
import os
# 获取图片名列表
# 只读取文件名以'.png'或'.jpg'或'.jpeg'结尾的图片
unknow_people_list = [i for i in os.listdir('unknow_people') if (i.endswith('.jpg')) or (i.endswith('.png')) or (i.endswith('.jpeg'))]
know_people_list = [i for i in os.listdir('know_people') if (i.endswith('.jpg')) or (i.endswith('.png')) or (i.endswith('.jpeg'))]
def face_select():
# 定义flag
flag = 0
for unknow_people in unknow_people_list:
# 读取待识别图片
unknow = face_recognition.load_image_file('unknow_people/' + unknow_people)
# 待识别图片转化为特征向量
unknow_encode = face_recognition.face_encodings(unknow)[0]
for know_people in know_people_list:
# 读取计算机已经认识的图片
know = face_recognition.load_image_file('know_people/'+know_people)
# 图片转化为特征向量
know_encode = face_recognition.face_encodings(know)[0]
# 两张图片进行比较
# tolerance刻画了比较的难易程度,值越小越难
res = face_recognition.compare_faces([know_encode],unknow_encode,tolerance=0.5)
if res[0]:
flag = 1
break
else:
flag = 0
if flag == 1:
print(f'匹配{unknow_people.split(".")[0]}')
else:
print(f'未匹配{unknow_people.split(".")[0]}')
if __name__ == '__main__':
face_select()
以上就是 短视频直播源码,自动对上传的图片进行识别实现的相关代码,更多内容欢迎关注之后的文章
标签:unknow,people,face,endswith,直播,know,上传,源码,图片 来源: https://www.cnblogs.com/yunbaomengnan/p/15931567.html