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

Function analyze_image_bytes

app/services/tenvision_adapter.py:931–995  ·  view source on GitHub ↗
(
    image_bytes: bytes,
    bg_offset: dict | None = None,
    prompt_text: str | None = None,
    use_deep_learning: bool | None = None,
    include_debug: bool = False,
)

Source from the content-addressed store, hash-verified

929 include_debug: bool = False,
930) -> dict[str, Any]:
931 result, vis = run_pipeline_bytes(image_bytes, prompt_text, include_debug=include_debug)
932
933 points = []
934 for idx, box in enumerate(result['click_boxes']):
935 if box is None:
936 continue
937 x, y, w, h = box
938 center_x = x + w // 2
939 center_y = y + h // 2
940
941 out_x = float(center_x)
942 out_y = float(center_y)
943 if bg_offset:
944 out_x -= float(bg_offset['x'])
945 out_y -= float(bg_offset['y'])
946
947 label = result['click_chars'][idx]
948 if label is None and idx < len(result['target_chars']):
949 label = result['target_chars'][idx]
950
951 points.append(
952 {
953 'order': idx + 1,
954 'x': int(round(out_x)),
955 'y': int(round(out_y)),
956 'label': label or '',
957 }
958 )
959
960 matched_scores = [score for score, box in zip(result['click_scores'], result['click_boxes']) if box is not None]
961 prompt_len = len(result['target_chars'])
962 matched_ratio = (len(points) / prompt_len) if prompt_len else 0.0
963 ocr_confidence = (sum(matched_scores) / len(matched_scores)) if matched_scores else 0.0
964 confidence = round(float(matched_ratio * ocr_confidence), 4)
965
966 debug_png = b''
967 if include_debug:
968 success, encoded = cv2.imencode('.png', vis)
969 debug_png = encoded.tobytes() if success else b''
970
971 return {
972 'width': result['image_width'],
973 'height': result['image_height'],
974 'points': points,
975 'candidate_count': len(result['candidate_boxes']),
976 'confidence': confidence,
977 'debug_png': debug_png,
978 'target_chars': result['target_chars'],
979 'prompt_text': result['prompt_text'],
980 'prompt_bbox': result['prompt_bbox'],
981 'candidate_boxes': result['candidate_boxes'],
982 'click_boxes': result['click_boxes'],
983 'click_chars': result['click_chars'],
984 'fallback_method': result.get('fallback_method') or '',
985 'recognized_text': result['prompt_text'],
986 'algorithm': 'catpcha_v2',
987 'use_deep_learning': bool(use_deep_learning) if use_deep_learning is not None else False,
988 }

Callers

nothing calls this directly

Calls 1

run_pipeline_bytesFunction · 0.85

Tested by

no test coverage detected