imread(图像路径,读取方式)
文件路径可以使用 “/” “//” “\” 中的任意一种。
读取方式中,不同的flag对应的结果如下
CV_LOAD_IMAGE_ANYDEPTH 读取到的文件只有一个通道,但是保持原图像的位深度。
其中位深度使用枚举的方式表示。
enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, CV_64F=6 };
所以在在下面的代码中,输出位深度为0;
Mat image = imread("C:\\Users\\hui.zhou\\Desktop\\Cuda Test\\32x32_ps.tif",2);
if (image.rows == 0)
{
printf("image read error! \n");
system("pause");
}
int width = image.cols;
int height = image.rows;
int n = width * height;
printf("width height channel depth: %d %d %d %d...\n",
width, height , image.channels() , image.depth());
所以这种代码风格很不好,建议使用如下代码
if (dst.depth() == CV_8U)
cout << "Unsigned char image" << endl;