Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use histogram comparision http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

You can use histogram comparision http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

here is the code in python:

import cv

def compute_histogram(src, h_bins = 30, s_bins = 32):
    #create images
    hsv = cv.CreateImage(cv.GetSize(src), 8, 3)
    hplane = cv.CreateImage(cv.GetSize(src), 8, 1)
    splane = cv.CreateImage(cv.GetSize(src), 8, 1)
    vplane = cv.CreateImage(cv.GetSize(src), 8, 1)

    planes = [hplane, splane]
    cv.CvtColor(src, hsv, cv.CV_BGR2HSV)
    cv.Split(hsv, hplane, splane, vplane, None)

    #compute histogram  (why not use v_plane?)
    hist = cv.CreateHist((h_bins, s_bins), cv.CV_HIST_ARRAY,
            ranges = ((0, 180),(0, 255)), uniform = True)
    cv.CalcHist(planes, hist)      #compute histogram
    cv.NormalizeHist(hist, 1.0)    #normalize hist

    return hist

src1 = cv.LoadImage("C:/ICP/buterfly_0.jpg", cv.CV_LOAD_IMAGE_COLOR)
src2 = cv.LoadImage("C:/ICP/buterfly_1.jpg", cv.CV_LOAD_IMAGE_COLOR)
hist1= compute_histogram(src1)
hist2= compute_histogram(src2)
sc= cv.CompareHist(hist1, hist2, cv.CV_COMP_BHATTACHARYYA)
print sc