(contours, hierarchy)
| 233 | return all_polygons |
| 234 | |
| 235 | def detect_foreground(contours, hierarchy): |
| 236 | hierarchy = np.squeeze(hierarchy, axis=(0,))[:, 2:] |
| 237 | |
| 238 | # find foreground contours (parent == -1) |
| 239 | hierarchy_1 = np.flatnonzero(hierarchy[:, 1] == -1) |
| 240 | foreground_contours = [contours[cont_idx] for cont_idx in hierarchy_1] |
| 241 | |
| 242 | all_holes = [] |
| 243 | for cont_idx in hierarchy_1: |
| 244 | all_holes.append(np.flatnonzero(hierarchy[:, 1] == cont_idx)) |
| 245 | |
| 246 | hole_contours = [] |
| 247 | for hole_ids in all_holes: |
| 248 | holes = [contours[idx] for idx in hole_ids] |
| 249 | hole_contours.append(holes) |
| 250 | |
| 251 | return foreground_contours, hole_contours |
| 252 | |
| 253 | def construct_polygon(foreground_contours, hole_contours, min_area): |
| 254 | polys = [] |
no outgoing calls
no test coverage detected