0

I'm trying to find the distance between two vectors using openCV's compareHist() method. I'm using opencv-contrib-python 3.4.2.17. If I try to use the compareHist() method as described in the documentation here https://docs.opencv.org/3.4.2/d6/dc7/group__imgproc__hist.html#gaf4190090efa5c47cb367cf97a9a519bd I get an error "AttributeError: module 'cv2.cv2' has no attribute 'CompareHist'"

Am I calling the method incorrectly, or am I using the documentation incorrectly?

My snippet of testing code is below for reference. Thanks.

import numpy as np
import cv2 as cv

img = cv.imread('../data/im3.jpg')
img2 = cv.imread('../data/im4.jpg')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray2 = cv.cvtColor(img2, cv.COLOR_BGR2GRAY)

sift = cv.xfeatures2d.SIFT_create()
kp, des1 = sift.detectAndCompute(gray,None)
kp2, des2 = sift.detectAndCompute(gray2,None)


print(cv.CompareHist(des1[0], des2[0], CV_COMP_CORREL))
user406955
  • 79
  • 9

1 Answers1

0

Try using cv.HISTCMP_CORREL instead of CV_COMP_CORREL in the CompareHist method like cv.CompareHist(des1[0], des2[0], CV_HISTCMP_CORREL). It was renamed in the newer versions.

Refer to this post for more information.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Vardan Agarwal
  • 2,023
  • 2
  • 15
  • 27
  • Alright, but then using `cv.HISTCMP_CORREL(des1[0], des2[0])` shouldn't this return a double? If I try to print the output of this function I'm getting a "int object is not callable" Type Error. Looking at https://docs.opencv.org/3.0-beta/modules/imgproc/doc/histograms.html – user406955 Feb 10 '19 at 19:22
  • I'm an idiot, the problem wasn't the method call, but the difference between `cv.CompareHist()` and `cv.compareHist()` Thanks – user406955 Feb 10 '19 at 19:26
  • @user406955 You got me wrong. I meant using cv.CompareHist(des1[0], des2[0], CV_HISTCMP_CORREL) in place of cv.CompareHist(des1[0], des2[0], CV_COMP_CORREL) as mentioned in the other post. – Vardan Agarwal Feb 10 '19 at 19:26
  • No problem, I have edited my answer to make it clearer. – Vardan Agarwal Feb 10 '19 at 19:29