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

落花浮王杯 提交于 2020-12-06 19:17:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!