You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenCV C++与Python运算结果不一致,是Bug还是操作有误?

OpenCV C++与Python版本图像相减结果不一致问题

我正在执行一系列简单的OpenCV操作:

  • 读取包含待检测目标的图像
  • 应用中值滤波去除噪声
  • 读取另一张背景相同但无目标的图像(纯背景)
  • 将背景图像与去噪后的图像相减

但发现C++与Python版本的输出结果不同。

C++代码片段

Mat img = imread("test_noise.pgm", 0);

Mat noise_removed_image;
medianBlur(img, noise_removed_image, 5);

Mat background_only = imread("light.pgm", 0);

imshow("Background Removed Substract", background_only - noise_removed_image);

Python代码片段

mat = cv2.imread("test_noise.pgm", 0)
background = cv2.imread("light.pgm", 0)

noise_removed = cv2.medianBlur(mat, 5)
cv2.imshow("Background Removed", background - noise_removed)

输出结果对比

Python生成结果
C++生成结果

我原本预期两个版本应产生完全相同的输出。

内容的提问来源于stack exchange,提问作者Pawan Adhikari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 20:32:36