10 Star 43 Fork 11

feiwang / FaceRank

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
t_find_faces_in_picture.py 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
fendouai 提交于 2017-07-29 19:07 . init
from PIL import Image
import face_recognition
import os
def find_and_save_face(web_file,face_file):
# Load the jpg file into a numpy array
image = face_recognition.load_image_file(web_file)
print(image.dtype)
# Find all the faces in the image
face_locations = face_recognition.face_locations(image)
print("I found {} face(s) in this photograph.".format(len(face_locations)))
for face_location in face_locations:
# Print the location of each face in this image
top, right, bottom, left = face_location
print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
# You can access the actual face itself like this:
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.save(face_file)
list = os.listdir("./test_web/")
print(list)
for image in list:
id_tag = image.find(".")
name=image[0:id_tag]
print(name)
web_file = "./test_web/" +image
face_file="./test_face/"+name+".jpg"
try:
find_and_save_face(web_file, face_file)
except:
print("fail")
Python
1
https://gitee.com/fendouai/FaceRank.git
git@gitee.com:fendouai/FaceRank.git
fendouai
FaceRank
FaceRank
master

搜索帮助