OpenCV-Python学习<六> 绘图

本文介绍了如何使用OpenCV库在图像上绘制各种图形,包括直线、矩形、圆以及添加文字。通过实例代码展示了如何设置颜色、线条类型和粗细,以及实心和空心图形的区别。此外,还演示了如何绘制椭圆和多边形,并讲解了在图像上添加文字的方法,包括字体、大小、颜色和方向的设置。

OpenCV提供了方便的绘图功能,可以绘制直线,矩阵,圆,椭圆等多种几何图形,还能再指定位置添加文字说明。

1. 绘制直线:

img = v2.line(img, pt1, pt2, color [, thickness [, lineType]])

返回值, img: 绘制出的图像。

参数:

img: 在其上绘制直线的载体图像(绘图的容器载体,也成为画布,画板)

pt1,pt2: 线段的起点和终点。类型为tuple.

color:绘制直线的颜色。通常使用BGR模型表示。 例如:(0, 0, 255)表示红色。

thickness:线条的粗细。默认为1. 值越大越粗。

lineType: 线条类型。默认为8连接类型。

import cv2
import sys

img_src = cv2.imread("images/sample_1.webp")
if(img_src is None):
    print("Read file error.")
    sys.exit()
print("Image Shape:", img_src.shape)

width = img_src.shape[1]
height = img_src.shape[0]

img_des = cv2.line(img_src, (0, 0), (width, height), (0, 0, 255), 3, cv2.LINE_AA)

cv2.imshow("Orz", img_src)
cv2.imshow("After", img_des)
cv2.waitKey()
cv2.destroyAllWindows()

2. 绘制矩形:

img = cv2.rectangle(img, pt1, pt2, color[

venv) mac@macdeMacBook-Pro project % python -c "import paddle; print(paddle.__version__)" /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages/paddle/utils/cpp_extension/extension_utils.py:718: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md warnings.warn(warning_message) 3.2.2 (venv) mac@macdeMacBook-Pro project % pip uninstall paddleocr -y WARNING: Skipping paddleocr as it is not installed. (venv) mac@macdeMacBook-Pro project % pip install "paddleocr>=2.7.0.3" --no-cache-dir Collecting paddleocr>=2.7.0.3 Downloading paddleocr-3.3.2-py3-none-any.whl.metadata (55 kB) Requirement already satisfied: paddlex<3.4.0,>=3.3.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (3.3.12) Requirement already satisfied: PyYAML>=6 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddleocr>=2.7.0.3) (6.0.2) Requirement already satisfied: requests in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddleocr>=2.7.0.3) (2.32.5) Requirement already satisfied: typing-extensions>=4.12 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddleocr>=2.7.0.3) (4.15.0) Requirement already satisfied: aistudio-sdk>=0.3.5 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.3.8) Requirement already satisfied: chardet in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (5.2.0) Requirement already satisfied: colorlog in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (6.10.1) Requirement already satisfied: filelock in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (3.20.1) Requirement already satisfied: huggingface-hub in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.2.3) Requirement already satisfied: modelscope>=1.28.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.33.0) Requirement already satisfied: numpy>=1.24 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.2.6) Requirement already satisfied: packaging in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (25.0) Requirement already satisfied: pandas>=1.3 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.3.3) Requirement already satisfied: pillow in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (12.0.0) Requirement already satisfied: prettytable in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (3.17.0) Requirement already satisfied: py-cpuinfo in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (9.0.0) Requirement already satisfied: pydantic>=2 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.12.5) Requirement already satisfied: ruamel.yaml in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.18.17) Requirement already satisfied: ujson in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (5.11.0) Requirement already satisfied: imagesize in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.4.1) Requirement already satisfied: opencv-contrib-python==4.10.0.84 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (4.10.0.84) Requirement already satisfied: pyclipper in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.4.0) Requirement already satisfied: pypdfium2>=4 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (5.2.0) Requirement already satisfied: python-bidi in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.6.7) Requirement already satisfied: shapely in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.1.2) Requirement already satisfied: psutil in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (7.2.0) Requirement already satisfied: tqdm in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (4.67.1) Requirement already satisfied: bce-python-sdk in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.9.56) Requirement already satisfied: click in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (8.3.1) Requirement already satisfied: setuptools in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from modelscope>=1.28.0->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (80.9.0) Requirement already satisfied: urllib3>=1.26 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from modelscope>=1.28.0->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.6.2) Requirement already satisfied: python-dateutil>=2.8.2 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pandas>=1.3->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.9.0.post0) Requirement already satisfied: pytz>=2020.1 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pandas>=1.3->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2025.2) Requirement already satisfied: tzdata>=2022.7 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pandas>=1.3->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2025.3) Requirement already satisfied: annotated-types>=0.6.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pydantic>=2->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.7.0) Requirement already satisfied: pydantic-core==2.41.5 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pydantic>=2->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2.41.5) Requirement already satisfied: typing-inspection>=0.4.2 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from pydantic>=2->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.4.2) Requirement already satisfied: six>=1.5 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas>=1.3->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.17.0) Requirement already satisfied: charset_normalizer<4,>=2 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from requests->paddleocr>=2.7.0.3) (3.4.4) Requirement already satisfied: idna<4,>=2.5 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from requests->paddleocr>=2.7.0.3) (3.11) Requirement already satisfied: certifi>=2017.4.17 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from requests->paddleocr>=2.7.0.3) (2025.11.12) Requirement already satisfied: pycryptodome>=3.8.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from bce-python-sdk->aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (3.23.0) Requirement already satisfied: future>=0.6.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from bce-python-sdk->aistudio-sdk>=0.3.5->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.0.0) Requirement already satisfied: fsspec>=2023.5.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (2025.12.0) Requirement already satisfied: hf-xet<2.0.0,>=1.2.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.2.0) Requirement already satisfied: httpx<1,>=0.23.0 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.28.1) Requirement already satisfied: shellingham in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.5.4) Requirement already satisfied: typer-slim in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.21.0) Requirement already satisfied: anyio in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from httpx<1,>=0.23.0->huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (4.12.0) Requirement already satisfied: httpcore==1.* in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from httpx<1,>=0.23.0->huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.0.9) Requirement already satisfied: h11>=0.16 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.16.0) Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from anyio->httpx<1,>=0.23.0->huggingface-hub->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (1.3.1) Requirement already satisfied: wcwidth in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from prettytable->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.2.14) Requirement already satisfied: ruamel.yaml.clib>=0.2.15 in /Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages (from ruamel.yaml->paddlex<3.4.0,>=3.3.0->paddlex[ocr-core]<3.4.0,>=3.3.0->paddleocr>=2.7.0.3) (0.2.15) Downloading paddleocr-3.3.2-py3-none-any.whl (86 kB) Installing collected packages: paddleocr Successfully installed paddleocr-3.3.2 (venv) mac@macdeMacBook-Pro project % python -c "import paddleocr; print(paddleocr.__version__)" Checking connectivity to the model hosters, this may take a while. To bypass this check, set `DISABLE_MODEL_SOURCE_CHECK` to `True`. 3.3.2 (venv) mac@macdeMacBook-Pro project % python ocr_test.py Checking connectivity to the model hosters, this may take a while. To bypass this check, set `DISABLE_MODEL_SOURCE_CHECK` to `True`. Traceback (most recent call last): File "/Users/mac/Projects/GaPinyc/PaddleOCR/Test/project/ocr_test.py", line 12, in <module> ocr = PaddleOCR( File "/Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages/paddleocr/_pipelines/ocr.py", line 163, in __init__ super().__init__(**base_params) File "/Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages/paddleocr/_pipelines/base.py", line 63, in __init__ self._common_args = parse_common_args( File "/Users/mac/Projects/GaPinyc/PaddleOCR/Test/venv/lib/python3.10/site-packages/paddleocr/_common_args.py", line 45, in parse_common_args raise ValueError(f"Unknown argument: {name}") ValueError: Unknown argument: layout_analysis (venv) mac@macdeMacBook-Pro project %
最新发布
12-28
你已经成功安装了 **`paddleocr==3.3.2`**(最新版),但遇到了这个错误: ``` ValueError: Unknown argument: layout_analysis ``` 这说明:**你在使用旧的参数名,而新版本 API 已经彻底重构!** --- ## ✅ 核心结论 > 🚨 `paddleocr>=3.0` 是一个**完全重写的版本**,基于 `PaddleX` 和 `ModelScope` 架构,**不再支持任何旧版参数**,包括: > > - ❌ `use_angle_cls` > - ❌ `layout_analysis` > - ❌ `det`, `rec` > - ❌ `lang='ch'` 你现在需要 **改用全新的初始化方式和调用逻辑**。 --- ## ✅ 解决方案:适配 `paddleocr>=3.3.2` 的正确写法 ### 🔧 第一步:设置环境变量跳过网络检查(必须) ```bash export DISABLE_MODEL_SOURCE_CHECK=True ``` 或在代码最开头添加: ```python import os os.environ['DISABLE_MODEL_SOURCE_CHECK'] = 'True' ``` --- ### ✅ 第二步:使用 `paddleocr` v3.3.2 的标准用法(官方推荐模式) ```python # ocr_test.py import os os.environ['DISABLE_MODEL_SOURCE_CHECK'] = 'True' from paddleocr import PaddleOCR import cv2 import numpy as np from PIL import Image, ImageDraw, ImageFont import matplotlib.pyplot as plt # 初始化 OCR 引擎(⚠️ 不要传 layout_analysis 等非法参数) ocr = PaddleOCR( ocr_type="structure_v3", # 启用文本检测+识别+方向分类 lang="zh-cn", # 注意:不是 'ch',而是 'zh-cn' use_gpu=False, # Mac 用户设为 False show_log=False # 减少日志输出 ) # 图片路径 img_path = 'test_images/demo.jpg' # 读取图像 image = cv2.imread(img_path) if image is None: raise FileNotFoundError(f"无法读取图片: {img_path}") # 执行 OCR print("正在识别...") results = ocr.ocr(img_path) # 提取结果 boxes = [] texts = [] # 注意:results 结构为 [ [{box}, (text, score)], ... ] for res in results[0]: # results 是嵌套列表 box = res[0] text = res[1][0] score = res[1][1] print(f"[{score:.3f}] {text}") boxes.append(box) texts.append(text) # 自定义绘图函数(支持中文) def draw_ocr_result(image, boxes, texts, font_size=18): rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) pil_image = Image.fromarray(rgb_image) draw = ImageDraw.Draw(pil_image) try: font = ImageFont.truetype("Arial Unicode.ttf", font_size) # macOS 内置 except: try: font = ImageFont.truetype("Helvetica", font_size) except: font = ImageFont.load_default() for box, text in zip(boxes, texts): pts = np.array(box, dtype=np.int32).reshape((-1, 1, 2)) cv2.polylines(image, [pts], True, (0, 255, 0), 2) draw.text((box[0][0], box[0][1] - 20), text, font=font, fill=(255, 0, 0)) return cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR) # 绘图并保存 result_img = draw_ocr_result(image, boxes, texts) cv2.imwrite("output_result.jpg", result_img) print("✅ 结果已保存为 output_result.jpg") # 显示图像 plt.figure(figsize=(10, 6)) plt.imshow(cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)) plt.axis("off") plt.title("PaddleOCR 识别结果") plt.show() ``` --- ## ✅ 关键变化说明(v3.3.2 vs 老版本) | 功能 | 老版本(≤2.6.1) | 新版本(≥3.0) | |------|------------------|---------------| | 安装命令 | `pip install paddleocr==2.6.1` | `pip install paddleocr>=3.0` | | 初始化类 | `PaddleOCR(lang='ch')` | `PaddleOCR(lang='zh-cn')` | | 方向识别 | `use_angle_cls=True` | ✅ 默认集成在 `structure_v3` 中 | | 检测+识别控制 | `det=True, rec=True` | 使用 `ocr_type="structure_v3"` | | 参数 `layout_analysis` | 支持 | ❌ 已移除(由单独 pipeline 控制) | | 返回结构 | `result[0][i][0]`: box, `[1][0]`: text | 相同 | | 是否需要 `draw_ocr` | 可用 | ❌ 已弃用,需手动绘制 | --- ## ✅ 测试图片准备(如果还没有) ```bash mkdir -p test_images curl -o test_images/demo.jpg https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg ``` --- ## ✅ 运行脚本 ```bash python ocr_test.py ``` 📌 首次运行会从 ModelScope 下载模型(约 20~40MB),后续秒开。 你应该看到: - 输出识别文本 - 弹出窗口显示带标注的图片 - 生成 `output_result.jpg` 🎯 成功! --- ## ✅ 验证版本号 ```bash python -c "import paddleocr; print(paddleocr.__version__)" ``` 输出应为: ``` 3.3.2 ``` ✅ 正确版本。 --- ## ✅ 总结:你现在应该记住的重点 | 项目 | 推荐值 | |------|--------| | `paddleocr` 版本 | ≥ 3.3.2 (当前最新稳定) | | 初始化参数 | `ocr_type="structure_v3"`, `lang="zh-cn"` | | **不要传** | `layout_analysis`, `use_angle_cls`, `det`, `rec` | | 设置环境变量 | `DISABLE_MODEL_SOURCE_CHECK=True` | | 中文支持 | ✅ 内建,无需额外配置 | | GPU 支持 | `use_gpu=False`(Mac 不支持 CUDA) | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值