Q:

Template Matching for android-opencv application

I have developed an algorithm for android using OpenCV. I need to find overlap between the previous image and current frame. So, I have produced the template from previous image to match with current frame to make a photograph. It is the procedure to complete photographing. (Taking more than 10 picture)
Here is the code that I have developed to find the overlap.
public void overlapFinder(Mat inputFrame , Mat inputTemplate )

{

Mat mResult; 

  int resultWidth =  inputFrame.width() - inputTemplate.width() + 1; 

  int resultHeight = inputFrame.height() - inputTemplate.height() + 1;

  mResult = new Mat(resultHeight, resultWidth, CvType.CV_8U); 

  Imgproc.matchTemplate(inputFrame, inputTemplate, mResult,Imgproc.TM_CCORR_NORMED) ; 
  Core.MinMaxLocResult result = Core.minMaxLoc(mResult);

  @SuppressWarnings("unused")

  double maxVal = result.maxVal;

}

The problem is that when the "overlap function" is called after generating template from previous image, the application is crashed.
Would anyone please help me with that?
Thanks

A:

Maybe you really need to do some debugging first, but in any case, I can see from your code that it would be worthwhile checking the sizes of your images - it seems that your code assumes the template is always smaller than the input frame. 
If that's not true, you will get negative resultWidth and/or resultHeight, which will make it crash.
One other thing - the documentation suggests that the result type should be CV_32FC1.
PS - Try initialising your result like this:
mResult.create(resultHeight, resultWidth, CvType.CV_32FC1); 

