Loading png image always result in an empty Matrix
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);
}
}
}
}
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.
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 ...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 ;)