Ask Your Question

Cannot Open a .PNG file using cv::imread()

asked 2012-11-06 04:43:59 -0500

manmedia gravatar image


I am trying to use cv::imread() to load a color image as grayscale. The image is in .PNG format and in colour. So I do the following:

cv::Mat subj(cv::imread("T:/datasets/ssr_main_barrier/barrier_snapshot_1.png",CV_LOAD_IMAGE_GRAYSCALE);

However, it doesn't load the image at all! The reason I am sure is that when I load a grayscale image in the same way, it shows meaningful data by invoking *( which the pointer to the continuous data blocks. And I have double checked the data in MATLAB by using their imread(). Why is this? am I supposed to do further conversion?

Kind Regards,

edit retag flag offensive close merge delete



Does the image have a 4th alpha channel for transparency? OpenCV doesn't support this, as far as I know.

Ben gravatar imageBen ( 2012-11-06 05:23:01 -0500 )edit

I saw today in CMake that you can compile OpenCV "WITH_PNG" which is .png support. If you compiled OpenCV yourself did you remember to include this flag?

ubehagelig gravatar imageubehagelig ( 2012-11-06 07:23:48 -0500 )edit

@ubehagelig I don't know :( Certainly cannot remember about that. I will double check. Thanks for that

@Ben No the image is a pure grayscale and checked it with other languages e.g. MATLAB

manmedia gravatar imagemanmedia ( 2012-11-06 07:49:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2012-11-06 08:13:21 -0500

manmedia gravatar image

updated 2012-11-06 08:19:57 -0500


Solved it! Pointer arithmetic i.e. the data blocks are 32 bits away from each other (4*8-bit Unsigned number) made me confused and the first few data elements of my image matrix is 0. therefore I couldn't see any useful information except 0s when I used the variable in my watch list in VS2010 debugger. My image has a big black patch at the first row, so it was 0. After tearing my hair off for almost a day, I finally realise that I suck at C++ programming :(

Sorry, I cannot put my answer before 48 hours of Orignal Post, Please feel free anyone to copy and paste my answers.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-11-06 04:43:59 -0500

Seen: 3,077 times

Last updated: Nov 06 '12