1

I'm using OpenCV on Android with Eclipse for the first time. I used the following line to read an image and the next one to get its size:

Mat m = Highgui.imread("C:/Users/IMG_5940.jpg"); Size size = m.size();

and Size returns 0x0. I therefore can't convert the image to a bitmap and I receive the error: width and height must be > 0.

Any ideas about what I'm doing wrong ?

user3855955
  • 87
  • 10
  • Are you sure the image path is spelled correctly? Do you have a second image for which the read works? Are you on a Windows machine? If, have a look at [link](http://stackoverflow.com/questions/7417637/imread-not-working-in-opencv) – LSA Jun 15 '15 at 16:39

1 Answers1

0

Usually when imread returns an image of zero by zero pixels, the image could not be read. You have two options:

First, you can have IMG_5940.jpg as a Resource in your Android project, and import it with the OpenCV Utils.loadResource function with something like:

Mat img = Utils.loadResource(context, referenceID, Highgui.CV_LOAD_IMAGE_COLOR);

Second, if you know the location of the image on your Android filesystem, e.g, you're getting it from a camera or you've asked the user to provide a valid image, then you can use the imread function with that File object like so:

Mat img = Highgui.imread(file.getAbsolutePath());
Mark Miller
  • 706
  • 4
  • 14