import face_recognition
import cv2
#加载图片
image = face_recognition.load_image_file("image/LYF.jpg")
#识别图片上所有人脸的位置
face_locations = face_recognition.face_locations(image)
img = cv2.imread("1.jpg", cv2.IMREAD_COLOR)
for i in face_locations:
#face_locations 返回参数位置说明 (top, right, bottom, left)
top = i[0]
right = i[1]
bottom = i[2]
left = i[3]
# param 1:图片
# param 2:左上角坐标
# param 3:右下角坐标
# param 方框颜色
# 方框大小
cv2.rectangle(img, (left, top), (right, bottom), (255, 255, 255), 2)
# 显示图片
cv2.imshow("1.jpg", img)
# 保存为新文件
cv2.imwrite("new.jpg", img)
cv2.waitKey(0)
cv2.destroyAllWindows()