问题
I want a faster Normalized cross correlation using which i can compute similarity between two images. I want to know whether there is any built in functions which can find correlation between two images other than scipy.signal.correlate2d() and matplotlib xcorr(). If these two functions are working can anyone show me an example to find correlation between two images.
path1='D:/image/cat1.jpg'
path2='D:/image/cat2.jpg'
corrCoefft = computeCorrelationCoefft(path1,path2)
回答1:
OpenCV does normalized cross-correlations using the function matchTemplate, with, eg, CV_TM_CCORR_NORMED
.
@Jonas suggested the following code to use this and compare the different methods
img = cv2.imread(path1)
template = cv2.imread(path2)
methods = ['cv2.TM_CCOEFF', 'cv2.TM_CCOEFF_NORMED', 'cv2.TM_CCORR','cv2.TM_CCORR_NORMED', 'cv2.TM_SQDIFF', 'cv2.TM_SQDIFF_NORMED']
for i in range(len(methods)):
result[i] = cv2.matchTemplate(img,template,methods[i])
print ("Method {} : Result{}") .format(method[i],result[i])
来源:https://stackoverflow.com/questions/23927361/built-in-functions-available-in-opencv2-python-to-find-distance-between-to-image