skibi11 commited on
Commit
0550be8
·
verified ·
1 Parent(s): 0bc9984
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -96,8 +96,6 @@ def run_leukocoria_prediction(iris_crop):
96
  # --- 3. FastAPI Application ---
97
  app = FastAPI()
98
 
99
- # In app.py, replace the existing function with this one for testing
100
-
101
  @app.post("/detect/")
102
  async def full_detection_pipeline(image: UploadFile = File(...)):
103
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
@@ -113,8 +111,6 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
113
  if not detect_faces_roboflow(temp_image_path):
114
  return JSONResponse(status_code=400, content={"error": "No face detected."})
115
 
116
- # --- This is the test logic with eye_crops.reverse() removed ---
117
-
118
  image_to_process = raw_image
119
  was_mirrored = False
120
 
@@ -146,16 +142,16 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
146
  initial_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
147
  print(f"--- 5. Initial eye coordinates (x,y,w,h): {initial_boxes} ---")
148
 
149
- # Sort the eyes from left to right based on their position in the image
150
  eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
151
 
152
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
153
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
154
 
155
- # --- THE CHANGE ---
156
- # The eye_crops.reverse() line has been removed for this test.
157
  if was_mirrored:
158
- print("--- 7. Image was mirrored. (Reverse logic is currently disabled for testing) ---")
 
 
 
159
 
160
  flags = {}
161
  eye_images_b64 = {}
@@ -177,8 +173,10 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
177
  else:
178
  flags[side] = None
179
 
 
 
180
  print("--- 10. Final generated flags:", flags, "---")
181
-
182
  is_success_main, buffer_main = cv2.imencode(".jpg", image_to_process)
183
  analyzed_image_b64 = ""
184
  if is_success_main:
 
96
  # --- 3. FastAPI Application ---
97
  app = FastAPI()
98
 
 
 
99
  @app.post("/detect/")
100
  async def full_detection_pipeline(image: UploadFile = File(...)):
101
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
 
111
  if not detect_faces_roboflow(temp_image_path):
112
  return JSONResponse(status_code=400, content={"error": "No face detected."})
113
 
 
 
114
  image_to_process = raw_image
115
  was_mirrored = False
116
 
 
142
  initial_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
143
  print(f"--- 5. Initial eye coordinates (x,y,w,h): {initial_boxes} ---")
144
 
 
145
  eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
146
 
147
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
148
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
149
 
 
 
150
  if was_mirrored:
151
+ print("--- 7. Image was mirrored, reversing eye order for correct labeling. ---")
152
+ eye_crops.reverse()
153
+ reversed_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
154
+ print(f"--- 8. Reversed eye coordinates (x,y,w,h): {reversed_boxes} ---")
155
 
156
  flags = {}
157
  eye_images_b64 = {}
 
173
  else:
174
  flags[side] = None
175
 
176
+ # --- THIS BLOCK IS NOW CORRECTLY UN-INDENTED ---
177
+ # It runs AFTER the 'for' loop is complete.
178
  print("--- 10. Final generated flags:", flags, "---")
179
+
180
  is_success_main, buffer_main = cv2.imencode(".jpg", image_to_process)
181
  analyzed_image_b64 = ""
182
  if is_success_main: