sample code for comparing histograms in OpenCV 3.2
import cv2
path='location_of_images'
im1 = cv2.imread(path+'/'+'first.jpg',0)
hist1 = cv2.calcHist([im1],[0],None,[256],[0,256])
im2 = cv2.imread(path+'/'+'second.jpg',0)
hist2 = cv2.calcHist([im2],[0],None,[256],[0,256])
a=cv2.compareHist(hist1,hist2,cv2.HISTCMP_BHATTACHARYYA)
print a
the return value shows how close one is to your test image. Example: the method cv2.HISTCMP_BHATTACHARYYAgives zero (0.0) for the same image. other methods:cv2.HISTCMP_CHISQR,cv2.HISTCMP_CHISQR_ALT,cv2.HISTCMP_CORREL cv2.HISTCMP_HELLINGER,cv2.HISTCMP_INTERSECT,cv2.HISTCMP_KL_DIV.
source
share