#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 main(int argc, WCHAR* argv[])
{
//创建图像窗口
UtilRender* Rcolor = new UtilRender(L"COLOR");
UtilRender* Rdepth = new UtilRender(L"DEPTH");
//引用接口,判断是否连接上R200
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 *colorIm, *depthIm, *irIm;
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();
Mat resizecolor;
resize(color,resizecolor,Size(640,480));
imshow("color", resizecolor);
waitKey(1);
Mat redepth = depth * 15;
imshow("depth", redepth);
waitKey(1);
imwrite("color.png",resizecolor);
imwrite("depth.png",redepth);
}
psm->Release();
}
OpenCV——Realsense读取保存RGB图像和深度图像
最新推荐文章于 2024-04-14 15:00:31 发布