MCPcopy Create free account
hub / github.com/CScorza/IntelOSINT / face_compare

Function face_compare

IntelOSINT.py:19372–19650  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19370
19371@app.route('/api/face/compare', methods=['POST'])
19372def face_compare():
19373 d = request.get_json(silent=True) or {}
19374 image_a = d.get('image_a')
19375 image_b = d.get('image_b')
19376 images_a = d.get('images_a')
19377 images_b = d.get('images_b')
19378 mode = d.get('mode', 'pair')
19379 threshold = d.get('threshold', (0.55 + 0.36) / 1.36)
19380 request_report = bool(d.get('request_report', False))
19381
19382 def _dataurl_to_temp_file(data_url: str, out_path: Path):
19383 if not isinstance(data_url, str):
19384 return False
19385 if "," not in data_url:
19386 return False
19387 _, payload = data_url.split(",", 1)
19388 try:
19389 raw = base64.b64decode(payload)
19390 except Exception:
19391 return False
19392 try:
19393 out_path.parent.mkdir(parents=True, exist_ok=True)
19394 out_path.write_bytes(raw)
19395 return out_path.exists()
19396 except Exception:
19397 return False
19398
19399 def _compute_face_hashes(file_path: Path):
19400 md5_h = hashlib.md5()
19401 sha256_h = hashlib.sha256()
19402 with open(file_path, "rb") as fh:
19403 while True:
19404 chunk = fh.read(1024 * 1024)
19405 if not chunk:
19406 break
19407 md5_h.update(chunk)
19408 sha256_h.update(chunk)
19409 return {"md5": md5_h.hexdigest(), "sha256": sha256_h.hexdigest()}
19410
19411 def _latin1(v):
19412 return str(v).encode("latin-1", "ignore").decode("latin-1")
19413
19414 def _build_face_report(job_id, result_payload: dict, images_a_payload: list, images_b_payload: list, threshold_value: float, mode_value: str):
19415 try:
19416 face_dir = Path(tempfile.gettempdir()) / "intelosint_face"
19417 face_dir.mkdir(parents=True, exist_ok=True)
19418 report_dir = face_dir / job_id
19419 report_dir.mkdir(parents=True, exist_ok=True)
19420 saved_inputs = []
19421 for idx, raw in enumerate(images_a_payload or [], start=1):
19422 p = report_dir / f"input_A_{idx:02d}.jpg"
19423 if _dataurl_to_temp_file(str(raw), p):
19424 h = _compute_face_hashes(p)
19425 saved_inputs.append({
19426 "side": "A",
19427 "index": idx,
19428 "path": p,
19429 "name": p.name,

Callers

nothing calls this directly

Calls 2

_build_face_reportFunction · 0.85
compare_faces_arcfaceMethod · 0.80

Tested by

no test coverage detected