OpenCV——Realsense读取保存RGB图像和深度图像

#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();
}
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值