Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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) but if i want to convert the result of the template matching function i get a FATAL EXCEPTION when i cll the Utils.matToBitmap function. here 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? is it something else?

click to hide/show revision 2
No.2 Revision

templateMatching mattoBitmap opencv for android

i I am trying to create a template matching function on android using opencv OpenCV with java Java (not with native). my problem is displaying the image. the class mattoBitmap matToBitmap works (in java) but if i want to convert the result of the template matching function i get a FATAL EXCEPTION when i cll the Utils.matToBitmap call the Utils.matToBitmap function. here 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 mResult to my knowledge is not important when it is created becuase because it is set afterwards by the template match function.

do i need to convert the mResult mat 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? is it something else?

click to hide/show revision 3
No.3 Revision

Conversion of templateMatching mattoBitmap opencv for androidresult to Android Bitmap

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. here 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 because 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? is it something else?