I am using the below code to view the following image.
(If you cannot see the image, right click the above space and save image..) The image is 32 bit. OpenCV shows white image. It is a white arrow image, with alpha value around it.
Mat img = imread("FordwardIcon.png", CV_LOAD_IMAGE_UNCHANGED | CV_LOAD_IMAGE_ANYDEPTH);
cout << img.depth() << "\t" << img.channels() << endl;
imshow("img", img);
waitKey(0);
Kindly let me know how to correctly load the image
no fear, your image loaded correctly.
the problem is more that you expected imshow() to honour the alpha channel ( it does not ) .
At present, Opencv (3.0) does not seem to be able to load png images with transparency (aka "alpha channel"). To load these kind of images with cv::imread()
, you need to remove the transparency channel first, and replace it with some color.
This can be done easily with Linux using the Imagemagick tools. For example:
convert input.png -background '#00ff00' -flatten result.png
You can check if an image has it (or not) with the file
tool. On the image you provide:
>$ file input.png
gives:
input.png: PNG image data, 52 x 32, 8-bit gray+alpha, non-interlaced
while
>$ file result.png
gives
result.png: PNG image data, 52 x 32, 8-bit colormap, non-interlaced
See http://www.imagemagick.org/script/convert.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With