I am using OpenCV library to see how two object in a two picture are similar. I read on many blogs in OpenCV histogram comparisons make this. Below is my code to do so.
I want to know minimum threshold value of this double text = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_BHATTACHARYYA);
I should consider that objects inside the two picture are similar and anything I am doing wrong , please share.
public Mat histogram(String filenameIn, String filenameOut) {
Mat img = Highgui.imread(filenameIn);
Mat src = new Mat(img.height(), img.width(), CvType.CV_8UC2);
Imgproc.cvtColor(img, src, Imgproc.COLOR_RGB2GRAY);
Vector<Mat> bgr_planes = new Vector<Mat>();
Core.split(src, bgr_planes);
MatOfInt histSize = new MatOfInt(256);
final MatOfFloat histRange = new MatOfFloat(0f, 256f);
boolean accumulate = false;
Mat b_hist = new Mat();
Imgproc.calcHist(bgr_planes, new MatOfInt(0), new Mat(), b_hist, histSize, histRange, accumulate);
Highgui.imwrite(filenameOut, b_hist);
return b_hist;
}
String mCapturedPicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
Mat H1 = histogram(mCapturedPicPath + "/Camera/1.jpg", mCapturedPicPath + "/Camera/5.jpg");
Mat H2 = histogram(mCapturedPicPath + "/Camera/2.jpg", mCapturedPicPath + "/Camera/6.jpg");
double text = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_BHATTACHARYYA);