<分区>
我有一个 Python(2.7) 脚本,可以检测图像中的人脸,效果很好。
from PIL import Image
import face_recognition
# Load the jpg file into a numpy array
image = face_recognition.load_image_file("/PATH_TO_IMAGE/IMAGE.jpg")
# Find all the faces in the image
face_locations = face_recognition.face_locations(image)
# a = print("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.show()
现在,我想把它变成一个 http://localhost:8080/detect这样用户就可以提供图像并单击提交按钮将显示输出。我认为有几种方法可以做到这一点,使用 Flask、Django 或 Web 服务器。但不确定哪种是最简单的方法以及如何去做。如何获取此代码并将其转换为网络服务?需要更改哪些代码?任何代码示例都会有很大帮助。