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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       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 
根据引用\[1\]中的描述,可以使用基于RGB信息的区域生长分割算法对Realsense D435i相机获取的现场图像进行快速分割。首先,使用D435i相机获取现场RGB和Depth信息生成带有彩色信息的点云,并对点云进行下采样。然后,对约简后的点云进行分割,实现点云的分割操作。 在使用Realsense D435i相机时,可以按照引用\[2\]中的指导进行操作。首先,在终端中运行命令"roslaunch realsense2_camera rs_camera.launch"来启动相机。然后,在rviz中修改全局坐标系,将Fixed Frame一栏改为"camera_color/depth_",并添加相机,选择上述realsense包发布的话题进行订阅,即可看到点云分割的效果。 如果需要使用OpenCV来判断物体的方向,可以参考引用\[3\]中的direction_func.py。该脚本使用OpenCV来判断物体的方向,通过计算物体的中心点坐标(cenx, ceny)和深度像素(depth_pixel)来获取物体的方向信息。 综上所述,可以使用Realsense D435i相机进行点云分割操作,并可以结合OpenCV来判断物体的方向。 #### 引用[.reference_title] - *1* [基于RGB_D图像的现场点云分割(d435i c++ pcl)](https://blog.youkuaiyun.com/m0_56838271/article/details/121158460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Realsense D435用rviz查看点云信息](https://blog.youkuaiyun.com/No_vegetable/article/details/124555837)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Intel RealSense D435i深度相机通过点云获取图片中任意点三维信息(python实现)](https://blog.youkuaiyun.com/weixin_49828565/article/details/127051358)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值