Skip to content

python opencv preprocess

qiannian edited this page Jun 13, 2026 · 1 revision

Python OpenCV 预处理示例

对图片文件执行 OpenCV 预处理流水线。

Code

from pathlib import Path
from win32com.client import Dispatch

# 创建 op COM 对象
op = Dispatch("op.opsoft")

# 示例图片路径,请提前准备 source.png
base_dir = Path(__file__).resolve().parent
src = base_dir / "assets" / "source.png"
dst = base_dir / "assets" / "source_pipeline.png"

# 灰度化 -> OTSU 二值化 -> 开运算去噪
pipeline = "gray|threshold:otsu,0,255|morph:open,3,1"
ret = op.CvPreprocessPipeline(str(src), str(dst), pipeline)

print("预处理结果:", ret)
print("输出文件:", dst)

Clone this wiki locally