Ask Your Question
0

Image is empty

asked 2013-03-21 10:45:39 -0600

Sylvain gravatar image

Hi,

i'm totally new with OpenCV and i'm starting with the Java version.

I'm trying some basics. The first part in the java tutorial was a success. I'm trying the Lena's Face detection. But i've a problem when I'm loading the file :

Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
System.out.println(image.toString());

Console return :

Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0x1ffed20, dataAddr=0x0 ]

I'm sure the path to the picture is good, if i change it i've a segmentation fault.

If someone have a idea...

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-03-21 16:27:23 -0600

Like @berak said, the command you use for the path is expecting the lena picture to be added to the resources of your java project. If you don't do that, the code has no idea where to actually get the image data. Relative paths are the way to go as basics! Configuring your project resources is a step further.

This guide could help you out : http://sandeepverma.wordpress.com/2009/11/27/accessing-a-resource-in-java/

edit flag offensive delete link more

Comments

Thank's a lot, it was a problem with my path. Thanks also for this nice guide, it was usefull :)

Sylvain gravatar imageSylvain ( 2013-03-22 04:36:40 -0600 )edit
5

answered 2013-03-21 12:02:24 -0600

berak gravatar image

updated 2013-03-21 12:04:04 -0600

"I'm sure the path to the picture is good"

let me bet against that ;)

getClass().getResource("lena.png").getPath()

just try to replace that monster with an absolute path for starters, like:

"/home/me/lena.png", or "c:/me/ma/miao/lena.png" // note : "/", not "\"

(an empty image is quite typical for imread not finding it)

edit flag offensive delete link more

Comments

Thank you very much, you were right, it was only a path problem. Thank's again ! Happy geek is happy !

Sylvain gravatar imageSylvain ( 2013-03-22 04:35:57 -0600 )edit

nice ;)

easy catch, btw, since there were others before you with the same prob

berak gravatar imageberak ( 2013-03-22 05:50:09 -0600 )edit

Question Tools

Stats

Asked: 2013-03-21 10:45:39 -0600

Seen: 5,105 times

Last updated: Mar 21 '13