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() << "):\n    " << 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()) << "\nMetadata Attribute,Value\n";

    // 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) << "\n";
        }
    }

    csv.close();
}

原文地址:https://www.cnblogs.com/herd/p/11390480.html

时间: 2024-11-05 19:25:54

Realsense D430 save的相关文章

Realsense D430 python pointclound

来自:https://github.com/IntelRealSense/librealsense/issues/1231------------------------------ import pyrealsense2 as rs pipeline = rs.pipeline() pipe_profile = pipeline.start() frames = pipeline.wait_for_frames() depth_frame = frames.get_depth_frame()

ubuntu连接多个realsense d435

import pyrealsense2 as rs import numpy as np import cv2 import time import datetime import threading from IPython import embed #from worker import get_worker, get_ptx from realsense_device_manager_old import DeviceManager from depth_utils import get_

Oralce的Save命令

使用save()命令可以将当前的缓冲区的内容保存到文件中,这样,即使缓冲区中的内容被覆盖, 也保留有当前的执行语句save命令的语法如下: Save [file] file_name[replace|create|append] 其中,file_name表示将SQL*PLUS缓冲区的内容保存到有file_name指定的文件中,create表示创 建一个file_name文件,并将缓冲区中的内容保存到该文件中,该选项为默认值.Replace表示如 果file_name已经存在,则覆盖file_na

Save your cat Aizu - 2224

Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. One day, an evil witch visited the village. She envied the cats for being loved by ev

npm --save 选项作用

学习了:https://segmentfault.com/q/1010000000403629 -save和save-dev可以省掉你手动修改package.json文件的步骤. spm install module-name -save 自动把模块和版本号添加到dependencies部分 spm install module-name -save-dve 自动把模块和版本号添加到devdependencies部分 看了api,感觉好像不太用了: -P, --save-prod: Packag

redis中save和bgsave区别

转自:redis中save和bgsave区别 SAVE 和 BGSAVE 两个命令都会调用 rdbSave 函数,但它们调用的方式各有不同: SAVE 直接调用 rdbSave ,阻塞 Redis 主进程,直到保存完成为止.在主进程阻塞期间,服务器不能处理客户端的任何请求. BGSAVE 则 fork 出一个子进程,子进程负责调用 rdbSave ,并在保存完成之后向主进程发送信号,通知保存已完成. Redis 服务器在BGSAVE 执行期间仍然可以继续处理客户端的请求.

npm install --save 与 npm install --save-dev 的区别

[npm install --save 与 npm install --save-dev 的区别] 以npm安装msbuild为例: npm install msbuild: 会把msbuild包安装到node_modules目录中 不会修改package.json 之后运行npm install命令时,不会自动安装msbuild npm install --save: 会把msbuild包安装到node_modules目录中 会在package.json的dependencies属性下添加ms

hibernate中save()、update()、saveOrUpdate()的区别

save()方法很显然是执行保存操作的,如果是对一个新的刚new出来的对象进行保存,自然要使用这个方法了,数据库中没有这个对象. update()如果是对一个已经存在的托管对象进行更新那么肯定是要使用update()方法了,数据中有这个对象. saveOrUpdate()这个方法是更新或者插入,有主键就执行更新,如果没有主键就执行插入. 区别:对于一个从托管状态到瞬态的对象(对于一个从数据库中取出来又被删除的对象),这个对象本身是有主键的,但是因为被删除了,所以这个时候因为数据库中已经没有了这条

SP2-0110: Cannot create save file &quot;afiedt.buf&quot;

sp2-0110:无法创建保存文件"afiedt.buf" 出处:此问题是由于使用 define _editor=vim 时,用ed更改时报错 问题原因:Cannot create save file "afiedt.buf" 因为在执行 edit的时候 "afiedt.buf" 文件默认保存在你键入sqlplus命令时所在目录中 比如:你在 / 目录下进入sqlplus, 当你用edit时,"afiedt.buf"文件就会保