realsense彩色图与深度图对齐

       其实realsense的彩色图与深度图对齐非常简单,因为当你开始采集彩色图与深度图流时,会自动产生一个对齐后的图像流,一个是彩色对齐深度:color_aligned_to_depth,一个是深度对齐彩色:depth_aligned_to_color,表现出来就是一个是显示深度图里具有深度部分才有的图像,一个刚好反过来,所以一个是RGB一个是16UC1,所以接上一篇,我们可以将他们显示出来。不过说看起来彩色图和深度图还是有误差的,所以如果要求准确的话,还是最好自己标定一下然后再自行对齐比较好。

#include <librealsense/rs.hpp>
#include "example.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <thread>

using namespace cv;
using namespace std;

struct rgb_pixel
{
    uint8_t r,g,b;
};

int main()
{
    rs::log_to_console(rs::log_severity::warn);
    rs::context ctx;
    if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
    rs::device & dev = *ctx.get_device(0);
    dev.enable_stream(rs::stream::color, 640, 480, rs::format::rgb8, 60);
    dev.enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 60);
    dev.start();

    while(1)
        {
            dev.wait_for_frames();
            uchar* pRgb = (uchar*)dev.get_frame_data(rs::stream::color);
            uint16_t *depthImage = (uint16_t *) dev.get_frame_data(rs::stream::depth);
            uchar* pCad = (uchar*)dev.get_frame_data(rs::stream::color_aligned_to_depth);
            Mat rgb_show;
            Mat rgb(480, 640, CV_8UC3, pRgb);
            cvtColor(rgb, rgb_show, CV_BGR2RGB);
            imshow("RGBImage",rgb_show);
            Mat depth(480,640,CV_16UC1, depthImage);
            imshow("Depthimage",depth*15);
            Mat cad_show;
            Mat cad(480, 640, CV_8UC3, pCad);
            cvtColor(cad, cad_show, CV_BGR2RGB);
            imshow("CADImage",cad_show);
            waitKey(10);
        }
}


评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值