如何使用compareHist函数opencv [英] how to use compareHist function opencv

查看:455
本文介绍了如何使用compareHist函数opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

img = cv2.imread('mandrill.png')
histg = cv2.calcHist([img],[0],None,[256],[0,256])

if len (sys.argv) < 2:
    print >>sys.stderr, "Usage:", sys.argv[0], "<image>..."
    sys.exit (1)

for fn in sys.argv[1:]:
    im = cv2.imread (fn)

histr = cv2.calcHist([im],[0],None,[256],[0,256])
a = cv2.compareHist(histr,histg,cv2.cv.CV_COMP_CORREL)
print a

我正在尝试使用上面的代码来比较直方图histrhistg之间的相关性,当我运行该代码时,我得到了错误

I am trying to use the code above to compare the correlation between histograms histr and histg when I run the code the I get the error

'module' object has no attribute 'cv'

似乎CV3各种相关函数的名称已更改.各种相关函数的名称是什么?

It seems that CV3 the names of the various correlation functions have changed. What are the names of the various correlation functions?

推荐答案

您使用的opencv版本已将cv2.cv.CV_COMP_CORREL重命名为cv2.HISTCMP_CORREL

The opencv version you are using has cv2.cv.CV_COMP_CORREL renamed to cv2.HISTCMP_CORREL

函数名称更改如下(左侧显示opencv2的名称,右侧显示最新版本的opencv(opencv3)的名称):

The function name changes are as follows (left hand side shows the names for opencv2, right hand side shows the name for the latest version of opencv(opencv3)):

cv2.cv.CV_COMP_CORREL:: cv2.HISTCMP_CORREL
cv2.cv.CV_COMP_CHISQR :: cv2.HISTCMP_CHISQR/ cv2.HISTCMP_CHISQR_ALT
cv2.cv.CV_COMP_INTERSECT :: cv2.HISTCMP_INTERSECT
cv2.cv.CV_COMP_BHATTACHARYYA :: cv2.HISTCMP_BHATTACHARYYA

这篇关于如何使用compareHist函数opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆