0

I have a picture that I had located in the drwable directroy. I need to use it as a mat file.

I found in the site that I should do this

bitmap batt= bitmapFactory.decodeFile("path");

Utils.bitmapToMat(batt,mBatt);

but it does not seem to work,

am I doing somthing wrong?

boaz
  • 920
  • 1
  • 13
  • 32

2 Answers2

0

I googled "opencv bitmap to mat", the first three links all address your problem and provide possible solutions...

Seems like the problem is an unstable bitmapToMat()-function.

For the solution(s), take a look the pages Google gave me:

  1. Java openCV - Error while conevrting Bitmap to Mat
  2. Correct way to convert between Bitmap and Mat in OpenCV on Android?
  3. A Simple Question - How do I convert between Bitmap and Mat?

The first two here are actually on stackoverflow, didn't they show as similar questions when you typed your question?

Good luck!

Community
  • 1
  • 1
Sander
  • 3,942
  • 2
  • 17
  • 22
0

The code you posted should work. What you are probably missing is to initialize the mBatt object.

First, declaring the batt object should be Bitmap with capital B (maybe this was just a type in your question code):

Bitmap batt = bitmapFactory.decodeFile("path");

Then you should do something like this, to initialize mBatt object, before bitmapToMat:

// battHeight and battWidth should have the height and width of your bitmap...
Mat mBatt = new Mat(battHeight, battWidth, CvType.CV_8UC1); 
Rui Marques
  • 8,567
  • 3
  • 60
  • 91