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

Function build_yellow_component_boxes

app/services/tenvision_adapter.py:674–710  ·  view source on GitHub ↗
(image, expected_count)

Source from the content-addressed store, hash-verified

672 min_w = max(28, int(image_w * 0.04))
673 min_h = max(36, int(image_h * 0.075))
674 max_w = max(min_w, int(image_w * 0.28))
675 max_h = max(min_h, int(image_h * 0.28))
676 min_area = max(900, int(image_w * image_h * 0.0025))
677
678 mask = hsv_yellow_mask(image)
679 boxes = []
680 for comp in connected_components(mask, min_area=80):
681 x, y, w, h = comp['bbox']
682 bbox_area = w * h
683 if w < min_w or h < min_h:
684 continue
685 if w > max_w or h > max_h:
686 continue
687 if bbox_area < min_area:
688 continue
689 boxes.append(
690 {
691 'bbox': (int(x), int(y), int(w), int(h)),
692 'area': int(comp['area']),
693 'bbox_area': int(bbox_area),
694 }
695 )
696
697 if len(boxes) < expected_count:
698 return []
699
700 if len(boxes) > expected_count:
701 boxes = sorted(boxes, key=lambda item: (item['bbox_area'], item['area']), reverse=True)[:expected_count]
702
703 return [item['bbox'] for item in sorted(boxes, key=lambda item: (item['bbox'][1], item['bbox'][0]))]
704
705
706def recognize_yellow_boxes(image, boxes, prompt_chars, engine):
707 if not boxes:
708 return []
709
710 crops = []
711 for box in boxes:
712 crop, _ = crop_bbox(image, box, pad=8)
713 crops.append(cv2.resize(crop, None, fx=3, fy=3, interpolation=cv2.INTER_CUBIC))

Callers 1

Calls 2

hsv_yellow_maskFunction · 0.85
connected_componentsFunction · 0.85

Tested by

no test coverage detected