44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Layout Detection Script using PaddleOCR PP-DocLayout
|
|
Outputs JSON with detected layout regions including seal
|
|
"""
|
|
import sys
|
|
import json
|
|
from paddleocr import LayoutDetection
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print(json.dumps({"error": "Usage: python layout_detect.py <image_path>"}))
|
|
sys.exit(1)
|
|
|
|
image_path = sys.argv[1]
|
|
|
|
try:
|
|
# Use PP-DocLayout_plus-L model (20 classes including seal)
|
|
model = LayoutDetection(model_name="PP-DocLayout_plus-L")
|
|
output = model.predict(image_path, batch_size=1, layout_nms=True)
|
|
|
|
results = []
|
|
for res in output:
|
|
# res contains boxes: [[x1, y1, x2, y2, label, score], ...]
|
|
for box in res["boxes"]:
|
|
x1, y1, x2, y2 = box["coordinate"]
|
|
results.append({
|
|
"label": box["label"],
|
|
"score": float(box["score"]),
|
|
"x1": float(x1),
|
|
"y1": float(y1),
|
|
"x2": float(x2),
|
|
"y2": float(y2)
|
|
})
|
|
|
|
print(json.dumps({"success": True, "detections": results}))
|
|
except Exception as e:
|
|
print(json.dumps({"error": str(e)}))
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|