opencv读取realsense
生活随笔
收集整理的這篇文章主要介紹了
opencv读取realsense
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
代碼如下:
#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 datars2::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 = "depth Image";const auto window_name1 = "color Image";namedWindow(window_name, WINDOW_AUTOSIZE);namedWindow(window_name1, WINDOW_AUTOSIZE);while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0&&getWindowProperty(window_name1, 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().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();const int w1 = color.as<rs2::video_frame>().get_width();const int h1 = color.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);Mat images(Size(w1, h1), CV_8UC3, (void*)color.get_data(), Mat::AUTO_STEP);// Update the window with new dataimshow(window_name1, images);imshow(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; }在這里插入代碼片總結(jié)
以上是生活随笔為你收集整理的opencv读取realsense的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TensorRT实现RetinaFace
- 下一篇: 易语言exe读写游戏例程源码_中文编程易