Mat hsvRef = new Mat();
Mat hsvCard = new Mat();
Mat srcRef = new Mat(refImage.getHeight(), refImage.getWidth(), CvType.CV_8UC2);
Utils.bitmapToMat(refImage, srcRef);
Mat srcCard = new Mat(cardImage.getHeight(), cardImage.getWidth(), CvType.CV_8UC2);
Utils.bitmapToMat(cardImage, srcCard);
/// Convert to HSV
Imgproc.cvtColor(srcRef, hsvRef, Imgproc.COLOR_BGR2HSV);
Imgproc.cvtColor(srcCard, hsvCard, Imgproc.COLOR_BGR2HSV);
/// Using 50 bins for hue and 60 for saturation
int hBins = 50;
int sBins = 60;
MatOfInt histSize = new MatOfInt( hBins, sBins);
// hue varies from 0 to 179, saturation from 0 to 255
MatOfFloat ranges = new MatOfFloat( 0f,180f,0f,256f );
// we compute the histogram from the 0-th and 1-st channels
MatOfInt channels = new MatOfInt(0, 1);
Mat histRef = new Mat();
Mat histCard = new Mat();
ArrayList<Mat> histImages=new ArrayList<Mat>();
histImages.add(hsvRef);
Imgproc.calcHist(histImages,
channels,
new Mat(),
histRef,
histSize,
ranges,
false);
Core.normalize(histRef,
histRef,
0,
1,
Core.NORM_MINMAX,
-1,
new Mat());
histImages=new ArrayList<Mat>();
histImages.add(hsvCard);
Imgproc.calcHist(histImages,
channels,
new Mat(),
histCard,
histSize,
ranges,
false);
Core.normalize(histCard,
histCard,
0,
1,
Core.NORM_MINMAX,
-1,
new Mat());
double resp1 = Imgproc.compareHist(histRef, histCard, 0);
Log.d(TAG, "HIST COMPARE 0" + resp1);
double resp2 = Imgproc.compareHist(histRef, histCard, 1);
Log.d(TAG, "HIST COMPARE 1" + resp2);
double resp3 = Imgproc.compareHist(histRef, histCard, 2);
Log.d(TAG, "HIST COMPARE 2" + resp3);
double resp4 = Imgproc.compareHist(histRef, histCard, 3);
Log.d(TAG, "HIST COMPARE 3" + resp4);