[机器学习]人脸识别

import face_recognition
import cv2

'''读入图片并识别人脸'''
img = face_recognition.load_image_file("gphoto.jpg")
face_locations = face_recognition.face_locations(img)
print(face_locations)

'''调用opencv显示图片'''
img = cv2.imread("gphoto.jpg")
cv2.namedWindow("1")
cv2.imshow("1", img)

'''遍历每个人脸,并标注'''
faceNum = len(face_locations)
for i in range(0, faceNum):
    top = face_locations[i][0]
    right = face_locations[i][1]
    bottom = face_locations[i][2]
    left = face_locations[i][3]
    
    start = (left, top)
    end = (right, bottom)
    color = (55, 255, 155)
    thinkness = 3
    cv2.rectangle(img, start, end, color, thinkness)

'''显示识别结果'''

cv2.namedWindow("2")
cv2.imshow("2", img)
cv2.waitKey(0)
发布了157 篇原创文章 · 获赞 1 · 访问量 6055

猜你喜欢

转载自blog.csdn.net/weixin_44699689/article/details/105321933