深度图转伪色彩图

该博客介绍了如何将深度图转换为伪色彩图的过程。通过指定的函数,利用深度图的像素值范围(最大值和最小值),可以将原始的灰度深度图像转化为具有色彩视觉效果的Mat格式图像。

函数

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;
            }

        }
    }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值