Ask Your Question
1

libpng warning: Image width is zero in IHDR

asked 2013-02-23 10:14:07 -0600

goodspeed gravatar image

Hi, when i run my first OpenCV application in Java i receive that message from compiler:

Running DetectFaceDemo
Detected 0 faces
Writing faceDetection.png
*libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data*

i try the example from: http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html

edit retag flag offensive close merge delete

5 answers

Sort by ยป oldest newest most voted
2

answered 2013-02-23 12:18:50 -0600

berak gravatar image

since it says:

Detected 0 faces

and

Image width is zero

i'm sure, that it could not load the lena image before.

(it's just reusing that, draw a face rect into it, and save it again.)

maybe you replace the whole

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

part with the absolute filename, like "/home/me/lena.png" or "c:/me/folder/lena.png"

if that works, rinse and repeat for the lbpcascade_frontalface.xml

edit flag offensive delete link more

Comments

it don't work =( i'm try CascadeClassifier faceDetector = new CascadeClassifier("D:\Study\work\HelloCV2\src\lbpcascade_frontalface.xml"); Mat image = Highgui.imread("D:\Study\work\HelloCV2\src\lena.png");

Running DetectFaceDemo Detected 0 faces Writing faceDetection.png libpng warning: Image width is zero in IHDR libpng warning: Image height is zero in IHDR libpng error: Invalid IHDR data

goodspeed gravatar imagegoodspeed ( 2013-02-23 17:30:20 -0600 )edit

oh, that should be either: "D:/Study/work/HelloCV2/src/lena.png" or "D:\Study\work\HelloCV2\src\lena.png" , backslashes in strings, avoid them, or take 2

berak gravatar imageberak ( 2013-02-24 04:12:15 -0600 )edit

Thanks! It works with D:/Study/work/HelloCV2/src/lena.png ! Wow! =D

goodspeed gravatar imagegoodspeed ( 2013-02-24 05:27:58 -0600 )edit

oh, nice :) now same idea for the cascade path!

berak gravatar imageberak ( 2013-02-24 05:29:52 -0600 )edit
4

answered 2013-08-17 09:12:09 -0600

DM1 gravatar image

updated 2013-08-17 09:40:52 -0600

For some reason, the returned resource path has a '/' prefix (I think I read somewhere this is a known Java bug). Plus, the code cannot handle %20 (space) in the url.
I used this code to solve it:

try{
    String url1 = getClass().getResource("/resources/lena.png").getPath();
    if (url1.startsWith("/", 0))
       url1=url1.replaceFirst("/", "");
    url1=URLDecoder.decode(url1, "UTF-8"); //this will replace %20 with spaces
    Mat image = Highgui.imread(url1); 
}
catch ...
edit flag offensive delete link more
0

answered 2014-03-23 00:55:37 -0600

Kevin Infante gravatar image

The second answer works perfect! But there are two things that I wanna say: 1. You have to update the eclipse running class by typing "run" when you are running sbt in the windows command prompt. You can check this by clicking the console eclipse line error. (For example, if it says error in line 26, you click this one and you will see if the line error corresponds to the actual error. And the most important 2. The string which worked for me was /lena.png instead of resources/lena.png. It is very important.

edit flag offensive delete link more
0

answered 2013-03-11 10:32:28 -0600

icykof gravatar image

Hi,

I have the same problem. In my case i am running on Windows XP using Eclipse. From my investigation it looks like there is no data in the image matrix.

I tried the various solutions given but none seems to work in my case.

If anyone could enlighten me. Thank you in advance!

edit flag offensive delete link more
0

answered 2014-02-19 10:01:18 -0600

lourish gravatar image

The problem is with URL paths and file paths. While on unix the URL path might work as an absolute file path on windows it is not the same thing. Probably the most reliable way to get the file path is to create a file object:

    final URI xmlUri = getClass().getResource("/lbpcascade_frontalface.xml").toURI();
    final CascadeClassifier faceDetector =
            new CascadeClassifier(new File(xmlUri).getAbsolutePath());
    final URI imageUri = getClass().getResource("/lena.png").toURI();
    final Mat image = Highgui.imread(new File(imageUri).getAbsolutePath());
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-23 10:14:07 -0600

Seen: 47,561 times

Last updated: Mar 23 '14