mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
added extract service route
This commit is contained in:
parent
b75e37c3f6
commit
9816b8f2bd
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@ benchmarks/results
|
|||||||
benchmarks/outputs
|
benchmarks/outputs
|
||||||
benchmarks/dataset
|
benchmarks/dataset
|
||||||
benchmarks/lfwe
|
benchmarks/lfwe
|
||||||
|
venv
|
@ -12,6 +12,29 @@ blueprint = Blueprint("routes", __name__)
|
|||||||
def home():
|
def home():
|
||||||
return f"<h1>Welcome to DeepFace API v{DeepFace.__version__}!</h1>"
|
return f"<h1>Welcome to DeepFace API v{DeepFace.__version__}!</h1>"
|
||||||
|
|
||||||
|
@blueprint.route("/represent", methods=["POST"])
|
||||||
|
def extract():
|
||||||
|
input_args = request.get_json()
|
||||||
|
|
||||||
|
if input_args is None:
|
||||||
|
return {"message": "empty input set passed"}
|
||||||
|
|
||||||
|
img_path = input_args.get("img") or input_args.get("img_path")
|
||||||
|
if img_path is None:
|
||||||
|
return {"message": "you must pass img_path input"}
|
||||||
|
|
||||||
|
obj = service.extract_faces(
|
||||||
|
img_path=img_path,
|
||||||
|
detector_backend=input_args.get("detector_backend", "opencv"),
|
||||||
|
enforce_detection=input_args.get("enforce_detection", True),
|
||||||
|
align=input_args.get("align", True),
|
||||||
|
anti_spoofing=input_args.get("anti_spoofing", False),
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug(obj)
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route("/represent", methods=["POST"])
|
@blueprint.route("/represent", methods=["POST"])
|
||||||
def represent():
|
def represent():
|
||||||
|
@ -31,6 +31,27 @@ def represent(
|
|||||||
tb_str = traceback.format_exc()
|
tb_str = traceback.format_exc()
|
||||||
return {"error": f"Exception while representing: {str(err)} - {tb_str}"}, 400
|
return {"error": f"Exception while representing: {str(err)} - {tb_str}"}, 400
|
||||||
|
|
||||||
|
def extract_faces(
|
||||||
|
img_path: str,
|
||||||
|
detector_backend: str,
|
||||||
|
enforce_detection: bool,
|
||||||
|
align: bool,
|
||||||
|
anti_spoofing: bool,
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
result = {}
|
||||||
|
faces_objs = DeepFace.extract_faces(
|
||||||
|
img_path=img_path,
|
||||||
|
detector_backend=detector_backend,
|
||||||
|
enforce_detection=enforce_detection,
|
||||||
|
align=align,
|
||||||
|
anti_spoofing=anti_spoofing,
|
||||||
|
)
|
||||||
|
result["results"] = faces_objs
|
||||||
|
return result
|
||||||
|
except Exception as err:
|
||||||
|
tb_str = traceback.format_exc()
|
||||||
|
return {"error": f"Exception while extracting faces: {str(err)} - {tb_str}"}, 400
|
||||||
|
|
||||||
def verify(
|
def verify(
|
||||||
img1_path: str,
|
img1_path: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user