人脸识别的python3.7的实现

代码的实现是借鉴于网上大神的教程,在python3.7上实现。
所需要的库有openCV, enjoy!

import numpy as np
import cv2
from pylab import *
img=cv2.imread("C:/Users/cheng7294/Pictures/QQ Photo20171030113022.jpg",1)
color = (0, 255, 0)
face_patterns=cv2.CascadeClassifier('C:/Users/cheng7294/AppData/Local/Programs/Python/Python37/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml')
grey = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faceRects = face_patterns.detectMultiScale(grey, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32)) 
if len(faceRects) > 0: # Large to 0,then it is a face
    for faceRect in faceRects:  
        x, y, w, h = faceRect
        cv2.rectangle(img, (x - 10, y - 10), (x + w + 10, y + h + 10), color, 3) 
#writen to image
font=cv2.FONT_HERSHEY_SIMPLEX
img=cv2.putText(img,'Bset regards! From Argmin2018.',(1,40),font,1.2,(14,26,25),2)
cv2.imwrite('output.jpg',img) 
cv2.imshow("Find Faces!",img)
cv2.waitKey(0)

猜你喜欢

转载自blog.csdn.net/u012373972/article/details/82916563
今日推荐