Ask Your Question
-1

Loading png image always result in an empty Matrix

asked 2017-06-23 07:20:21 -0600

evilkid gravatar image

I am trying to load a simple png image with opencv (3.2.0) with java, using the x64 library. But each time i get an empty matrix (all the pixels are 0). However, when i convert the image to jpg, it works just fine. I have tried to run imread method with every flag possible, I even did this (iterated over every possible flag f):

System.loadLibrary("opencv_java320");
for (int k = 0; k < 130; f++) {
    Mat img = Imgcodecs.imread(inFile, f);
    for (int i = 0; i < img.cols(); i++) {
        for (int j = 0; j < img.rows(); j++) {
            if (img.get(i, j) != null && img.get(i, j)[0] > 0) {
                System.out.println(f);
                System.exit(0);
            }
        }
    }
}

Here is the image I'm running imread against. enter image description here

edit retag flag offensive close merge delete

Comments

unrelated, but , please never try to loop over pixels thatway. use Mat.dump() instead.

you also got rows and cols in reverse in get() , so for sure you should not trust any ouptut of that.

what does System.out.println(img) print ?

why the silly loop over k ? the only flags suppported are -1, 0 and 1.

all and all, i'm suspecting, that each hapless attempt at debugging it, gets you farther away from the truth, not closer.

berak gravatar imageberak ( 2017-06-23 07:30:52 -0600 )edit

ok ill make sure to use dump in the future, but all i sout(img) gave me: Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0xe390b0, dataAddr=0x0 ] and sout(img.dump()) gave me and empty array [] for the silly loop, was a desperate move ...

evilkid gravatar imageevilkid ( 2017-06-23 14:24:36 -0600 )edit

also, be careful with png images containing alpha !

in the case of the image above, the color channels are all 0, the only information is in alpha. (someone tried to make it extra hard to decrypt this ;)

berak gravatar imageberak ( 2017-06-24 02:31:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-23 14:40:21 -0600

evilkid gravatar image

I noticed you said the only supported flags are -1,0,1. So i tried with -1 and worked, weird because i have tried with Imgcodecs.IMREAD_UNCHANGED earlier and it didnt work.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-23 07:20:21 -0600

Seen: 396 times

Last updated: Jun 23 '17