内置函数在opencv2 python中可用以查找图像之间的距离 [英] Built in functions available in opencv2 python to find distance between to images

查看:73
本文介绍了内置函数在opencv2 python中可用以查找图像之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个更快的归一化互相关,通过它我可以计算两个图像之间的相似度.我想知道除 scipy.signal.correlate2d()和matplotlib xcorr()之外,是否有任何内置函数可以找到两个图像之间的相关性.如果这两个函数都在工作,谁能告诉我一个例子来找到两个图像之间的相关性.

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)

推荐答案

OpenCV 使用函数 matchTemplate,例如,CV_TM_CCORR_NORMED.

OpenCV does normalized cross-correlations using the function matchTemplate, with, eg, CV_TM_CCORR_NORMED.

@Jonas建议使用以下代码来使用它并比较不同的方法

@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])

这篇关于内置函数在opencv2 python中可用以查找图像之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆