OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 19 Aug 2015 18:34:15 -0500compareHist with HISTCMP_CORRELhttp://answers.opencv.org/question/68990/comparehist-with-histcmp_correl/ I'm evaluating compareHist() and when I compare a 'flat' histogram with a single spike, the correlation value is 1.0! This is obviously wrong (by hand I get zero divided by zero but it should be approaching zero).
Am I doing something wrong? Here's my code:
import numpy, cv2
spike = numpy.ones((1,256), dtype=numpy.uint8).reshape(16, 16) * 127
flat = numpy.arange(256, dtype=numpy.uint8).reshape(16,16)
# Calculate the histograms
hist_s = cv2.calcHist([spike], [0], None, [256], [0, 256])
hist_f = cv2.calcHist([flat], [0], None, [256], [0, 256])
print cv2.compareHist(hist_f, hist_s, method=0)
returns 1.0
Plot of the two histograms (spike=red, flat=blue):
![image description](/upfiles/14400271862802213.png)Wed, 19 Aug 2015 18:34:15 -0500http://answers.opencv.org/question/68990/comparehist-with-histcmp_correl/