滑块验证码图像差异比较 - 接收Base64编码的目标图和背景图
(
request: SlideComparisonRequest,
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="是否显示广告")
)
| 635 | # 滑块比较端点 |
| 636 | @app.post("/slide_comparison", response_model=SlideComparisonResponse) |
| 637 | async def slide_comparison_recognition( |
| 638 | request: SlideComparisonRequest, |
| 639 | background_tasks: BackgroundTasks, |
| 640 | ocr: bool = Query(False, description="是否启用OCR功能"), |
| 641 | det: bool = Query(False, description="是否启用目标检测功能"), |
| 642 | use_gpu: bool = Query(default_use_gpu, description="是否使用GPU加速"), |
| 643 | device_id: int = Query(default_device_id, description="GPU设备ID"), |
| 644 | show_ad: bool = Query(default_show_ad, description="是否显示广告") |
| 645 | ): |
| 646 | """ |
| 647 | 滑块验证码图像差异比较 - 接收Base64编码的目标图和背景图 |
| 648 | """ |
| 649 | target_data = _decode_base64_bytes(request.target_image) |
| 650 | background_data = _decode_base64_bytes(request.background_image) |
| 651 | |
| 652 | config_key = f"ocr={ocr}-det={det}-gpu={use_gpu}-dev={device_id}" |
| 653 | |
| 654 | ocr_instance = get_ocr_instance( |
| 655 | config_key, ocr, det, False, False, use_gpu, device_id, show_ad, |
| 656 | default_import_onnx_path, default_charsets_path |
| 657 | ) |
| 658 | |
| 659 | start_time = time.time() |
| 660 | try: |
| 661 | result = ocr_instance.slide_comparison( |
| 662 | target_bytes=target_data, |
| 663 | background_bytes=background_data |
| 664 | ) |
| 665 | except (DdddOcrInputError, InvalidImageError) as exc: |
| 666 | raise HTTPException(status_code=400, detail=str(exc)) from exc |
| 667 | except Exception as exc: |
| 668 | logger.error(f"滑块比较失败: {str(exc)}") |
| 669 | raise HTTPException(status_code=500, detail=f"滑块比较失败: {str(exc)}") from exc |
| 670 | |
| 671 | background_tasks.add_task(cleanup_inactive_instances) |
| 672 | |
| 673 | return { |
| 674 | "result": result, |
| 675 | "processing_time": time.time() - start_time |
| 676 | } |
| 677 | |
| 678 | # 设置字符范围端点 |
| 679 | # 设置字符范围端点 |
nothing calls this directly
no test coverage detected
searching dependent graphs…