The matching methods for matchTemplate() in opencv “ cv2.TM_CCORR_NORMED” and “cv.CV_COMP_BHATTACHARYYA” give the same measure

StackOverflow https://stackoverflow.com//questions/24035535

Question

Hi i would like to bring to your notice there is some issue in the openCV matchTemplate() methods. According to book bhattacharya coefficient is totally different from Normalized cross correalation , but when i tried this chunk of code , i got the same distance everywhere for each image.Can anyone bring this notice to opencv developers and try to tell why this happened. I was trying to find the distance measure using these two methods

path1 = 'D:/cat1.png'
path2 = 'D:/cat2.png'
im1=cv2.imread(path1, cv2.CV_LOAD_IMAGE_GRAYSCALE)
im2=cv2.imread(path2, cv2.CV_LOAD_IMAGE_GRAYSCALE)
result = cv2.matchTemplate(im1,im2,cv.CV_COMP_BHATTACHARYYA) #Bhattacharya Coefficient
result2=cv2.matchTemplate(im1,im2,cv2.TM_CCORR_NORMED)       #Normalized Cross Correlation

print"BCC :",result
print '\n'
print"NCC :",result2
Was it helpful?

Solution

no wonder.

apart from CV_COMP_BHATTACHARYYA not being a valid compare flag for matchTemplate ,

both CV_COMP_BHATTACHARYYA and TM_CCORR_NORMED resolve to the same enum value 3 under the hood.

so basically you're doing the very same thing twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top