VeuReu commited on
Commit
37abc42
·
verified ·
1 Parent(s): 6383024

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -44
app.py CHANGED
@@ -436,52 +436,53 @@ def _get_ocr_characters_to_image(
436
  face_col = json.loads(face_col)
437
  faces_detected = []
438
 
439
- for f in raw_faces:
440
- embedding_image = f
441
- identity = "Desconegut"
442
- knn = []
443
-
444
- # Now search for the 3 nearest neighbors in the database for each embedding.
445
- if face_col and embedding_image is not None:
446
- try:
447
- num_embeddings = len(face_col)
448
-
449
- if num_embeddings < 1:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  knn = []
451
  identity = "Desconegut"
452
-
453
- else:
454
- n_results = min(3, num_embeddings)
455
-
456
- embedding_image = np.array(embedding_image)
457
-
458
- distances_embedding = []
459
-
460
- # Compute Euclidean distance between the detected face and each stored embedding
461
- for image_base_datos in face_col:
462
- image_base_datos_embedding = np.array(image_base_datos["embedding"])
463
- distance = np.linalg.norm(embedding_image - image_base_datos_embedding)
464
- distances_embedding.append({
465
- "identity": image_base_datos["nombre"],
466
- "distance": float(distance)
467
- })
468
-
469
- # Sort by distance and keep the top N matches
470
- distances_embedding = sorted(distances_embedding, key=lambda x: x["distance"])
471
- knn = distances_embedding[:n_results]
472
-
473
- # Assign identity if closest match is below distance threshold
474
- if knn and knn[0]["distance"] < 0.8:
475
- identity = knn[0]["identity"]
476
- else:
477
- identity = "Desconegut"
478
-
479
- except Exception as e:
480
- print(f"Face KNN failed: {e}")
481
- knn = []
482
- identity = "Desconegut"
483
-
484
- faces_detected.append(identity)
485
 
486
  # Now perform OCR detection
487
  ocr_text_easyocr = ""
 
436
  face_col = json.loads(face_col)
437
  faces_detected = []
438
 
439
+ if len(raw_faces)>0:
440
+ for f in raw_faces:
441
+ embedding_image = f
442
+ identity = "Desconegut"
443
+ knn = []
444
+
445
+ # Now search for the 3 nearest neighbors in the database for each embedding.
446
+ if face_col and embedding_image is not None:
447
+ try:
448
+ num_embeddings = len(face_col)
449
+
450
+ if num_embeddings < 1:
451
+ knn = []
452
+ identity = "Desconegut"
453
+
454
+ else:
455
+ n_results = min(3, num_embeddings)
456
+
457
+ embedding_image = np.array(embedding_image)
458
+
459
+ distances_embedding = []
460
+
461
+ # Compute Euclidean distance between the detected face and each stored embedding
462
+ for image_base_datos in face_col:
463
+ image_base_datos_embedding = np.array(image_base_datos["embedding"])
464
+ distance = np.linalg.norm(embedding_image - image_base_datos_embedding)
465
+ distances_embedding.append({
466
+ "identity": image_base_datos["nombre"],
467
+ "distance": float(distance)
468
+ })
469
+
470
+ # Sort by distance and keep the top N matches
471
+ distances_embedding = sorted(distances_embedding, key=lambda x: x["distance"])
472
+ knn = distances_embedding[:n_results]
473
+
474
+ # Assign identity if closest match is below distance threshold
475
+ if knn and knn[0]["distance"] < 0.8:
476
+ identity = knn[0]["identity"]
477
+ else:
478
+ identity = "Desconegut"
479
+
480
+ except Exception as e:
481
+ print(f"Face KNN failed: {e}")
482
  knn = []
483
  identity = "Desconegut"
484
+
485
+ faces_detected.append(identity)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
 
487
  # Now perform OCR detection
488
  ocr_text_easyocr = ""