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

Function recognize_prompt_boxes

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

Source from the content-addressed store, hash-verified

483 for box in boxes:
484 crop, _ = crop_bbox(image, box, pad=8)
485 if crop.size == 0:
486 crops.append(np.zeros((8, 8, 3), dtype=np.uint8))
487 continue
488 crops.append(cv2.resize(crop, None, fx=3, fy=3, interpolation=cv2.INTER_CUBIC))
489
490 result = engine.recognize_txt(crops)
491 texts = to_list(getattr(result, 'txts', None))
492 scores = to_list(getattr(result, 'scores', None))
493 prompt_set = set(prompt_chars or [])
494 candidates = []
495
496 for index, box in enumerate(boxes):
497 source_text = normalize_text(str(texts[index])) if index < len(texts) else ''
498 score = float(scores[index]) if index < len(scores) else 0.0
499 chars = extract_chinese_chars(source_text)
500 exact_char = next((char for char in chars if char in prompt_set), '')
501 candidates.append(
502 {
503 'bbox': tuple(int(v) for v in box),
504 'char': exact_char,
505 'text': exact_char,
506 'score': score,
507 'source_text': source_text,
508 'source_index': index,
509 'source': 'split_box_recognize_txt',
510 'area': int(box[2] * box[3]),
511 }
512 )
513
514 return candidates
515
516
517def repair_candidates_by_prompt(candidates, prompt_chars):
518 if len(prompt_chars) < 2 or not candidates:
519 return candidates
520
521 used_ids = set()
522 missing_chars = []
523 for prompt_char in prompt_chars:
524 options = [

Callers 1

split_ocr_itemFunction · 0.85

Calls 4

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

Tested by

no test coverage detected