How to get the bit-depth of an image?
Hi everyone, I have a PNG file which is 16bt per channel (total 48bit), but when I check the bit-depth with openCV using depth() it keeps returning CV_8U (zero).
int imgDepth = cvImage.depth();
Can someone please provide me with a solution to this problem, or at least explain what I'm doing wrong?
Thanks in advance, Mark.
you can find here your answer
Depth number of bits by channel A jpg image (like lena.jpg in opencv/data ) is 8 bits by channel and 3 channels but chicky_512.png is 8 bits by channel and 4channels
Sorry but I still don't understand. The documentation says depth() "Returns the depth of a matrix element" and "CV_8U - 8-bit unsigned integers ( 0..255 )" and "CV_16U - 16-bit unsigned integers ( 0..65535 )"
I already know all of this, and it's not working. I'm new to openCV and new to programming so I don't really know what to do...
may be you can share image
Here is the image
16rows X16 cols X 3channels pixels size 16 bits
mat->rows,mat->cols,mat->channels() mat->depth() (CV_16S)
Why am I getting CV_8U?
Here is my code:
I will try installing newer version and see if it still doesn't work.
may be use cv::IMREAD_UNCHANGED instead of CV_LOAD_IMAGE_COLOR
I managed to fix the problem using: CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR But now the problem is it won't recognize a 4 channel image (says '3'). If I use UNCHANGED flag then it crashes the program when loading a 4 channel image.
It seems that you are not using opencv 3.0? cv::IMREAD_UNCHANGED is for opencv 3.0. I don't know if imread had changed between 2.4.11 and 3.0. May be you should test your program with images in opencv/data giving explicit path for jpg and png and check it