refactor: 统一CLI输出格式为标准JSON

This commit is contained in:
OpenClaw Agent
2026-02-11 01:10:45 +08:00
parent 06f279451a
commit df15f9a6fb
5 changed files with 134 additions and 50 deletions
+26 -9
View File
@@ -304,7 +304,10 @@ def main():
input_dir = args.input
if args.video:
if not os.path.exists(args.video):
print(f"❌ 视频文件不存在: {args.video}")
print(json.dumps({
"success": False,
"error": f"视频文件不存在: {args.video}"
}, ensure_ascii=False, indent=2))
return 1
# 创建临时帧目录
@@ -312,6 +315,10 @@ def main():
input_dir = extract_frames(args.video, frames_dir, fps=args.fps)
if not input_dir:
print(json.dumps({
"success": False,
"error": "截帧失败"
}, ensure_ascii=False, indent=2))
return 1
# 初始化处理器
@@ -324,19 +331,29 @@ def main():
# 保存结果
processor.save_results(results, args.output, merge=args.merge)
# 打印摘要
# 统一输出格式
total_texts = sum(1 for r in results if r.get("text"))
avg_conf = sum(r.get("confidence", 0) for r in results) / len(results) if results else 0
print(f"\n=== 摘要 ===")
print(f"处理帧数: {len(results)}")
print(f"识别到文字的帧: {total_texts}")
print(f"平均置信度: {avg_conf:.2%}")
output = {
"success": True,
"filename": Path(args.output).name,
"filepath": str(Path(args.output).resolve()),
"message": f"OCR处理完成",
"stats": {
"total_frames": len(results),
"frames_with_text": total_texts,
"avg_confidence": round(avg_conf, 4)
}
}
print(json.dumps(output, ensure_ascii=False, indent=2))
return 0
else:
print("未处理到任何结果")
print(json.dumps({
"success": False,
"error": "未处理到任何结果"
}, ensure_ascii=False, indent=2))
return 1
return 0
if __name__ == "__main__":