简体   繁体   English

接收错误:AttributeError:尝试调用openCV方法时,模块'cv2.cv2'没有属性'CompareHist'

[英]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. 在较新的版本中将其重命名。

Refer to this post for more information. 请参阅此帖子以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 模块 'cv2.cv2' 在 OpenCV 中没有属性 'freetype' - AttributeError: module 'cv2.cv2' has no attribute 'freetype' in OpenCV AttributeError: 模块 'cv2.cv2' 在 OpenCV 中没有属性 'faces' - AttributeError: module 'cv2.cv2' has no attribute 'faces' in OpenCV AttributeError:模块“cv2.cv2”没有属性“cv” - AttributeError: module 'cv2.cv2' has no attribute 'cv' AttributeError: 模块 'cv2.cv2' 没有属性 'DataFrame' - AttributeError: module 'cv2.cv2' has no attribute 'DataFrame' AttributeError:模块“ cv2.cv2”没有属性面 - AttributeError: module 'cv2.cv2' has no attribute face 属性错误模块 'cv2.cv2' 没有属性 'videocapture' - attributeerror module 'cv2.cv2' has no attribute 'videocapture' AttributeError: 模块 'cv2.cv2' 没有属性 'xfeatures2d' [Opencv 3.4.3] - AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' [Opencv 3.4.3] 模块“cv2.cv2”没有属性“cv” - module 'cv2.cv2' has no attribute 'cv' AttributeError:模块'cv2.cv2'没有属性'createFisherFaceRecognizer' - AttributeError: module 'cv2.cv2' has no attribute 'createFisherFaceRecognizer' AttributeError: 模块 'cv2.cv2' 没有属性 'samples' - AttributeError: module 'cv2.cv2' has no attribute 'samples'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM