当前位置: 首页 > news >正文

使用opencv基于realsense D435i展示基本的图像

此示例是 Intel RealSense 相机与 OpenCV 集成的 “Hello World” 基础代码。示例将打开一个 OpenCV 的 UI 窗口,并将彩色化的深度流渲染到窗口中。以下代码片段演示了如何从 rs2::frame 创建 cv::Mat:
在这里插入图片描述

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include <opencv2/opencv.hpp>   // Include OpenCV APIint main(int argc, char * argv[]) try
{// Declare depth colorizer for pretty visualization of depth data// 建着色过滤器(Colorizer Filter)// 该过滤器根据输入的深度帧生成彩色图像。// 与直接使用OpenCV的区别,RealSense Colorizer	硬件加速、低延迟	依赖RealSense SDK// cv::applyColorMap()	跨平台、可定制	需手动处理深度值归一化rs2::colorizer color_map;// Declare RealSense pipeline, encapsulating the actual device and sensorsrs2::pipeline pipe;// Start streaming with default recommended configurationpipe.start();using namespace cv;const auto window_name = "Display Image"; namedWindow(window_name, WINDOW_AUTOSIZE);while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0){rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camerars2::frame depth = data.get_depth_frame().apply_filter(color_map);// Query frame size (width and height)// 返回图像的像素高度const int w = depth.as<rs2::video_frame>().get_width();const int h = depth.as<rs2::video_frame>().get_height();// Create OpenCV matrix of size (w,h) from the colorized depth dataMat image(Size(w, h), CV_8UC3, (void*)depth.get_data(), Mat::AUTO_STEP);// Update the window with new dataimshow(window_name, image);}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;
}

此外,上面手动转换image如果是彩色图像色值会有问题,可以直接使用realsense提供的转换接口:

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include <opencv2/opencv.hpp>   // Include OpenCV API
#include "../cv-helpers.hpp"
int main(int argc, char * argv[]) try
{// Declare depth colorizer for pretty visualization of depth data// 建着色过滤器(Colorizer Filter)// 该过滤器根据输入的深度帧生成彩色图像。// 与直接使用OpenCV的区别,RealSense Colorizer	硬件加速、低延迟	依赖RealSense SDK// cv::applyColorMap()	跨平台、可定制	需手动处理深度值归一化rs2::colorizer color_map;// Declare RealSense pipeline, encapsulating the actual device and sensorsrs2::pipeline pipe;// Start streaming with default recommended configurationpipe.start();using namespace cv;const auto window_name = "Display Image"; namedWindow(window_name, WINDOW_AUTOSIZE);while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0){rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camerars2::frame depth = data.get_depth_frame().apply_filter(color_map);rs2::frame color = data.get_color_frame();// Query frame size (width and height)// 返回图像的像素高度const int w = depth.as<rs2::video_frame>().get_width();const int h = depth.as<rs2::video_frame>().get_height();const int cw = color.as<rs2::video_frame>().get_width();const int ch = color.as<rs2::video_frame>().get_height();// Create OpenCV matrix of size (w,h) from the colorized depth data//Mat image(Size(w, h), CV_8UC3, (void*)depth.get_data(), Mat::AUTO_STEP);Mat image = frame_to_mat(depth);// Update the window with new dataimshow(window_name, image);}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;
}
http://www.lryc.cn/news/609607.html

相关文章:

  • 计算机网络:有路由器参与的子网间通信原理
  • 阿里云与华为云产品的差异
  • 计算机网络:网络号和网络地址的区别
  • OpenCV轻松入门_面向python(第二章图像处理基础)
  • 从物理扇区到路径访问:Linux文件抽象的全景解析
  • Linux 网络深度剖析:传输层协议 UDP/TCP 原理详解
  • iostat 系统IO监控命令学习
  • 二叉树的概念以及二叉树的分类,添加,删除
  • OpenCV计算机视觉实战(18)——视频处理详解
  • Postman:配置环境变量
  • 【Unity3D实例-功能-镜头】第三人称视觉
  • VUE2 学习笔记17 路由
  • 算法训练营DAY50 第十一章:图论part01
  • 代码随想录day55图论5
  • [spring-cloud: 负载均衡]-源码分析
  • 软件设计 VS 软件需求:了解成功软件开发外包的关键差异
  • 【数据结构入门】链表
  • Centos7.9安装Oracle11.2.0.1版本问题处理
  • Python实现Word转PDF全攻略:从入门到实战
  • 电商直播流量爆发式增长,华为云分布式流量治理与算力调度服务的应用场景剖析
  • windows内核研究(软件调试-软件断点)
  • 房屋租赁小程序租房小程序房产信息发布系统房屋租赁微信小程序源码
  • 架构师面试(三十九):微服务重构单体应用
  • 剧本杀小程序系统开发:开启沉浸式推理社交新纪元
  • 力扣1124:表现良好的最长时间段
  • 【Java】使用FreeMarker来实现Word自定义导出
  • leetcode-sql-3497分析订阅转化
  • 旧物回收小程序:开启绿色生活新篇章
  • Array容器学习
  • LeetCode 132:分割回文串 II