win下使用realsense+opencv获取RGBD数据
来源:互联网 发布:windows swift 编译器 编辑:程序博客网 时间:2024/05/19 00:56
最近在学习realsense,期间遇到了很多麻烦,经过大家的帮助最终都解决了。现在记录下来,也方便帮助他人。
这篇文章主要是实现opencv显示realsense读取的彩色和深度数据。
首先说一下环境:win10+VS2013;opencv2.4.9 ;realsense有官方的SDK,不过我使用的是git上的资源librealsense,这里贴一下链接:https://github.com/IntelRealSense/librealsense。在这里,首先你要把opencv配置好,这个网上有很多资源。然后把librealsense下载下来,根据自己VS的版本打开相应工程就行。
代码很简单,如下:
// License: Apache 2.0. See LICENSE file in root directory.// Copyright(c) 2015 Intel Corporation. All Rights Reserved./////////////////////////////////////////////////////// librealsense tutorial #1 - Accessing depth data ///////////////////////////////////////////////////////#include <librealsense/rs.hpp>#include <cstdio>#include <iostream>#include <opencv2/opencv.hpp>using namespace std;using namespace cv;int main() try{// 创建context对象,用来控制所有realsense设备。rs::context ctx;printf("There are %d connected RealSense devices.\n", ctx.get_device_count());if (ctx.get_device_count() == 0) return EXIT_FAILURE;// 这里只获取一个设备。rs::device * dev = ctx.get_device(0);printf("\nUsing device 0, an %s\n", dev->get_name());printf(" Serial number: %s\n", dev->get_serial());printf(" Firmware version: %s\n", dev->get_firmware_version());//设备设置数据流只有两种,彩色和深度。dev->enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 30);dev->enable_stream(rs::stream::color, 640, 480, rs::format::bgr8, 30);dev->start();// 这里dev->get_depth_scale()返回深度和实际转换比例:0.001。const uint16_t one_meter = static_cast<uint16_t>(1.0f / dev->get_depth_scale());bool flag = true;while (flag){dev->wait_for_frames();// 数据读取和填充的部分。uchar * color_frame = (uchar*)(dev->get_frame_data(rs::stream::color));uint16_t * depth_frame = (uint16_t *)(dev->get_frame_data(rs::stream::depth));Mat colorImg(480,640,CV_8UC3,color_frame);Mat depthImg(480,640,CV_16UC1,depth_frame);// 最终显示。imshow("color", colorImg);imshow("depth", depthImg*10);waitKey(10);}return EXIT_SUCCESS;}catch (const rs::error & e){// 异常处理。printf("rs::error was thrown when calling %s(%s):\n", e.get_failed_function().c_str(), e.get_failed_args().c_str());printf(" %s\n", e.what());return EXIT_FAILURE;}
阅读全文
0 0
- win下使用realsense+opencv获取RGBD数据
- win下使用realsense进行数据修正并获取三维坐标
- ubuntu14.04利用opencv‘获取realsense图像
- 利用PCL处理Realsense点云数据-使用VoxelGrid滤波器对点云进行下采样
- RGBD物体识别(4)--使用opencv3读取kinect数据
- 配置realsense和opencv
- Intel RealSense学习之图像及图像深度数据获取
- WIN下使用PYTHON和JAVA作OPENCV开发
- 利用PCL处理Realsense点云数据-在vs2015里用PCL获取Realsense点云数据
- win下安装opencv-python
- realsense r200模块在ros-indigo版本下的使用
- realsense r200与rtabmap在ros下的使用
- ROS下使用intel Realsense摄像头进行人脸检测
- ROS下使用intel Realsense摄像头进行人脸检测
- RealSense SDK 开发笔记 (三)获取R200的图像(OpenCV Mat)
- kth-rgbd程序使用注意事项
- win下使用mongodb
- Win 下使用py2exe
- Java的System类,Runtime类
- Flask扩展: Flask-Bootstrap
- ZooKeeper集群搭建 windows篇
- 金蝶EAS,KDTable数据填充,需重新解析表格tblMain.checkParsed()
- 安装mysql出现卡死
- win下使用realsense+opencv获取RGBD数据
- ADB server didn't ACK failed to start daemon
- SpringBoot——初接触
- python模块源代码加密方法
- java语言基础|java语言特点
- 字符串处理,根据传入的参数进行分离,目前较适合字符串中提取引号包裹的部分的提取
- oracle发送邮件
- Mybatis Generator完整配置详解
- Linux下mysql安装教程,环境:阿里云 Ubuntu 14.04 mysql 5.6