[英]Receiving error: AttributeError: module 'cv2.cv2' has no attribute 'CompareHist' when trying to call a openCV method
I'm trying to find the distance between two vectors using openCV's compareHist() method. 我正在尝试使用openCV的compareHist()方法查找两个向量之间的距离。 I'm using opencv-contrib-python 3.4.2.17.
我正在使用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'"
如果我尝试使用文档中所述的compareHist()方法,请参见此处https://docs.opencv.org/3.4.2/d6/dc7/group__imgproc__hist.html#gaf4190090efa5c47cb367cf97a9a519bd,我会收到一条错误消息“ AttributeError:模块'cv2。 cv2'没有属性'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))
Try using cv.HISTCMP_CORREL
instead of CV_COMP_CORREL
in the CompareHist method
like cv.CompareHist(des1[0], des2[0], CV_HISTCMP_CORREL)
. 尝试在
CompareHist method
使用cv.HISTCMP_CORREL
代替CV_COMP_CORREL
,例如cv.CompareHist(des1[0], des2[0], CV_HISTCMP_CORREL)
。 It was renamed in the newer versions. 在较新的版本中将其重命名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.