Skip to content Skip to sidebar Skip to footer

Templatematching Mattobitmap Opencv For Android

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) b

Solution 1:

You need to convert bitmap to RGBA format and vice versa. Maybe you need to take a look here: https://groups.google.com/group/android-opencv/ and here: Java openCV - Error while conevrting Bitmap to Mat

Solution 2:

The problem is that the matchTemplate() result is a float point single channel Mat so I needed to normalize the mResult vector. the solution is:

void TemplateMatch(){

mFind=newMat(256, 192, CvType.CV_8UC4); 
Input = newMat(256, 192, CvType.CV_8UC4); 

MatmResult8u=newMat(256, 192, CvType.CV_8UC4); 

mResult = newMat(217, 153, CvType.CV_8UC4); 

Utils.bitmapToMat(bmp2, mFind);
Utils.bitmapToMat(bmp1, Input);


Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF) ;
bmp3= Bitmap.createBitmap(mResult.cols(),  mResult.rows(),Bitmap.Config.ARGB_8888);
Core.normalize(mResult, mResult8u, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);
Utils.matToBitmap(mResult8u, bmp3);
iv2.setImageBitmap(bmp3);

}

Post a Comment for "Templatematching Mattobitmap Opencv For Android"