【无标题】

1.深度相机使用的基本代码

 D415深度相机的基本功能可以靠Intel提供的

<librealsense2/rs.hpp>头文件实现

(1)相机视野中心物体到相机的距离:

 #include <librealsense2/rs.hpp>

rs2::pipeline p;//创建管道,用于传输流和每一帧的数据

p.start();

rs2::frameset frames = p.wait_for_frames();//(深度相机通常提供多个视频流),等待用于接受每一个源流的帧

rs2::depth_frame depth = frames.get_depth_frame();//获得总帧数

float width = depth.get_width();

float height = depth.get_height();

float dist_to_center = depth.get_distance(width / 2, height / 2);//获取距离

(2)对齐

作用:将图像从一种视图转变为另一种视图(例如从深度—颜色转变为颜色—深度)

代码:

#include <librealsense2/rs.hpp>

#include "../example.hpp"

#include "imgui.h"

#include "imgui_impl_glfw.h"

rs2::pipeline pipe;

rs2::config cfg;

cfg.enable_stream(RS2_STREAM_DEPTH);

cfg.enable_stream(RS2_STREAM_COLOR);//创建深度流和颜色流

pipe.start(cfg);//配置

rs2::align align_to_depth(RS2_STREAM_DEPTH);

rs2::align align_to_color(RS2_STREAM_COLOR);

frameset = align_to_depth.process(frameset);

glEnable(GL_BLEND);//使用OpenGL 混合功能渲染两个重叠的流

// 使用 Alpha 通道进行混合

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

if (dir == direction::to_depth)

{

    // 对齐深度,首先渲染深度,然后用底片在上面覆盖颜色  

   depth_image.render(colorized_depth, { 0, 0, app.width(), app.height() });

    color_image.render(color, { 0, 0, app.width(), app.height() }, alpha);

}

else

{

    // 同上

    color_image.render(color, { 0, 0, app.width(), app.height() });

    depth_image.render(colorized_depth, { 0, 0, app.width(), app.height() }, 1 - alpha);

}

glColor4f(1.f, 1.f, 1.f, 1.f);

glDisable(GL_BLEND);

//Imgui用于设置UI

ImGui_ImplGlfw_NewFrame(1);

render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir);

ImGui::Render();

(3)将深度和 RGB 数据流传输到屏幕

#include <librealsense2/rs.hpp>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值