- 首页 > it技术 > >
Mat src = https://www.it610.com/article/imread("path", IMREAD_UNCHANGED);
//对于深度为8位的普通深度图,IMREAD_UNCHANGED可以省略,若原始深度图像的深度为16位,不能省略,否则src会成为三通道的色彩图像
Mat Gray = Mat(src.rows, src.cols, CV_8UC1);
for (size_t i = 0;
i < src.rows;
i++)
{
uchar* data_gray = Gray.ptr(i);
ushort* data_src = https://www.it610.com/article/src.ptr(i);
//16位用ushort,如果为8位则改为uchar
for (size_t j = 0;
j < src.cols;
j++)
{
if (data_src[j]min) //max,min表示需要的深度值的最大/小值
{
data_gray[j] = (data_src[j] - min) / (max - min) * 255.0f;
}
else
{
data_gray[j] = 255;
}
}
}
imwrite("path", Gray);
imshow("gray", Gray);
waitKey(0);
推荐阅读