版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28467367/article/details/82262249
Github项目网址:
https://github.com/IntelRealSense/librealsense/tree/master/examples
1.环境配置:
(1)在项目属性管理器中加入C:\Program Files (x86)\Intel RealSense SDK 2.0
目录下的intel.realsense.props文件
如下图:
(2)为引用头文件example.hpp,在项目-属性-VC++目录-包含目录中加入
C:\Program Files (x86)\Intel RealSense SDK 2.0\samples
或者,直接在头文件添加现有项example.hpp即可
2.代码如下:
#include "stdafx.h"
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include "example.hpp" // Include short list of convenience functions for rendering
// Capture Example demonstrates how to
// capture depth and color video streams and render them to the screen
int main(int argc, char * argv[]) try
{
rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
// Create a simple OpenGL window for rendering:
window app(1280, 720, "RealSense Capture Example");
// Declare two textures on the GPU, one for color and one for depth
texture depth_image, color_image;
// Declare depth colorizer for pretty visualization of depth data
//声明深度着色器,以增强深度数据的颜色可视化
rs2::colorizer color_map;
// Declare RealSense pipeline, encapsulating(封装) the actual device and sensors
rs2::pipeline pipe;
// Start streaming with default recommended configuration
pipe.start();
while (app) // Application still alive?
{
rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
// Find and colorize the depth data查找深度数据并给其上色
rs2::frame depth = color_map(data.get_depth_frame());
rs2::frame color = data.get_color_frame(); // Find the color data
// For cameras that don't have RGB sensor, we'll render infrared frames instead of color
if (!color)
color = data.get_infrared_frame();
// Render depth on to the first half of the screen and color on to the second
depth_image.render(depth, { 0, 0, app.width() / 2, app.height() });
color_image.render(color, { app.width() / 2, 0, app.width() / 2, app.height() });
}
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
3.注意:调试过程中,example.hpp文件会出现如下报错“
error C2664:“HWND CreateWindowExW
(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)”:
无法将参数3从“const char”转换为“LPCWSTR”
解决办法:将项目使用的字符集从unicode改成多字节。