Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use compareHist function 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

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'

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

like image 642
Dappa jack Avatar asked Nov 06 '16 16:11

Dappa jack


People also ask

How do I compare two images in OpenCV?

Python - OpenCV & PyQT5 together To compare two images, we use the Mean Square Error (MSE) of the pixel values of the two images. Similar images will have less mean square error value. Using this method, we can compare two images having the same height, width and number of channels.


1 Answers

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

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
like image 149
ZdaR Avatar answered Oct 19 '22 17:10

ZdaR