feat: round output JSON floats to 2dp + unify ensure_ascii for asr/asrx
This commit is contained in:
@@ -27,6 +27,17 @@ SWIFT_OCR_ALT = os.path.join(
|
||||
SWIFT_PROGRESS_RE = re.compile(r"\[SwiftOCR\] Progress:\s*(\d+)%")
|
||||
|
||||
|
||||
def _round_json_numbers(obj):
|
||||
"""Recursively round all float values to 2 decimal places (JSON output only)."""
|
||||
if isinstance(obj, float):
|
||||
return round(obj, 2)
|
||||
if isinstance(obj, dict):
|
||||
return {k: _round_json_numbers(v) for k, v in obj.items()}
|
||||
if isinstance(obj, list):
|
||||
return [_round_json_numbers(v) for v in obj]
|
||||
return obj
|
||||
|
||||
|
||||
def process_ocr(
|
||||
video_path: str,
|
||||
output_path: str,
|
||||
@@ -121,7 +132,7 @@ if __name__ == "__main__":
|
||||
publisher)
|
||||
|
||||
with open(args.output_path, "w") as f:
|
||||
json.dump(result, f, indent=2)
|
||||
json.dump(_round_json_numbers(result), f, indent=2)
|
||||
print(f"OCR: {len(result.get('frames', []))} frames with text")
|
||||
if publisher:
|
||||
publisher.complete("ocr", f"{len(result.get('frames',[]))} frames")
|
||||
|
||||
Reference in New Issue
Block a user