提高视频帧率

This commit is contained in:
2025-10-08 11:51:28 +08:00
parent f40d6ffcb6
commit f0b4c5a8bf
13 changed files with 133 additions and 648 deletions

View File

@@ -129,17 +129,13 @@ async def detect_file(
model_name: str,
file: UploadFile = File(...)
):
# 1. 打印 model_name直接打印字符串即可
print(f"接收到的 model_name: {model_name}")
# 2. 打印 file 的基本信息(文件名、内容类型等)
print(f"文件名: {file.filename}")
print(f"文件内容类型: {file.content_type}") # 例如 image/jpeg、text/plain 等
"""Detect objects in an uploaded image file"""
print(f"接收到的 model_name: {model_name}")
print(f"文件名: {file.filename}")
print(f"文件内容类型: {file.content_type}")
global model_manager
if not model_manager:
raise HTTPException(status_code=500, detail="Model manager not initialized")
@@ -151,16 +147,39 @@ async def detect_file(
# Read uploaded file
try:
contents = await file.read()
print(f"文件大小: {len(contents)} 字节")
if len(contents) == 0:
raise HTTPException(status_code=400, detail="Empty file")
nparr = np.frombuffer(contents, np.uint8)
print(f"numpy数组形状: {nparr.shape}, dtype: {nparr.dtype}")
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if image is None:
raise HTTPException(status_code=400, detail="Invalid image data")
print("错误: cv2.imdecode 返回 None")
raise HTTPException(status_code=400, detail="Invalid image data - failed to decode")
print(f"解码后图像形状: {image.shape}, dtype: {image.dtype}")
except HTTPException:
raise
except Exception as e:
print(f"处理图像时出错: {str(e)}")
import traceback
traceback.print_exc()
raise HTTPException(status_code=400, detail=f"Failed to process image: {str(e)}")
# Run detection
detections, inference_time = detector.detect(image)
try:
detections, inference_time = detector.detect(image)
print(f"检测完成: 找到 {len(detections)} 个目标, 耗时 {inference_time:.2f}ms")
except Exception as e:
print(f"推理过程中出错: {str(e)}")
import traceback
traceback.print_exc()
raise HTTPException(status_code=500, detail=f"Detection failed: {str(e)}")
return DetectionResponse(
model_name=model_name,