MCPcopy Create free account
hub / github.com/VitoHowe/glm-coding / choose_best_mask

Function choose_best_mask

app/services/tenvision_adapter.py:311–324  ·  view source on GitHub ↗
(crop, expected_count)

Source from the content-addressed store, hash-verified

309 for mask in masks:
310 comps = connected_components(mask, min_area=3)
311 fg_ratio = float(np.count_nonzero(mask)) / max(mask.size, 1)
312 score = abs(len(comps) - expected_count) * 3.0 + abs(fg_ratio - 0.18) * 4.0
313 if score < best_score:
314 best_score = score
315 best_mask = mask
316
317 return best_mask
318
319
320def split_mask_to_boxes(mask, origin_x, origin_y, expected_count):
321 h, w = mask.shape
322 horizontal = w >= h
323 comps = connected_components(mask, min_area=4)
324
325 if len(comps) >= expected_count:
326 comps = sorted(comps, key=lambda c: c['bbox'][0] if horizontal else c['bbox'][1])
327 if len(comps) > expected_count:

Callers 2

split_ocr_itemFunction · 0.85

Calls 2

build_color_masksFunction · 0.85
connected_componentsFunction · 0.85

Tested by

no test coverage detected