我正在尝试使用模板图像计算图像的相关性。 (例如ref链接:https://www.mathworks.com/examples/image/mw/images-ex92197313-perform-fft-based-correlation-to-locate-image-features之类的东西)在代码段的下方。
img = cv2.imread ("/home/engineer/Desktop/Ai/tracking/KCFpy_learning/demoimags/text.png", 0) #grayscale image read
a = img[32:45,88:98]
a_rot = np.rot90(a, 2)
def pad_with(vector, pad_width, iaxis, kwargs):
pad_value = kwargs.get('padder', 0)
# print("val : ", pad_value, ", width : ", pad_width)
vector[:pad_width[0]] = pad_value
vector[-pad_width[1]:] = pad_value
return vector
reshape_a = np.pad(a_rot, 123, pad_with)
reshape_a = cv2.resize(reshape_a, (img.shape), interpolation = cv2.INTER_CUBIC)
print("shape : ", img.shape, " , resh : ", reshape_a.shape)
dft_img = cv2.dft(np.float32(img), flags = cv2.DFT_COMPLEX_OUTPUT)
dft_templ_img = cv2.dft(np.float32(reshape_a), flags = cv2.DFT_COMPLEX_OUTPUT)
conv_res = cv2.mulSpectrums(dft_img, dft_templ_img, 0, conjB=False)
img_back = cv2.idft(conv_res)
real = img_back[:,:,0]
r = np.max(real)
print("max val : ", r)
cv2.imshow("real_part", real)
从真实的最大值非常。我如何验证我的输出?还是有其他方法可以在频域中识别图像和模板之间最可能的相关性。
谢谢, Vivek T