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

Method extract_from_image

IntelOSINT.py:10872–10927  ·  view source on GitHub ↗
(index, data_url, side)

Source from the content-addressed store, hash-verified

10870 threshold = 0.9
10871
10872 def extract_from_image(index, data_url, side):
10873 bgr = self._decode_dataurl_to_bgr(data_url)
10874 if bgr is None:
10875 return {"error": f"Formato immagine non valido lato {side} #{index}.", "annotated": "", "faces": []}
10876 if not use_fallback:
10877 faces = engine.get(bgr)
10878 if not faces:
10879 return {"error": f"Volto non rilevato lato {side} #{index}.", "annotated": "", "faces": []}
10880 ann = self._annotate_faces(bgr, faces)
10881 payload = []
10882 for i, f in enumerate(faces, start=1):
10883 emb = getattr(f, "embedding", None)
10884 bb = getattr(f, "bbox", None)
10885 if emb is None:
10886 continue
10887 vb = np.asarray(emb, dtype="float32")
10888 n = float(np.linalg.norm(vb) + 1e-12)
10889 if n <= 0:
10890 continue
10891 payload.append({
10892 "side": side,
10893 "image_index": index,
10894 "face": i,
10895 "embedding": vb / n,
10896 "icon": self._face_icon(bgr, bb),
10897 })
10898 if not payload:
10899 return {"error": f"Embedding non disponibili lato {side} #{index}.", "annotated": ann, "faces": []}
10900 return {"error": "", "annotated": ann, "faces": payload}
10901 boxes = self._detect_faces_cv2(bgr)
10902 if not boxes:
10903 return {"error": f"Nessun volto rilevato lato {side} #{index}.", "annotated": "", "faces": []}
10904 payload = []
10905 import cv2
10906 draw = bgr.copy()
10907 for i, bb in enumerate(boxes[:20], start=1):
10908 emb = self._face_embedding_cv2(bgr, bb)
10909 if emb is None:
10910 continue
10911 n = float(np.linalg.norm(emb) + 1e-12)
10912 if n <= 0:
10913 continue
10914 x1, y1, x2, y2 = bb
10915 cv2.rectangle(draw, (x1, y1), (x2, y2), (0, 229, 255), 2)
10916 cv2.putText(draw, f"Face {i}", (x1, max(18, y1 - 8)), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 229, 255), 2)
10917 payload.append({
10918 "side": side,
10919 "image_index": index,
10920 "face": i,
10921 "embedding": emb / n,
10922 "icon": self._face_icon(bgr, bb),
10923 })
10924 ann = self._encode_bgr_png(draw)
10925 if not payload:
10926 return {"error": f"Fallback: embedding non disponibili lato {side} #{index}.", "annotated": ann, "faces": []}
10927 return {"error": "", "annotated": ann, "faces": payload}
10928
10929 face_results_a = []

Callers

nothing calls this directly

Calls 6

_annotate_facesMethod · 0.95
_face_iconMethod · 0.95
_detect_faces_cv2Method · 0.95
_face_embedding_cv2Method · 0.95
_encode_bgr_pngMethod · 0.95

Tested by

no test coverage detected