skibi11 commited on
Commit
afea313
·
verified ·
1 Parent(s): 9532436

identation of for loop fixed

Browse files
Files changed (1) hide show
  1. app.py +4 -20
app.py CHANGED
@@ -103,16 +103,13 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
103
 
104
  if not detect_faces_roboflow(temp_image_path):
105
  return JSONResponse(status_code=400, content={"error": "No face detected."})
106
-
107
  image_to_process = raw_image
108
  was_mirrored = False
109
 
110
- print("--- 1. Attempting detection on original image... ---")
111
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, image_to_process)
112
- print(f"--- 2. Found {len(eye_crops)} eyes in original image. ---")
113
 
114
  if len(eye_crops) != 2:
115
- print("--- 3. Original failed. Attempting detection on mirrored image... ---")
116
  mirrored_image = cv2.flip(raw_image, 1)
117
  image_to_process = mirrored_image
118
  was_mirrored = True
@@ -122,7 +119,6 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
122
  temp_mirrored_image_path = tmp_mirrored.name
123
  try:
124
  eye_crops, error_msg = detect_eyes_roboflow(temp_mirrored_image_path, image_to_process)
125
- print(f"--- 4. Found {len(eye_crops)} eyes in mirrored image. ---")
126
  finally:
127
  os.remove(temp_mirrored_image_path)
128
 
@@ -132,32 +128,20 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
132
  content={"error": "Could not detect exactly two eyes. Please try another photo."}
133
  )
134
 
135
- # Get the bounding box coordinates before sorting
136
- initial_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
137
- print(f"--- 5. Initial eye coordinates (x,y,w,h): {initial_boxes} ---")
138
-
139
- # Sort the eyes from left to right based on their position in the image
140
  eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
141
 
142
- sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
143
- print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
144
-
145
  if was_mirrored:
146
- print("--- 7. Image was mirrored, reversing eye order for correct labeling. ---")
147
  eye_crops.reverse()
148
- reversed_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
149
- print(f"--- 8. Reversed eye coordinates (x,y,w,h): {reversed_boxes} ---")
150
 
151
  flags = {}
152
  eye_images_b64 = {}
153
  for i, eye_crop in enumerate(eye_crops):
154
  side = "right" if i == 0 else "left"
155
- print(f"--- 9. Processing loop index {i}, assigning to: {side} eye. ---")
156
 
157
- # ... (rest of the processing loop remains the same) ...
158
  is_success, buffer = cv2.imencode(".jpg", eye_crop)
159
  if is_success:
160
  eye_images_b64[side] = "data:image/jpeg;base64," + base64.b64encode(buffer).decode("utf-8")
 
161
  pred = get_largest_iris_prediction(eye_crop)
162
  if pred:
163
  x1, y1 = int(pred['x'] - pred['width'] / 2), int(pred['y'] - pred['height'] / 2)
@@ -168,8 +152,8 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
168
  else:
169
  flags[side] = None
170
 
171
- print("--- 10. Final generated flags:", flags, "---")
172
-
173
  is_success_main, buffer_main = cv2.imencode(".jpg", image_to_process)
174
  analyzed_image_b64 = ""
175
  if is_success_main:
 
103
 
104
  if not detect_faces_roboflow(temp_image_path):
105
  return JSONResponse(status_code=400, content={"error": "No face detected."})
106
+
107
  image_to_process = raw_image
108
  was_mirrored = False
109
 
 
110
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, image_to_process)
 
111
 
112
  if len(eye_crops) != 2:
 
113
  mirrored_image = cv2.flip(raw_image, 1)
114
  image_to_process = mirrored_image
115
  was_mirrored = True
 
119
  temp_mirrored_image_path = tmp_mirrored.name
120
  try:
121
  eye_crops, error_msg = detect_eyes_roboflow(temp_mirrored_image_path, image_to_process)
 
122
  finally:
123
  os.remove(temp_mirrored_image_path)
124
 
 
128
  content={"error": "Could not detect exactly two eyes. Please try another photo."}
129
  )
130
 
 
 
 
 
 
131
  eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
132
 
 
 
 
133
  if was_mirrored:
 
134
  eye_crops.reverse()
 
 
135
 
136
  flags = {}
137
  eye_images_b64 = {}
138
  for i, eye_crop in enumerate(eye_crops):
139
  side = "right" if i == 0 else "left"
 
140
 
 
141
  is_success, buffer = cv2.imencode(".jpg", eye_crop)
142
  if is_success:
143
  eye_images_b64[side] = "data:image/jpeg;base64," + base64.b64encode(buffer).decode("utf-8")
144
+
145
  pred = get_largest_iris_prediction(eye_crop)
146
  if pred:
147
  x1, y1 = int(pred['x'] - pred['width'] / 2), int(pred['y'] - pred['height'] / 2)
 
152
  else:
153
  flags[side] = None
154
 
155
+ # --- THIS BLOCK IS NOW CORRECTLY UN-INDENTED ---
156
+ # It runs AFTER the 'for' loop is complete.
157
  is_success_main, buffer_main = cv2.imencode(".jpg", image_to_process)
158
  analyzed_image_b64 = ""
159
  if is_success_main: