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)
输出结果对比


我原本预期两个版本应产生完全相同的输出。
内容的提问来源于stack exchange,提问作者Pawan Adhikari
相关产品推荐
相关产品推荐

