Receiving error: AttributeError: module 'cv2.cv2' has no attribute 'CompareHist' when trying to call a openCV method

Receiving error: AttributeError: module 'cv2.cv2' has no attribute 'CompareHist' when trying to call a openCV method

我正在尝试使用 openCV 的 compareHist() 方法找出两个向量之间的距离。我正在使用 opencv-contrib-python 3.4.2.17。如果我尝试使用此处 https://docs.opencv.org/3.4.2/d6/dc7/group__imgproc__hist.html#gaf4190090efa5c47cb367cf97a9a519bd 文档中所述的 compareHist() 方法,我会收到错误消息 "AttributeError: module 'cv2.cv2' has no attribute 'CompareHist'"

是我调用方法不正确,还是我使用文档不正确?

我的测试代码片段如下,供参考。谢谢。

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

尝试使用 cv.HISTCMP_CORREL 而不是 CV_COMP_CORREL CompareHist method 喜欢 cv.CompareHist(des1[0], des2[0], CV_HISTCMP_CORREL)。它在较新的版本中被重命名。

有关详细信息,请参阅