我目前正在尝试为扫雷机器人创建一个计算机视觉。然而,使用scipy.signal.correlate2d只会产生噪声。下面是我的测试代码,为什么输出只是噪声,而不是我期望的热图?
from scipy import signal
import numpy as np
from cv2 import cv2
from PIL import Image
image = cv2.imread('MinesweeperTest.png',0)
template = cv2.imread('Mine2.png',0)
corr = signal.correlate2d(image,template,mode="same")
Image.fromarray(corr).save("correlation.png")所有涉及到的图片都可以在这里找到:
MinesweeperTest.png:https://imgur.com/PpLLOW7
Min2.png:https://imgur.com/ApIIs1Z
Correlation.png:https://imgur.com/hkskY00
发布于 2019-12-06 05:55:21
在调用correlate2d之前对图像进行预处理,使其平均值为0,这将有助于获得更有意义的2D互相关:
image = image - image.mean()
template = template - template.mean()一个可重现的例子是:
from imageio import imread
from matplotlib import pyplot as plt
from scipy import signal
import numpy as np
image = imread('https://i.imgur.com/PpLLOW7.png', pilmode='L')
template = imread('https://i.imgur.com/ApIIs1Z.png', pilmode='L')
# fixed these
image = image - image.mean()
template = template - template.mean()
corr = signal.correlate2d(image, template, mode="same")
plt.imshow(corr, cmap='hot')https://stackoverflow.com/questions/59203554
复制相似问题