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

Function recognize_yellow_boxes

app/services/tenvision_adapter.py:713–746  ·  view source on GitHub ↗
(image, boxes, prompt_chars, engine)

Source from the content-addressed store, hash-verified

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))
714
715 result = engine.recognize_txt(crops)
716 texts = to_list(getattr(result, 'txts', None))
717 scores = to_list(getattr(result, 'scores', None))
718 prompt_set = set(prompt_chars)
719 candidates = []
720
721 for index, box in enumerate(boxes):
722 text = normalize_text(str(texts[index])) if index < len(texts) else ''
723 score = float(scores[index]) if index < len(scores) else 0.0
724 chars = extract_chinese_chars(text)
725 exact_char = next((char for char in chars if char in prompt_set), '')
726 candidates.append(
727 {
728 'bbox': tuple(int(v) for v in box),
729 'char': exact_char,
730 'text': exact_char,
731 'score': score,
732 'source_text': text,
733 'source_index': index,
734 'source': 'yellow_component_rec',
735 'area': int(box[2] * box[3]),
736 }
737 )
738
739 return fill_missing_prompt_chars(candidates, prompt_chars)
740
741
742def fill_missing_prompt_chars(candidates, prompt_chars):
743 used_ids = set()
744 resolved = []
745
746 for prompt_char in prompt_chars:
747 options = [
748 candidate
749 for candidate in candidates

Callers 1

Calls 5

crop_bboxFunction · 0.85
to_listFunction · 0.85
normalize_textFunction · 0.85
extract_chinese_charsFunction · 0.85

Tested by

no test coverage detected