使用python3完成人脸识别
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用python3完成人脸识别相关的知识,希望对你有一定的参考价值。
原文地址:https://www.jb51.net/article/160197.htm
第一种:
1 # -*- coding:utf-8 -*- 2 import cv2 as cv 3 import numpy as np 4 5 src = cv.imread(‘test1.jpg‘) 6 path = r‘D:face‘ 7 8 def face_detect_demo(): 9 gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY) 10 11 face_detector = cv.CascadeClassifier(‘haarcascade_frontalface_default.xml‘) 12 face_detector.load(path + ‘haarcascade_frontalface_default.xml‘) 13 faces = face_detector.detectMultiScale(gray,1.3,5) 14 for x,y,w,h in faces: 15 cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2) 16 cv.imshow("result",src) 17 18 print("--------------python face detect-------------") 19 cv.namedWindow("input image",0) 20 cv.namedWindow("result",0) 21 cv.imshow("input image",src) 22 face_detect_demo() 23 cv.waitKey(0) 24 cv.destroyAllWindows()
效果:
第二种:
1 # -*- coding:utf-8 -*- 2 import cv2 as cv 3 import numpy as np 4 5 src = cv.imread(‘test1.jpg‘) 6 path = r‘D:face‘ 7 8 def face_detect_demo(): 9 gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY) 10 11 face_detector = cv.CascadeClassifier(‘haarcascade_frontalface_default.xml‘) 12 face_detector.load(path + ‘haarcascade_frontalface_default.xml‘) 13 faces = face_detector.detectMultiScale(gray,1.3,5) 14 for x,y,w,h in faces: 15 cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2) 16 cv.imshow("result",src) 17 18 print("--------------python face detect-------------") 19 cv.namedWindow("input image",0) 20 cv.namedWindow("result",0) 21 cv.imshow("input image",src) 22 face_detect_demo() 23 cv.waitKey(0) 24 cv.destroyAllWindows()
效果:
以上是关于使用python3完成人脸识别的主要内容,如果未能解决你的问题,请参考以下文章
opencv+python3.4的人脸识别----2017-7-19
遮挡人脸识别:基于Python3.8+Tensorflow2.2人脸遮挡情况的人脸识别