MCPcopy Index your code
hub / github.com/sml2h3/ddddocr / object_detection

Function object_detection

ddddocr/api/app.py:501–539  ·  view source on GitHub ↗

目标检测功能 - 接收Base64编码的图片

(
    request: Base64Image,
    background_tasks: BackgroundTasks,
    ocr: bool = Query(False, description="是否启用OCR功能"),
    det: bool = Query(True, 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

499# 目标检测端点
500@app.post("/det", response_model=DetectionResponse)
501async def object_detection(
502 request: Base64Image,
503 background_tasks: BackgroundTasks,
504 ocr: bool = Query(False, description="是否启用OCR功能"),
505 det: bool = Query(True, description="是否启用目标检测功能"),
506 use_gpu: bool = Query(default_use_gpu, description="是否使用GPU加速"),
507 device_id: int = Query(default_device_id, description="GPU设备ID"),
508 show_ad: bool = Query(default_show_ad, description="是否显示广告")
509):
510 """
511 目标检测功能 - 接收Base64编码的图片
512 """
513 try:
514 img_data = _decode_base64_bytes(request.image)
515 except HTTPException:
516 raise
517
518 config_key = f"ocr={ocr}-det={det}-gpu={use_gpu}-dev={device_id}"
519
520 ocr_instance = get_ocr_instance(
521 config_key, ocr, det, False, False, use_gpu, device_id, show_ad,
522 default_import_onnx_path, default_charsets_path
523 )
524
525 start_time = time.time()
526 try:
527 result = ocr_instance.detection(img_bytes=img_data)
528 except (DdddOcrInputError, InvalidImageError) as exc:
529 raise HTTPException(status_code=400, detail=str(exc)) from exc
530 except Exception as exc:
531 logger.error(f"目标检测失败: {str(exc)}")
532 raise HTTPException(status_code=500, detail=f"目标检测失败: {str(exc)}") from exc
533
534 background_tasks.add_task(cleanup_inactive_instances)
535
536 return {
537 "result": result,
538 "processing_time": time.time() - start_time
539 }
540
541# 目标检测端点 - 文件上传
542@app.post("/det/file", response_model=DetectionResponse)

Callers

nothing calls this directly

Calls 3

_decode_base64_bytesFunction · 0.85
get_ocr_instanceFunction · 0.85
detectionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…