知乎专栏 |
import face_recognition as face image = face.load_image_file("face.jpeg") face_locations = face.face_locations(image) print(face_locations)
neo@MacBook-Pro-Neo ~/workspace/python/face % python3.9 /Users/neo/workspace/python/face/face_locations.py [(231, 676, 498, 409)]
使用深度学习模型达到更加精准的人脸定位
import face_recognition image = face_recognition.load_image_file("my_picture.jpg") face_locations = face_recognition.face_locations(image, model="cnn")
例 16.1. 找出图片中头像
import PIL.Image as img import face_recognition as face file = "face.jpeg" image = face.load_image_file(file) face_locations = face.face_locations(image) print(face_locations) if face_locations: (top, right, bottom, left) = face_locations[0] im = img.open(file) box = (left, top, right, bottom) head = im.crop(box) head.save('head.jpg')