• Realsense D430 save


    rs-save-to-disk.cpp

    // License: Apache 2.0. See LICENSE file in root directory.
    // Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
    
    #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
    
    #include <fstream>              // File IO
    #include <iostream>             // Terminal IO
    #include <sstream>              // Stringstreams
    
    // 3rd party header for writing png files
    #define STB_IMAGE_WRITE_IMPLEMENTATION
    #include "stb_image_write.h"
    
    // Helper function for writing metadata to disk as a csv file
    void metadata_to_csv(const rs2::frame& frm, const std::string& filename);
    
    // This sample captures 30 frames and writes the last frame to disk.
    // It can be useful for debugging an embedded system with no display.
    int main(int argc, char * argv[]) try
    {
        // Declare depth colorizer for pretty visualization of depth data
        rs2::colorizer color_map;
    
        // Declare RealSense pipeline, encapsulating the actual device and sensors
        rs2::pipeline pipe;
        // Start streaming with default recommended configuration
        pipe.start();
    
        // Capture 30 frames to give autoexposure, etc. a chance to settle
        for (auto i = 0; i < 30; ++i) pipe.wait_for_frames();
    
        // Wait for the next set of frames from the camera. Now that autoexposure, etc.
        // has settled, we will write these to disk
        for (auto&& frame : pipe.wait_for_frames())
        {
            // We can only save video frames as pngs, so we skip the rest
            if (auto vf = frame.as<rs2::video_frame>())
            {
                auto stream = frame.get_profile().stream_type();
                // Use the colorizer to get an rgb image for the depth stream
                if (vf.is<rs2::depth_frame>()) vf = color_map(frame);
    
                // Write images to disk
                std::stringstream png_file;
                png_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name() << ".png";
                stbi_write_png(png_file.str().c_str(), vf.get_width(), vf.get_height(),
                               vf.get_bytes_per_pixel(), vf.get_data(), vf.get_stride_in_bytes());
                std::cout << "Saved " << png_file.str() << std::endl;
    
                // Record per-frame metadata for UVC streams
                std::stringstream csv_file;
                csv_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name()
                         << "-metadata.csv";
                metadata_to_csv(vf, csv_file.str());
            }
        }
    
        return EXIT_SUCCESS;
    }
    catch(const rs2::error & e)
    {
        std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):
        " << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    catch(const std::exception & e)
    {
        std::cerr << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    
    void metadata_to_csv(const rs2::frame& frm, const std::string& filename)
    {
        std::ofstream csv;
    
        csv.open(filename);
    
        //    std::cout << "Writing metadata to " << filename << endl;
        csv << "Stream," << rs2_stream_to_string(frm.get_profile().stream_type()) << "
    Metadata Attribute,Value
    ";
    
        // Record all the available metadata attributes
        for (size_t i = 0; i < RS2_FRAME_METADATA_COUNT; i++)
        {
            if (frm.supports_frame_metadata((rs2_frame_metadata_value)i))
            {
                csv << rs2_frame_metadata_to_string((rs2_frame_metadata_value)i) << ","
                    << frm.get_frame_metadata((rs2_frame_metadata_value)i) << "
    ";
            }
        }
    
        csv.close();
    }
  • 相关阅读:
    WKWebView加载显示问题
    获取iOS设备信息(内存/电量/容量/型号/IP地址/当前WIFI名称)
    iOS scrollsToTop
    iOSNSTimer 后台运行
    iOS监听home,进入后台
    iOS 模拟器改变定位地点的两种方法
    iOS 系统定位具体到省市区街道
    iOS 中的 HotFix 方案总结详解
    iOS 10 :用 UIViewPropertyAnimator 编写动画
    iOS中常见 Crash 及解决方案
  • 原文地址:https://www.cnblogs.com/herd/p/11390480.html
Copyright © 2020-2023  润新知