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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With