使用python3完成人脸识别
第一种:
# -*- coding:utf-8 -*- import cv2 as cv import numpy as np src = cv.imread(‘test1.jpg‘) path = r‘D:\face‘ def face_detect_demo(): gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY) face_detector = cv.CascadeClassifier(‘haarcascade_frontalface_default.xml‘) face_detector.load(path + ‘\haarcascade_frontalface_default.xml‘) faces = face_detector.detectMultiScale(gray,1.3,5) for x,y,w,h in faces: cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2) cv.imshow("result",src) print("--------------python face detect-------------") cv.namedWindow("input image",0) cv.namedWindow("result",0) cv.imshow("input image",src) face_detect_demo() cv.waitKey(0) cv.destroyAllWindows()
效果:
第二种:
# -*- coding:utf-8 -*- import cv2 as cv import numpy as np src = cv.imread(‘test1.jpg‘) path = r‘D:\face‘ def face_detect_demo(): gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY) face_detector = cv.CascadeClassifier(‘haarcascade_frontalface_default.xml‘) face_detector.load(path + ‘\haarcascade_frontalface_default.xml‘) faces = face_detector.detectMultiScale(gray,1.3,5) for x,y,w,h in faces: cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2) cv.imshow("result",src) print("--------------python face detect-------------") cv.namedWindow("input image",0) cv.namedWindow("result",0) cv.imshow("input image",src) face_detect_demo() cv.waitKey(0) cv.destroyAllWindows()
效果:
相关推荐
chuckchen 2020-10-31
Will0 2020-10-12
Dreamhome 2020-10-09
xirongxudlut 2020-09-28
星辰大海的路上 2020-09-13
chaochao 2020-08-31
猪猪侠喜欢躲猫猫 2020-08-17
快递小可 2020-08-16
shengge0 2020-07-26
巩庆奎 2020-07-21
张文倩数据库学生 2020-07-19
xirongxudlut 2020-07-18
Ericbig 2020-07-18
kyelu 2020-07-09
liangzhouqu 2020-07-07
GuoSir 2020-06-28
chaigang 2020-06-27
pythonxuexi 2020-06-25