MCPcopy
hub / github.com/sml2h3/ddddocr / slide_match_recognition

Function slide_match_recognition

ddddocr/api/app.py:593–633  ·  view source on GitHub ↗

滑块验证码匹配 - 接收Base64编码的目标图和背景图

(
    request: SlideMatchRequest,
    background_tasks: BackgroundTasks,
    ocr: bool = Query(False, description="是否启用OCR功能"),
    det: bool = Query(False, description="是否启用目标检测功能"),
    use_gpu: bool = Query(default_use_gpu, description="是否使用GPU加速"),
    device_id: int = Query(default_device_id, description="GPU设备ID"),
    show_ad: bool = Query(default_show_ad, description="是否显示广告")
)

Source from the content-addressed store, hash-verified

591# 滑块匹配端点
592@app.post("/slide_match", response_model=SlideMatchResponse)
593async def slide_match_recognition(
594 request: SlideMatchRequest,
595 background_tasks: BackgroundTasks,
596 ocr: bool = Query(False, description="是否启用OCR功能"),
597 det: bool = Query(False, description="是否启用目标检测功能"),
598 use_gpu: bool = Query(default_use_gpu, description="是否使用GPU加速"),
599 device_id: int = Query(default_device_id, description="GPU设备ID"),
600 show_ad: bool = Query(default_show_ad, description="是否显示广告")
601):
602 """
603 滑块验证码匹配 - 接收Base64编码的目标图和背景图
604 """
605 target_data = _decode_base64_bytes(request.target_image)
606 background_data = _decode_base64_bytes(request.background_image)
607
608 config_key = f"ocr={ocr}-det={det}-gpu={use_gpu}-dev={device_id}"
609
610 ocr_instance = get_ocr_instance(
611 config_key, ocr, det, False, False, use_gpu, device_id, show_ad,
612 default_import_onnx_path, default_charsets_path
613 )
614
615 start_time = time.time()
616 try:
617 result = ocr_instance.slide_match(
618 target_bytes=target_data,
619 background_bytes=background_data,
620 simple_target=request.simple_target,
621 flag=request.flag
622 )
623 except (DdddOcrInputError, InvalidImageError) as exc:
624 raise HTTPException(status_code=400, detail=str(exc)) from exc
625 except Exception as exc:
626 logger.error(f"滑块匹配失败: {str(exc)}")
627 raise HTTPException(status_code=500, detail=f"滑块匹配失败: {str(exc)}") from exc
628
629 background_tasks.add_task(cleanup_inactive_instances)
630 return {
631 "result": result,
632 "processing_time": time.time() - start_time
633 }
634
635# 滑块比较端点
636@app.post("/slide_comparison", response_model=SlideComparisonResponse)

Callers

nothing calls this directly

Calls 3

_decode_base64_bytesFunction · 0.85
get_ocr_instanceFunction · 0.85
slide_matchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…