|
@@ -37,7 +37,7 @@ def create_app():
|
|
|
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
|
|
temp_file.write(response.content)
|
|
|
temp_file.close()
|
|
|
- find = find_faces_in_image(temp_file.name)
|
|
|
+ find = find_faces_in_image(temp_file.name, url)
|
|
|
os.remove(temp_file.name) # 删除临时文件
|
|
|
results = return_json(find)
|
|
|
return results
|
|
@@ -55,7 +55,7 @@ def create_app():
|
|
|
# 创建一个临时文件保存上传的文件
|
|
|
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
|
|
file.save(temp_file.name)
|
|
|
- find = find_faces_in_image(temp_file.name)
|
|
|
+ find = find_faces_in_image(temp_file.name, file.filename)
|
|
|
os.remove(temp_file.name)# 删除临时文件
|
|
|
results = return_json(find)
|
|
|
return results
|
|
@@ -65,8 +65,6 @@ def create_app():
|
|
|
|
|
|
|
|
|
# 调用 setup_logging 函数创建并配置日志记录器
|
|
|
-
|
|
|
-
|
|
|
def setup_logging():
|
|
|
# 创建一个 Logger 对象
|
|
|
logger = logging.getLogger('sensitive-face-recognizer_logger')
|
|
@@ -133,7 +131,7 @@ def get_face_similarity(known_face_encoding, face_encoding):
|
|
|
similarity = 1 - face_distances
|
|
|
return similarity
|
|
|
|
|
|
-def find_faces_in_image(image_path):
|
|
|
+def find_faces_in_image(image_path, url):
|
|
|
image = face_recognition.load_image_file(image_path)
|
|
|
face_locations = face_recognition.face_locations(image)
|
|
|
face_encodings = face_recognition.face_encodings(image, face_locations)
|
|
@@ -147,7 +145,7 @@ def find_faces_in_image(image_path):
|
|
|
found_faces.append(name)
|
|
|
known_face_encoding = known_face_encodings[first_match_index]
|
|
|
similarity = get_face_similarity(known_face_encoding, face_encoding)
|
|
|
- logger.info(f'image_name={name} similarity={similarity}')
|
|
|
+ logger.info(f'image_name={name} similarity={similarity} url={url}')
|
|
|
if found_faces:
|
|
|
return True
|
|
|
else:
|