Most .jpg images are 8-bit images. By default, their default data type is unsigned char or char .
Some images, such as .png or .tif , also support a 16-bit pixel value, so their data type is unsigned short . But this is not necessary, as they can be 8 bits.
To load the image as is in OpenCV, use imread as follows:
cv::Mat img = cv::imread(imagePath, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
There are various combinations of these flags:
Download 8 bits (regardless of the original depth):
CV_LOAD_IMAGE_COLOR
Loading with original depth:
CV_LOAD_IMAGE_COLOR | CV_LOAD_IMAGE_ANYDEPTH
Download as grayscale (no matter how many channels an image has):
CV_LOAD_IMAGE_GRAYSCALE
Grayscale loading with original depth:
CV_LOAD_IMAGE_GRAYSCALE| CV_LOAD_IMAGE_ANYDEPTH
In your case, lena.jpg is an 8-bit image, so you get an unsigned char data type.
Update:
For newer versions of OpenCV, use the flags defined by enum in the C ++ interface. Just replace CV_LOAD_IMAGE_* with cv::IMREAD_* .
eg. CV_LOAD_IMAGE_GRAYSCALE becomes cv::IMREAD_GRAYSCALE .
source share