Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built in functions available in opencv2 python to find distance between to images

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)
like image 847
Jonas Avatar asked Oct 23 '25 17:10

Jonas


1 Answers

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])
like image 128
tom10 Avatar answered Oct 25 '25 06:10

tom10