首页 » 技术分享 » R200显示深度图

R200显示深度图

 

开始编程之前,不要忘了下载安装RealSense的SDK,添加路径。楼主的安装路径在D盘,并用VS2013编程,具体应做对应修改,如vs2010编程应改成v100


包含目录添加


D:\R200SDK安装\RSSDK\sample\core\common\include


D:\R200SDK安装\RSSDK\include


D:\R200SDK安装\RSSDK\include\service


D:\R200SDK安装\RSSDK\include\utilities


库目录添加


D:\R200SDK安装\RSSDK\lib\Win32


D:\R200SDK安装\RSSDK\sample\common\lib\Win32\v110


链接器->输入添加

libpxc_d.lib

libpxcutils_d.lib

到此处,配置完成

代码如下:

#include "pxcsensemanager.h"
#include "pxcmetadata.h"
#include "util_cmdline.h"
#include "util_render.h"
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;

int wmain(int argc, WCHAR* argv[])
{
        UtilRender*  Rcolor=new UtilRender(L"COLOR");
        UtilRender*  Rdepth=new UtilRender(L"DEPTH");
        
        PXCSenseManager *psm = PXCSenseManager::CreateInstance();
    if (!psm)
    {
        wprintf_s(L"Unabel to create the PXCSenseManager\n");
        return 1;
    }
        

    psm->EnableStream(PXCCapture::STREAM_TYPE_COLOR);
    psm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH);

    if (psm->Init() != PXC_STATUS_NO_ERROR)
    {
        wprintf_s(L"Unable to Init the PXCSenseManager\n");
        return 2;
    }

    PXCImage *colorIm, *depthIm;
    PXCImage::ImageData depth_data;
    PXCImage::ImageData color_data;
    PXCImage::ImageInfo depth_information;
    PXCImage::ImageInfo color_information;

    while (1)
    {
        if (psm->AcquireFrame(true) < PXC_STATUS_NO_ERROR) break;

        PXCCapture::Sample *sample = psm->QuerySample();

        colorIm = sample->color;
        depthIm = sample->depth;

                //获取深度和彩色帧
                colorIm->AcquireAccess(PXCImage::ACCESS_READ,PXCImage::PIXEL_FORMAT_RGB24,  &color_data);
        depthIm->AcquireAccess(PXCImage::ACCESS_READ, &depth_data);//深度帧获取的格式也可调节

        depth_information = sample->depth->QueryInfo();
        color_information = sample->color->QueryInfo();

       //最后步进不要忘了除以uchar的大小
                Mat depth(Size(depth_information.width,depth_information.height),CV_16UC1,(void*)depth_data.planes[0],depth_data.pitches[0]/sizeof(uchar));
                Mat color(Size(color_information.width,color_information.height),CV_8UC3, (void*)color_data.planes[0],color_data.pitches[0]/sizeof(uchar));
        
        depthIm->ReleaseAccess(&depth_data);
        colorIm->ReleaseAccess(&color_data);

        psm->ReleaseFrame();
        
                imshow("color", color);
                waitKey(1);
                //CV_16UC1的图片在imshow时会除以256,将最远探测距离设为z,那么imshow时可以乘以255*256/z,此处乘以15
                imshow("depth",depth*15);
        waitKey(1);
    }
    psm->Release(); 
}

转载自原文链接, 如需删除请联系管理员。

原文链接:R200显示深度图,转载请注明来源!

0