# libpng warning: Image width is zero in IHDR

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*

edit retag close merge delete

Sort by » oldest newest most voted

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

more

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

( 2013-02-23 17:30:20 -0500 )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

( 2013-02-24 04:12:15 -0500 )edit

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

( 2013-02-24 05:27:58 -0500 )edit

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

( 2013-02-24 05:29:52 -0500 )edit

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
}
catch ...

more

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.

more

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!

more

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 URI imageUri = getClass().getResource("/lena.png").toURI();
final Mat image = Highgui.imread(new File(imageUri).getAbsolutePath());

more

Official site

GitHub

Wiki

Documentation