I am trying to create a template matching function on Android using OpenCV with Java (not with native).
My problem is displaying the image. The class mattoBitmap works (in Java) but if I want to convert the result of the template matching function I get a FATAL EXCEPTION
when I call the Utils.matToBitmap
function.
Below is the relevant code:
void TemplateMatch() {
mFind = new Mat(256, 192, CvType.CV_8UC4);
Input = new Mat(256, 192, CvType.CV_8UC4);
mResult = new Mat(217, 153, CvType.CV_8UC4); // (bmp2 size is 40)
Utils.bitmapToMat(bmp2, mFind);
Utils.bitmapToMat(bmp1, Input);
Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF);
bmp3 = Bitmap.createBitmap(mResult.cols(), mResult.rows(), conf);
Utils.matToBitmap(mResult, bmp3);
iv2.setImageBitmap(bmp3);
}
The size of mResult to my knowledge is not important when it is created becuase it is set afterwards by the template match function.
Do I need to convert the mResult mat to something before I convert it to bmp?
Do I need to convert the bmp to something before I can convert the mat to it?