OpenCV+Dlib+FR人脸识别和对齐

阅读: 评论:0

OpenCV+Dlib+FR人脸识别和对齐

OpenCV+Dlib+FR人脸识别和对齐

人脸定位(仅Opencv)

安装:pip install opencv-python
代码:

import cv2def detect(filename):face_cascade = cv2.CascadeClassifier('C:/Users/13311/Anaconda3/Lib/site-packages/cv2/data/haarcascade_l')#括号内路径为:'Python路径下/Lib/site-packages/cv2/data/haarcascade_l'img = cv2.imread(filename)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = face_cascade.detectMultiScale(gray, 1.3, 5)for (x, y, w, h) in faces:img = angle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)cv2.imshow('Person Detected!', img)cv2.waitKey(0)cv2.destroyAllWindows()if __name__ == '__main__':detect('1.jpg')

输出结果:

存在未识别到人脸和识别错误。

人脸定位(face_recognition)

需要python3.7+opencv+face_recognition
且需要先安装cmake,boost和dlib,然后才可以安装face_recognition

cmake安装:pip install cmake
如下图则安装成功

boost安装:pip install boost

dlib安装:pip install dlib
如存在问题,则手动安装。
自行下载相应版本的dlib(该链接为python3.7版本)
链接:
提取码:ur13
下载后在命令行该whl文件路径下输入命令python -m pip install xx.whl

face_recognition安装:pip install face_recognition

代码:

import face_recognition
import cv2image = face_recognition.load_image_file("1.jpg")
face_locations_noCNN = face_recognition.face_locations(image)
# A list of tuples of found face locations in css (top, right, bottom, left) order
# 因为返回值的顺序是这样子的,因此在后面的for循环里面赋值要注意按这个顺序来print("face_location_noCNN:")
print(face_locations_noCNN)
face_num2 = len(face_locations_noCNN)
print(face_num2)       # The number of faces
# 到这里为止,可以观察两种情况的坐标和人脸数,一般来说,坐标会不一样,但是检测出来的人脸数应该是一样的
# 也就是说face_num1 = face_num2; face_locations_useCNN 和 face_locations_noCNN 不一样org = cv2.imread("1.jpg")
img = cv2.imread("1.jpg")
cv2.imshow("1.jpg", img)  # 原始图片for i in range(0, face_num2):top = face_locations_noCNN[i][0]right = face_locations_noCNN[i][1]bottom = face_locations_noCNN[i][2]left = face_locations_noCNN[i][3]start = (left, top)end = (right, bottom)color = (0, 255, 255)thickness = angle(org, start, end, color, thickness)cv2.imshow("no cnn ", org)cv2.waitKey(0)
cv2.destroyAllWindows()

输出结果:

控制台输出:

人脸识别更为准确,该例中未出现错误。

特征点检测

需要下载包shape_predictor_68_face_landmarks.dat
安装包放置于‘Python路径下/Lib/site-packages/’

代码:

import cv2
import dlibpath = "1.jpg"
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#人脸分类器
detector = _frontal_face_detector()
# 获取人脸检测器
predictor = dlib.shape_predictor(r"C:Users13311Anaconda3Libsite-packagesshape_predictor_68_face_landmarks.datshape_predictor_68_face_landmarks.dat")
# 括号内路径为:'Python路径下/Lib/site-packages/shape_predictor_68_face_landmarks.dat/shape_predictor_68_face_landmarks.dat'
dets = detector(gray, 1)
for face in dets:shape = predictor(img, face)  # 寻找人脸的68个标定点# 遍历所有点,打印出其坐标,并圈出来for pt in shape.parts():pt_pos = (pt.x, pt.y)cv2.circle(img, pt_pos, 2, (0, 255, 0), 1)cv2.imshow("image", img)cv2.waitKey(0)
cv2.destroyAllWindows()

输出结果:

Opencv:
.3.0/d9/de5/tutorial_py_table_of_contents_objdetect.html
mooc第四周:
=2403042001&trace_c_p_k2=a30ffd1da6024a348e70354906a3b5af#/info
旷视科技(国际顶级的人脸识别团队之一):

商汤科技(国际顶级人脸识别之一):
=30
爱奇艺:探寻人工智能:
=input&sr=16028073540123868&ssrt=20210513114701184&ssra=73756ec02a6e6e284f1aae5360b422cd

本文发布于:2024-02-04 06:23:19,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170700959953069.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:OpenCV   Dlib   FR
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23