Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -126,6 +126,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
|
|
126 |
finally:
|
127 |
os.remove(temp_mirrored_image_path)
|
128 |
|
|
|
129 |
if error_msg or len(eye_crops) != 2:
|
130 |
return JSONResponse(
|
131 |
status_code=400,
|
@@ -136,7 +137,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
|
|
136 |
eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
|
137 |
|
138 |
# --- NEW: If the image was mirrored, reverse the sorted list ---
|
139 |
-
# This ensures the person's right eye is always first.
|
140 |
if was_mirrored:
|
141 |
print("--- Image was mirrored, reversing eye order for correct labeling. ---")
|
142 |
eye_crops.reverse()
|
@@ -144,7 +145,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
|
|
144 |
flags = {}
|
145 |
eye_images_b64 = {}
|
146 |
for i, eye_crop in enumerate(eye_crops):
|
147 |
-
# Now, because of the reverse, i=0 is ALWAYS the person's right eye
|
148 |
side = "right" if i == 0 else "left"
|
149 |
|
150 |
is_success, buffer = cv2.imencode(".jpg", eye_crop)
|
|
|
126 |
finally:
|
127 |
os.remove(temp_mirrored_image_path)
|
128 |
|
129 |
+
# Final check after both attempts
|
130 |
if error_msg or len(eye_crops) != 2:
|
131 |
return JSONResponse(
|
132 |
status_code=400,
|
|
|
137 |
eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
|
138 |
|
139 |
# --- NEW: If the image was mirrored, reverse the sorted list ---
|
140 |
+
# This ensures the person's right eye is always first in the list.
|
141 |
if was_mirrored:
|
142 |
print("--- Image was mirrored, reversing eye order for correct labeling. ---")
|
143 |
eye_crops.reverse()
|
|
|
145 |
flags = {}
|
146 |
eye_images_b64 = {}
|
147 |
for i, eye_crop in enumerate(eye_crops):
|
148 |
+
# Now, because of the sort (and potential reverse), i=0 is ALWAYS the person's right eye
|
149 |
side = "right" if i == 0 else "left"
|
150 |
|
151 |
is_success, buffer = cv2.imencode(".jpg", eye_crop)
|