人脸识别需要几个步骤,人脸识别正确使用步骤

首页 > 技术 > 作者:YD1662022-11-25 22:40:38

你只需要按步骤敲代码即可为全部代码,当然为了便于大家直接cv,代码展示如下:

# coding=gbk """ import sys import cv2 import face_recognition #dlib 人脸识别库 face_img=face_recognition.load_image_file('1.png') # print(face_img) face_encodings=face_recognition.face_encodings(face_img)#进行特征提取向量化,获取人脸的编码 face_locations=face_recognition.face_locations(face_img)#五官对应的位置 # print(face_encodings) n=len(face_encodings) print(n) #这里只做判断两个人是否为一个人,超出两个就退出了 if n>2: print('超过两个人') sys.exit() #获取两个人的数据 face1=face_encodings[0] face2=face_encodings[1] result=face_recognition.compare_faces([face1],face2,tolerance=0.6)#人脸比较,,误差不超过0.6则可以,默认值也为0.6 # print(result) if result==[True]: name='same' print('两个人为同一个人') else: print('两者不是同一个人') name='different' for i in range(len(face_encodings)): face_encoding=face_encodings[(i-1)] #倒序获取 face_location = face_locations[(i - 1)] # print(face_location)#获取人脸位置 top,right,bottom,left=face_location#确定出坐标 #画框框 cv2.rectangle(face_img,(left,top),(right,bottom),(255,0,0))#传参分别为:图片,坐标,RGB颜色,框粗细 #写字上去 cv2.putText(face_img,name,(left-10,top-10),cv2.FONT_HERSHEY_DUPLEX,0.8,(255,255,0),2)#传参数分别为:图片,文字,坐标,字体,字体大小,颜色,粗细 face_img_rgb=cv2.cvtColor(face_img,cv2.COLOR_BGR2RGB)#确保颜色不要混乱 #展示图像 cv2.imshow('compare',face_img_rgb) #设置等待关闭 cv2.waitKey(0)

标出了两个人脸并写上为different,就是不同的意思,当然本篇文章为了给大家简单介绍实现人脸识别,并没有做过多的复杂实现,近段时间我研究人脸识别也做了一些复杂的功能实现,感兴趣也可以一起聊聊。

上一页123末页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.