RealSense D435深度相机开发(二)----基于距离的图像分割(上)

本文介绍了使用RealSense D435深度相机进行图像分割的方法。通过深度信息,可以更精确地进行背景分割,例如仅显示距离相机2米、3米或6米以内的图像。提供了在VS2015中运行的效果图和核心代码,帮助理解并实现该功能。

       RGB-D相机,对比传统的RGB相机,我们很快就能找到不同之处---深度。那么有了深度信息,我们能够做什么呢?

       在做背景分割的时候,RGB相机只能通过帧间差分、特定颜色提取、基于混合高斯模型去除背景等方法,做到前景背景分离,有了RGB-D相机的深度信息,那我们就可以通过Z方向的距离来剔除背景了。先看看vs2015中跑的效果图:

       下面三张图分别表示只显示距离相机2米以内的图像、3米以内、6米以内的图像: 

 

 


       这样我们就能很好的进行背景分割了,不过只是实现了功能,后续还需要再优化,下面是核心代码,有详尽的注释,看懂应该是很容易的。

main.cpp

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>
#include "../example.hpp"
#include <imgui.h>
#include "imgui_impl_glfw.h"

#include <sstream>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>

void render_slider(rect location, float& clipping_dist);
void remove_background(rs2::video_frame& other, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist);
float get_depth_scale(rs2::device dev);
rs2_stream find_stream_to_align(const std::vector<rs2::stream_profile>& streams);
bool profile_changed(const std::vector<rs2::stream_profile>& current, const std::vector<rs2::stream_profile>& prev);

int main(int argc, char * argv[]) try
{
    // Create and initialize GUI related objects
    window app(1280, 720, "CPP - Align Example"); // Simple window handling
    ImGui_ImplGlfw_Init(app, false);      // ImGui library intializition
    rs2::colorizer c;                          // Helper to colorize depth images
    texture renderer;                     // Helper for renderig images

    // Create a pipeline to easily configure and start the camera
    rs2::pipeline pipe;
    //Calling pipeline's start() without any additional parameters will start the first device
    // with its default streams.
    //The start function returns the pipeline profile which the pipeline used to start the device
    rs2::pipeline_profile profile 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值