#!/usr/bin/env python3 """Straighten the specified reference first, then recalibrate framing ratios.""" import json from pathlib import Path import sys ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) import cv2 from hairline.framing import calibrate_reference, decode_portrait, PROFILE_PATH from hairline.service import get_landmarker if __name__ == "__main__": source = Path(sys.argv[1]) if len(sys.argv)>1 else ROOT/"tests/output/upload_framing/reference.jpg" photo = decode_portrait(source.read_bytes()) if photo is None: raise ValueError("Reference image cannot be decoded") landmarks = get_landmarker().detect(cv2.cvtColor(photo, cv2.COLOR_BGR2RGB), include_iris=True) if landmarks is None: raise ValueError("Reference face not detected") image, _, profile = calibrate_reference(photo, landmarks) cv2.imwrite(str(ROOT/"static/framing_reference.png"), image) PROFILE_PATH.write_text(json.dumps(profile, ensure_ascii=False, indent=2)+"\n", encoding="utf-8") print(json.dumps(profile, ensure_ascii=False, indent=2))