/usr/local/face_recognition路径下 文件名recognition.py5090;识别接口http://xxxx:5090/match;解码接口http://xxxxx:5090/encodeversion: '2'
services:
#face_recognition 服务模块
face_recognition:
networks:
jianxin:
ipv4_address: 172.18.1.10
image: "huzhihui/face_recognition"
restart: always
container_name: face_recognition
volumes:
- "/alidata/docker/face_recognition:/usr/local/face_recognition/user"
ports:
- "5090:5090"
command: "python /usr/local/face_recognition/user/recognition.py" # 此处我指定的是我外部的文件 ,如果用默认改为 python /usr/local/face_recognition/recognition.py
networks:
wode:
external: true
# -*- coding: utf-8 -*-
import face_recognition
from flask import Flask, jsonify, request
import numpy
app = Flask(__name__)
@app.route('/encode', methods=['POST'])
def get_face_encoding():
face_encoding = ''
file = request.files['file']
img = face_recognition.load_image_file(file)
face_locations = face_recognition.face_locations(img)
if len(face_locations) > 0:
encoding = face_recognition.face_encodings(img)[0]
s = numpy.array2string(encoding, separator=',')
face_encoding = s
return face_encoding
@app.route('/match', methods=['POST'])
def match():
found_face = False
same_user = False
try:
file = request.files['file']
encode = request.form.get('encode')
encode = encode[1:-1] # 过滤首尾的 [ ]
str_list = encode.split(',')
known_face_encoding = [float(i) for i in str_list]
img = face_recognition.load_image_file(file)
face_locations = face_recognition.face_locations(img)
if len(face_locations) > 0:
unknown_face_encodings = face_recognition.face_encodings(img)
if len(unknown_face_encodings) > 0:
found_face = True
match_results = face_recognition.compare_faces([known_face_encoding], unknown_face_encodings[0], 0.5)
if match_results[0]:
same_user = True
except Exception as e:
print(e)
finally:
result = {
"found_face": found_face,
"same_user": same_user
}
return jsonify(result)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5090, debug=True)
Content type
Image
Digest
Size
462.8 MB
Last updated
over 6 years ago
docker pull huzhihui/face_recognition