fix: PaddleOCR v3 API — explicit model name + predict() statt ocr()
Some checks failed
Deploy to Coolify / deploy (push) Has been cancelled
Some checks failed
Deploy to Coolify / deploy (push) Has been cancelled
lang="latin" braucht text_recognition_model_name in PP-OCRv5. Neue API nutzt predict() statt ocr(), Ergebnis-Format angepasst. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,8 +19,11 @@ def get_engine():
|
|||||||
from paddleocr import PaddleOCR
|
from paddleocr import PaddleOCR
|
||||||
|
|
||||||
_engine = PaddleOCR(
|
_engine = PaddleOCR(
|
||||||
lang="latin",
|
lang="en",
|
||||||
use_angle_cls=True,
|
text_recognition_model_name="latin_PP-OCRv5_mobile_rec",
|
||||||
|
use_doc_orientation_classify=False,
|
||||||
|
use_doc_unwarping=False,
|
||||||
|
use_textline_orientation=False,
|
||||||
show_log=False,
|
show_log=False,
|
||||||
)
|
)
|
||||||
return _engine
|
return _engine
|
||||||
@@ -44,25 +47,31 @@ async def ocr(
|
|||||||
img_np = np.array(img)
|
img_np = np.array(img)
|
||||||
|
|
||||||
engine = get_engine()
|
engine = get_engine()
|
||||||
result = engine.ocr(img_np)
|
result = engine.predict(img_np)
|
||||||
|
|
||||||
words = []
|
words = []
|
||||||
for line in result[0] or []:
|
for item in result:
|
||||||
box, (text, conf) = line[0], line[1]
|
rec_texts = item.get("rec_texts", [])
|
||||||
x_min = min(p[0] for p in box)
|
rec_scores = item.get("rec_scores", [])
|
||||||
y_min = min(p[1] for p in box)
|
dt_polys = item.get("dt_polys", [])
|
||||||
x_max = max(p[0] for p in box)
|
|
||||||
y_max = max(p[1] for p in box)
|
for text, score, poly in zip(rec_texts, rec_scores, dt_polys):
|
||||||
words.append(
|
if not text or not text.strip():
|
||||||
{
|
continue
|
||||||
"text": text,
|
xs = [p[0] for p in poly]
|
||||||
"left": int(x_min),
|
ys = [p[1] for p in poly]
|
||||||
"top": int(y_min),
|
x_min, x_max = min(xs), max(xs)
|
||||||
"width": int(x_max - x_min),
|
y_min, y_max = min(ys), max(ys)
|
||||||
"height": int(y_max - y_min),
|
words.append(
|
||||||
"conf": round(conf * 100, 1),
|
{
|
||||||
}
|
"text": text.strip(),
|
||||||
)
|
"left": int(x_min),
|
||||||
|
"top": int(y_min),
|
||||||
|
"width": int(x_max - x_min),
|
||||||
|
"height": int(y_max - y_min),
|
||||||
|
"conf": round(float(score) * 100, 1),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"words": words,
|
"words": words,
|
||||||
|
|||||||
Reference in New Issue
Block a user