函数
void depth2color(cv::Mat & color, const cv::Mat & depth, const double max, const double min)
{
cv::Mat grayImage;
double alpha = 255.0 / (max - min);
depth.convertTo(grayImage, CV_8UC1, alpha, -alpha * min );// expand your range to 0..255. Similar to histEq();
cv::applyColorMap(grayImage, color, cv::COLORMAP_JET);// this is great. It converts your grayscale image into a tone-mapped one, much more pleasing for the eye function is found in contrib module, so include contrib.hpp and link accordingly
}
- 函数各参数意义
color: 目标Mat格式图(伪彩色图)
depth:源深度图
max和min:指每帧深度图的像素点(距离)的最大值和最小值
double imax=0, imin=70000;
int imrow = depthTmp.rows;
int imcol = depthTmp.cols * depthTmp.channels();
for (int i = 0; i < imrow; i++)
{
for (int j = 0; j < imcol; j++)
{
ushort data = depthTmp.at<ushort>(i, j);
if (imin >= data && data!=0)
{
imin = data;
}
if (imax <= data)
{
imax = data;
}
}
}
该博客介绍了如何将深度图转换为伪色彩图的过程。通过指定的函数,利用深度图的像素值范围(最大值和最小值),可以将原始的灰度深度图像转化为具有色彩视觉效果的Mat格式图像。
1597

被折叠的 条评论
为什么被折叠?



