当前位置:网站首页>Realsense d435 d435i d415 depth camera obtains RGB map, left and right infrared camera map, depth map and IMU data under ROS
Realsense d435 d435i d415 depth camera obtains RGB map, left and right infrared camera map, depth map and IMU data under ROS
2022-07-04 10:13:00 【Wildcraner】
First of all, you should make sure that your camera driver is installed , Environment configuration can be seen in another article of mine :https://blog.csdn.net/weixin_46195203/article/details/119205851
** First step :** Create a new file informationread( The recommended file name here is :informationread, In this way, there is no need to modify it separately Makelist The information in the )
** The second step :** stay informationread Create two new files under the folder, which are build and src One more CMakeLists.txt file
** The third step :** stay CMakeLists.txt Copy the code in the file
cmake_minimum_required(VERSION 3.1.0)
project(alldata)
set( CMAKE_CXX_COMPILER "g++" )
set( CMAKE_BUILD_TYPE "Release" )
set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(realsense2 REQUIRED)
include_directories( ${
OpenCV_INCLUDE_DIRS} )
include_directories( ${
realsense2_INCLUDE_DIRS})
add_executable(informationread src/GetAlldata.cpp)
target_link_libraries(informationread ${
OpenCV_LIBS} ${
realsense2_LIBRARY})
** Step four :** Copy the following code to a .cpp file Put it in src In file ( It is suggested that cpp The file named :GetAlldata.cpp, In this way, there is no need to modify it separately Makelist The information in the )
#include <librealsense2/rs.hpp>
// include OpenCV header file
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define width 640
#define height 480
#define fps 30
int main(int argc, char** argv) try
{
// judge whether devices is exist or not
rs2::context ctx;
auto list = ctx.query_devices(); // Get a snapshot of currently connected devices
if (list.size() == 0)
throw std::runtime_error("No device detected. Is it plugged in?");
rs2::device dev = list.front();
//
rs2::frameset frames;
//Contruct a pipeline which abstracts the device
rs2::pipeline pipe;// Establish a communication pipeline //https://baike.so.com/doc/1559953-1649001.html pipeline The explanation of
//Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;
//Add desired streams to configuration
cfg.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_BGR8, fps);// Color images
cfg.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16,fps);// Depth image
cfg.enable_stream(RS2_STREAM_INFRARED, 1, width, height, RS2_FORMAT_Y8, fps);// Infrared image 1
cfg.enable_stream(RS2_STREAM_INFRARED, 2, width, height, RS2_FORMAT_Y8, fps);// Infrared image 2
// If you want to get imu Data uncomment the following two lines of code , And modify it imu Assignment
//cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);// gyroscope
//cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);// gyroscope
int imu = 0;// If you want to get imu data , This is set to 1
// get depth scale
// float depth_scale = get_depth_scale(profile.get_device());
// start stream
pipe.start(cfg);// Instructs the pipeline to start the flow with the requested configuration
while(1)
{
frames = pipe.wait_for_frames();// Wait for all configured flow generation frameworks
// Align to depth
rs2::align align_to_depth(RS2_STREAM_DEPTH);
frames = align_to_depth.process(frames);
// Get imu data
if(imu){
if (rs2::motion_frame accel_frame = frames.first_or_default(RS2_STREAM_ACCEL))
{
rs2_vector accel_sample = accel_frame.get_motion_data();
std::cout << "Accel:" << accel_sample.x << ", " << accel_sample.y << ", " << accel_sample.z << std::endl;
}
if (rs2::motion_frame gyro_frame = frames.first_or_default(RS2_STREAM_GYRO))
{
rs2_vector gyro_sample = gyro_frame.get_motion_data();
std::cout << "Gyro:" << gyro_sample.x << ", " << gyro_sample.y << ", " << gyro_sample.z << std::endl;
}
}
//Get each frame
rs2::frame color_frame = frames.get_color_frame();
rs2::frame depth_frame = frames.get_depth_frame();
rs2::video_frame ir_frame_left = frames.get_infrared_frame(1);
rs2::video_frame ir_frame_right = frames.get_infrared_frame(2);
// Creating OpenCV Matrix from a color image
Mat color(Size(width, height), CV_8UC3, (void*)color_frame.get_data(), Mat::AUTO_STEP);
Mat pic_right(Size(width,height), CV_8UC1, (void*)ir_frame_right.get_data());
Mat pic_left(Size(width,height), CV_8UC1, (void*)ir_frame_left.get_data());
Mat pic_depth(Size(width,height), CV_16U, (void*)depth_frame.get_data(), Mat::AUTO_STEP);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", color);
waitKey(1);
imshow("Display depth", pic_depth*15);
waitKey(1);
imshow("Display pic_left", pic_left);
waitKey(1);
imshow("Display pic_right",pic_right);
waitKey(1);
}
return 0;
}
// error
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;
}
The default in the code is D415 perhaps D435 This one doesn't imu The camera has no output imu Information
If you want imu Information Follow the instructions to make minor modifications .
** Step four :** stay build Open the command window in the file and enter
cmake ..
make -j4
./informationread
Now you can see the real-time running results
边栏推荐
- Modules golang
- 2. Data type
- H5 audio tag custom style modification and adding playback control events
- 2021-08-11 function pointer
- Hands on deep learning (32) -- fully connected convolutional neural network FCN
- C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
- Go context 基本介绍
- Go context basic introduction
- ASP. Net to access directory files outside the project website
- PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
猜你喜欢

C语言指针经典面试题——第一弹

Dynamic memory management

xxl-job惊艳的设计,怎能叫人不爱

Some summaries of the third anniversary of joining Ping An in China

Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot

【Day2】 convolutional-neural-networks

基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2

QTreeView+自定义Model实现示例

If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display

Mmclassification annotation file generation
随机推荐
Servlet基本原理与常见API方法的应用
Intelligent gateway helps improve industrial data acquisition and utilization
使用 C# 提取 PDF 文件中的所有文字(支持 .NET Core)
Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
回复评论的sql
Exercise 8-10 output student grades (20 points)
智慧路灯杆水库区安全监测应用
A little feeling
Kotlin set operation summary
华为联机对战如何提升玩家匹配成功几率
Ruby时间格式转换strftime毫秒匹配格式
PHP book borrowing management system, with complete functions, supports user foreground management and background management, and supports the latest version of PHP 7 x. Database mysql
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
转载:等比数列的求和公式,及其推导过程
The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
C # use ffmpeg for audio transcoding
Golang 类型比较
How web pages interact with applets
Ruby time format conversion strftime MS matching format
PHP code audit 3 - system reload vulnerability