#18347·PaddleOCR

识别不准确

作者: xiaoxinmiao创建于 2026年9月5日更新于 2026年9月8日

import os os.environ.setdefault('HUB_DATASET_ENDPOINT', 'https://modelscope.cn') os.environ["PADDLE_PDX_ENABLE_MKLDNN_BYDEFAULT"] = "0" os.environ["FLAGS_use_onednn"] = "0" os.environ["FLAGS_enable_pir_api"] = "0" from paddleocr import PaddleOCR def start_ocr(image_path): ocr = PaddleOCR(use_textline_orientation=True, lang='ch', device='cpu') result = ocr.predict(image_path)

if result:
    for res in result:
        json_data = getattr(res, 'json', None)
        if json_data and isinstance(json_data, dict):
            data_dict = json_data.get('res')
            if data_dict and 'rec_texts' in data_dict:
                texts = data_dict['rec_texts']
                scores = list(data_dict['rec_scores']) if 'rec_scores' in data_dict else []
                
                for i, text in enumerate(texts):
                    text_clean = str(text).strip()
                    if text_clean:
                        score = scores[i] if i < len(scores) else 1.0
                        print(f"识别内容: {text_clean}  (置信度: {float(score):.2f})")

if name == "main": test_image = "test/8.10_10.jpg" if os.path.exists(test_image): start_ocr(test_image)

内容来源: PaddlePaddle/PaddleOCR