skibi11 commited on
Commit
6531628
·
verified ·
1 Parent(s): 381811c

with enhanced_eye_crop

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -59,10 +59,17 @@ def detect_eyes_roboflow(image_path, raw_image):
59
  print(f"Error in Roboflow eye detection: {e}")
60
  return [], str(e)
61
 
 
 
62
  def get_largest_iris_prediction(eye_crop):
63
  "Calls Roboflow to find the largest iris using a temporary file for reliability."
 
 
 
 
64
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
65
- cv2.imwrite(tmp.name, eye_crop)
 
66
  temp_iris_path = tmp.name
67
 
68
  try:
@@ -144,7 +151,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
144
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
145
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
146
 
147
- # --- THE CRITICAL FIX ---
148
  if was_mirrored:
149
  print("--- 7. Image was mirrored, reversing eye order for correct labeling. ---")
150
  eye_crops.reverse()
@@ -154,6 +161,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
154
  flags = {}
155
  eye_images_b64 = {}
156
  for i, eye_crop in enumerate(eye_crops):
 
157
  side = "right" if i == 0 else "left"
158
  print(f"--- 9. Processing loop index {i}, assigning to: {side} eye. ---")
159
 
 
59
  print(f"Error in Roboflow eye detection: {e}")
60
  return [], str(e)
61
 
62
+ # In app.py, replace the existing function with this one
63
+
64
  def get_largest_iris_prediction(eye_crop):
65
  "Calls Roboflow to find the largest iris using a temporary file for reliability."
66
+
67
+ # --- NEW: Enhance the eye crop before saving it ---
68
+ enhanced_eye_crop = enhance_image_unsharp_mask(eye_crop)
69
+
70
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
71
+ # Save the ENHANCED version, not the original
72
+ cv2.imwrite(tmp.name, enhanced_eye_crop)
73
  temp_iris_path = tmp.name
74
 
75
  try:
 
151
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
152
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
153
 
154
+ # --- THE CRITICAL FIX for SWAPPED LABELS ---
155
  if was_mirrored:
156
  print("--- 7. Image was mirrored, reversing eye order for correct labeling. ---")
157
  eye_crops.reverse()
 
161
  flags = {}
162
  eye_images_b64 = {}
163
  for i, eye_crop in enumerate(eye_crops):
164
+ # Because of the sort and potential reverse, i=0 is ALWAYS the person's right eye
165
  side = "right" if i == 0 else "left"
166
  print(f"--- 9. Processing loop index {i}, assigning to: {side} eye. ---")
167