我想计算两幅图像之间的差异。我只对图像的某一部分的差值感兴趣。为此,我将所需的部分图像复制到临时图像,并对这些图像进行操作。但是使用http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html上指定的像素分配。这是给你的
ball = img[280:340, 330:390]
img[273:333, 100:160] = ball
使用类似的逻辑,我写了一个python程序
import cv2
import numpy as np
img_file = 'carparking2_1.jpg'
img = cv2.imread(img_file, cv2.IMREAD_COLOR)
img_withoutcar = 'carparking2_1.jpg'
img_withcar = 'carparking2.jpg'
img1 = img_withoutcar[47:151, 106:157]
img2 = img_withcar[47:151, 106:157]
diff1 = cv2.absdiff(img1, img2)
diff2 = cv2.absdiff(img1, img1)
print 'RGB shape: ', img.shape # Rows, cols, channels
print 'Difference with car and without: ', diff1
print 'Difference with car and with car: ', diff2
但是,我收到了输出消息:
^{pr2}$我在Windows10上运行带有OpenCV3.1.0的Python2.7。在
出现错误是因为您的命令试图将字符串“carparking2_1.jpg”切分为图像数据。
相关问题 更多 >
编程相关推荐