refactor: 重构图片检测功能,拆分组件并优化返回格式
1. 后端api修改:将图片结果返回从文件路径改为base64格式,移除本地文件存储 2. 新增图片检测组件ImageDetection.vue,封装独立的图片检测UI逻辑 3. 重构Home页面,使用tab切换图片/视频检测模块,简化原有布局 4. 更新web包名与rollup依赖版本
This commit is contained in:
@@ -36,18 +36,17 @@ async def detect_image(
|
||||
|
||||
if result['success']:
|
||||
annotated_frame = detection_service.draw_detections(frame, result['detections'])
|
||||
|
||||
import uuid
|
||||
result_filename = f"result_{uuid.uuid4().hex[:8]}.jpg"
|
||||
result_path = f"static/results/{result_filename}"
|
||||
cv2.imwrite(result_path, annotated_frame)
|
||||
|
||||
|
||||
# 将标注后的图片转换为 base64
|
||||
_, buffer = cv2.imencode('.jpg', annotated_frame)
|
||||
img_base64 = base64.b64encode(buffer).decode('utf-8')
|
||||
|
||||
return ImageDetectionResult(
|
||||
success=True,
|
||||
message="检测完成",
|
||||
data={
|
||||
"detections": result['detections'],
|
||||
"image_url": f"/static/results/{result_filename}",
|
||||
"image_base64": img_base64,
|
||||
"stats": result['stats']
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user