reselsense采集深度值

在显示的深度视频流点击鼠标显示该像素点的深度值

#include "pxcsensemanager.h"

#include "pxcmetadata.h"
#include "util_cmdline.h"
#include "util_render.h"
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
Mat depth;
Mat color;
//鼠标点击回调函数
void on_mouse(int event, int x, int y, int flags, void *ustc);
int wmain(int argc, WCHAR* argv[])
{
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;


namedWindow("depth");
setMouseCallback("depth", on_mouse, 0);
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的大小
depth = Mat(Size(depth_information.width, depth_information.height), CV_16UC1, (void*)depth_data.planes[0], depth_data.pitches[0] / sizeof(uchar));
color = Mat(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);
//CV_16UC1的图片在imshow时,原始数据将除以256,将最远探测距离设为z,那么imshow时可以乘以255*256/z,此处乘以15
imshow("depth", depth * 15);


waitKey(1);
}
psm->Release();
}
void on_mouse(int event, int x, int y, int flags, void *ustc)
{
if (event == CV_EVENT_LBUTTONDOWN)
{
cout << depth.at<ushort>(y, x) << "mm" << endl;
}
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值