欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

人脸识别python face_recognize_【python+face_recognition】人脸识别初始

发布时间:2025/3/20 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 人脸识别python face_recognize_【python+face_recognition】人脸识别初始 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

【python+face_recognition】人脸识别初始

发布时间:2018-09-01 12:03,

浏览次数:366

, 标签:

python

face

recognition

face_recognition 人脸识别初始

说到人脸识别,我们肯定会联系到机器学习,机器学习说起来可能遥不可及,在python 当道的今天,如何快速实现人脸识别功能,这是个问题

今天我们来了解下python 的 face_recognition 库,来做一个简单的人脸识别程序。走进机器学习,人工智能的大门

我们使用face_recognition 来识别图片中是否是同一个人。

我们使用到的识别素材2.jpg

# -*- coding:utf-8 -*- import cv2 #画图用 import face_recognition #人脸识别库 import

sys face_image = face_recognition.load_image_file("E://pics/2.jpg") #读取图片

face_encodings = face_recognition.face_encodings(face_image) face_locations =

face_recognition.face_locations(face_image)# 判断图片中出现的人数 n = len(face_encodings)

if n>2 : print("3") sys.exit() try: face1 = face_encodings[0] face2 =

face_encodings[1] except : print("2") sys.exit() results =

face_recognition.compare_faces([face1], face2, tolerance=0.5) if results == [

True]: print("0") name = "PASS" else: print("1") name = "DENIED" #绘图 绘制出图片 for i

in range(len(face_encodings)): face_encoding = face_encodings[(i-1)]

face_location = face_locations[(i-1)] top, right, bottom, left = face_location

cv2.rectangle(face_image, (left, top), (right, bottom), (0, 255, 0), 2)

cv2.putText(face_image, name, (left-10, top-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8,

(255, 0, 0), 2) face_image_rgb = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)

cv2.imshow("Output", face_image_rgb) cv2.imwrite(

'C:/Users/Administrator/Desktop/fk_model/face/output/intrest.jpg'

,face_image_rgb,[int(cv2.IMWRITE_JPEG_QUALITY),100]) cv2.waitKey(0)

我们看下识别结果

控制台打印为1 表示不是同一个人

当然大家可以尝试不同的图像,也可以做到工业级应用,这就涉及到图片特征训练,特征提取,比这种简单的识别复杂很多,当然这些都是需要训练自己的模型,在后期不断完善。

总结

以上是生活随笔为你收集整理的人脸识别python face_recognize_【python+face_recognition】人脸识别初始的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。