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

Function object_detection

ddddocr/api/routes.py:121–145  ·  view source on GitHub ↗

执行目标检测

(request: DetectionRequest)

Source from the content-addressed store, hash-verified

119
120 @app.post("/detect", response_model=APIResponse)
121 async def object_detection(request: DetectionRequest):
122 """执行目标检测"""
123 try:
124 if not service.det_instance:
125 raise HTTPException(status_code=400, detail="目标检测功能未初始化,请先调用 /initialize 接口")
126
127 if "detection" not in service.enabled_features:
128 raise HTTPException(status_code=400, detail="目标检测功能已禁用")
129
130 # 解码base64图片
131 try:
132 image_data = base64.b64decode(request.image)
133 except Exception:
134 raise HTTPException(status_code=400, detail="图片base64解码失败")
135
136 # 执行目标检测
137 bboxes = service.det_instance.detection(image_data)
138
139 response_data = DetectionResponse(bboxes=bboxes)
140 return APIResponse(success=True, message="目标检测成功", data=response_data.dict())
141
142 except HTTPException:
143 raise
144 except Exception as e:
145 return APIResponse(success=False, message=f"目标检测失败: {str(e)}")
146
147 @app.post("/slide-match", response_model=APIResponse)
148 async def slide_match(request: SlideMatchRequest):

Callers

nothing calls this directly

Calls 3

APIResponseClass · 0.85
detectionMethod · 0.80
DetectionResponseClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…