VS2015forOpeCV411版本读取图像深度单通道16bit
#include
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat src;
src = imread(“D:/1.tif”, IMREAD_ANYDEPTH);
if (src.empty())
{
cout << “pic error” << endl;
return -1;
}
ushort *pdata = src.ptr(0);
cout << “pix–” << src.elemSize() << endl;
for (int i = 0; i < 640; i++)
{
printf("%ld ", *pdata++);
}
namedWindow("tt");
imshow("tt", src);
waitKey(0);
return 0;
}
imread(读取图片函数)函数第二参数诠释:
注:读取图片的时候第一个参数字符串中要使用“D:/1.tif“,斜杠打反了会转义后面的字符。
flag=-1时,8位深度,原通道
flag=0,8位深度,1通道
flag=1, 8位深度 ,3通道
flag=2,原深度,1通道
flag=3, 原深度,3通道
flag=4,8位深度 ,3通道
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
读取图片的灰度值(这里以单通道16bit为例)
ushort *pdata = src.ptr(0);
ptr读取的是一行的数据。