phyloforfun commited on
Commit
2c609f6
·
1 Parent(s): a4b44e3
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -178,13 +178,7 @@ def warp_and_display_images(img, centroids, base_name, flag_mask_rgb, plant_mask
178
  return plant_rgb, plot_rgb, plant_rgb_warp, plant_mask_warp
179
 
180
  def process_image(image_path, flag_lower, flag_upper, plant_lower, plant_upper, loc):
181
- # Ensure session_state variables are initialized
182
- if 'valid_quadrilaterals' not in st.session_state:
183
- st.session_state.valid_quadrilaterals = [perm for perm in itertools.permutations(significant_contours, 4) if is_valid_quadrilateral(get_points_from_contours(perm))]
184
- if 'selected_quad_index' not in st.session_state:
185
- st.session_state.selected_quad_index = 0
186
- if 'centroids' not in st.session_state:
187
- st.session_state.centroids = get_points_from_contours(st.session_state.valid_quadrilaterals[0])
188
 
189
  with loc:
190
  btn_back, btn_next = st.columns([2,2])
@@ -227,6 +221,14 @@ def process_image(image_path, flag_lower, flag_upper, plant_lower, plant_upper,
227
  # Filter out noise based on a predefined area threshold
228
  significant_contours = [cnt for cnt in sorted_contours if cv2.contourArea(cnt) > MIN_AREA]
229
 
 
 
 
 
 
 
 
 
230
  # Logic to handle cases where there are more than 4 significant contours
231
  if len(significant_contours) < 4:
232
  with loc:
 
178
  return plant_rgb, plot_rgb, plant_rgb_warp, plant_mask_warp
179
 
180
  def process_image(image_path, flag_lower, flag_upper, plant_lower, plant_upper, loc):
181
+
 
 
 
 
 
 
182
 
183
  with loc:
184
  btn_back, btn_next = st.columns([2,2])
 
221
  # Filter out noise based on a predefined area threshold
222
  significant_contours = [cnt for cnt in sorted_contours if cv2.contourArea(cnt) > MIN_AREA]
223
 
224
+ # Ensure session_state variables are initialized
225
+ if 'valid_quadrilaterals' not in st.session_state:
226
+ st.session_state.valid_quadrilaterals = [perm for perm in itertools.permutations(significant_contours, 4) if is_valid_quadrilateral(get_points_from_contours(perm))]
227
+ if 'selected_quad_index' not in st.session_state:
228
+ st.session_state.selected_quad_index = 0
229
+ if 'centroids' not in st.session_state:
230
+ st.session_state.centroids = get_points_from_contours(st.session_state.valid_quadrilaterals[0])
231
+
232
  # Logic to handle cases where there are more than 4 significant contours
233
  if len(significant_contours) < 4:
234
  with loc: