Anyone here have tried implementing the chamerMatching method on android using opencv4android? I cant get it to work properly on my device galaxy tab 3 kitkat.
the application crashes as soon as I call the chamerMatching method.
here's the screenshot of the logcat from where the problem starts.
it seems like a memory problem.
I'm trying to create an application the will compute the similarity scores between two edge maps/matrices using the chamfer matching algorithm provided on the contrib folder of opencv 2.4.11.
heres my code.
public static float getScore(Mat img, Mat tpl)
{
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
if (img.empty() | tpl.empty())
{
System.out.println("Could not read image file.");
return 0;
}
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(tpl, tpl, Imgproc.COLOR_BGR2GRAY);
Mat cimg = new Mat(img.rows(), img.cols(), CvType.CV_8UC1);
Imgproc.cvtColor(img, cimg, Imgproc.COLOR_GRAY2BGR);
List<MatOfPoint> results = new Vector<>();
MatOfFloat costs = new MatOfFloat();
int best = Contrib.chamerMatching(img, tpl, results, costs);
if (best < 0) {
System.out.println("matching not found");
return 0;
}
System.out.println("Chamfer Distance = " + costs.toList().get(best));
for (int i =0; i < results.get(best).rows(); i++)
{
Core.circle(cimg, results.get(best).toArray()[i], 0, new Scalar(0,255,0));
}
int count_contour = Core.countNonZero(img);
Imgproc.cvtColor(cimg, cimg, Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(cimg, cimg, 150, 255, Imgproc.THRESH_BINARY);
int count_white = Core.countNonZero(cimg);
System.out.println("Contour = " + count_contour);
System.out.println("White = " + count_white);
float m = count_contour - count_white;
float d = m / count_contour;
float s = d * 100;
return s;
}