Skip to content

Commit

Permalink
do not load settings from json file
Browse files Browse the repository at this point in the history
- set depth units via sensor.set_option instead
- also notify user what range/precision the depth units result in
  • Loading branch information
bmegli committed Jan 1, 2020
1 parent a781c17 commit b5a8f3d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 129 deletions.
94 changes: 0 additions & 94 deletions high_accuracy.json

This file was deleted.

68 changes: 33 additions & 35 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* Realsense D400 infrared stream to H.264 with VAAPI encoding
* Realsense D400 depth stream to HEVC Main10 with VAAPI encoding
*
* Copyright 2019 (C) Bartosz Meglicki <[email protected]>
* Copyright 2019-2020 (C) Bartosz Meglicki <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

/* This program is example how to use:
/* TO DO This program is example how to use:
* - VAAPI to hardware encode
* - Realsense D400 greyscale infrared stream
* - to H.264 raw video
Expand All @@ -25,13 +25,6 @@
// Realsense API
#include <librealsense2/rs.hpp>

//loading json settings
#include <librealsense2/rs_advanced_mode.hpp>
//#include <string>
//#include <fstream>
//#include <streambuf>
//end of json settings

#include <fstream>
#include <iostream>
using namespace std;
Expand All @@ -46,13 +39,13 @@ struct input_args
int width;
int height;
int framerate;
float depth_units;
int seconds;
};

bool main_loop(const input_args& input, rs2::pipeline& realsense, hve *avctx, ofstream& out_file);
void dump_frame_info(const rs2::depth_frame &frame);
void init_realsense(rs2::pipeline& pipe, const input_args& input);
void load_camera_json(const rs2::pipeline_profile &profile, const char *filename);
int process_user_input(int argc, char* argv[], input_args* input, hve_config *config);

int main(int argc, char* argv[])
Expand Down Expand Up @@ -173,50 +166,55 @@ void dump_frame_info(const rs2::depth_frame &f)
void init_realsense(rs2::pipeline& pipe, const input_args& input)
{
rs2::config cfg;
// depth stream seems to be required for infrared to work
cfg.enable_stream(RS2_STREAM_DEPTH, input.width, input.height, RS2_FORMAT_Z16, input.framerate);
cfg.enable_stream(RS2_STREAM_INFRARED, 1, input.width, input.height, RS2_FORMAT_Y8, input.framerate);

rs2::pipeline_profile profile = pipe.start(cfg);
rs2::depth_sensor depth_sensor = profile.get_device().first<rs2::depth_sensor>();

load_camera_json(profile, "../high_accuracy.json");
}

void load_camera_json(const rs2::pipeline_profile &profile, const char *filename)
{
std::ifstream t(filename);
if(!t)
try
{
std::cerr << "[ERROR]: impossible to open camera config " << filename << std::endl;
exit(1);
depth_sensor.set_option(RS2_OPTION_DEPTH_UNITS, input.depth_units);
}
catch(const exception &)
{
rs2::option_range range = depth_sensor.get_option_range(RS2_OPTION_DEPTH_UNITS);
cerr << "failed to set depth units to " << input.depth_units << " (range is " << range.min << "-" << range.max << ")" << endl;
throw;
}
std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
rs400::advanced_mode dev = profile.get_device();
dev.load_json(str);
}



cout << "Setting realsense depth units to " << input.depth_units << endl;
cout << "This will result in:" << endl;
cout << "-range " << input.depth_units * UINT16_MAX << " m" << endl;
cout << "-precision " << input.depth_units*64.0f << " m (" << input.depth_units*64.0f*1000 << " mm)" << endl;
}

int process_user_input(int argc, char* argv[], input_args* input, hve_config *config)
{
if(argc < 5)
if(argc < 6)
{
cerr << "Usage: " << argv[0] << " <width> <height> <framerate> <seconds> [device]" << endl;
cerr << "Usage: " << argv[0] << " <width> <height> <framerate> <depth units> <seconds> [device]" << endl;
cerr << endl << "examples: " << endl;
cerr << argv[0] << " 640 360 30 5" << endl;
cerr << argv[0] << " 640 360 30 5 /dev/dri/renderD128" << endl;

cerr << argv[0] << " 848 480 30 0.0001 5" << endl;
cerr << argv[0] << " 848 480 30 0.0001 5 /dev/dri/renderD128" << endl;
return -1;
}

config->width = input->width = atoi(argv[1]);
config->height = input->height = atoi(argv[2]);
config->framerate = input->framerate = atoi(argv[3]);
input->depth_units = strtof(argv[4], NULL);
input->seconds = atoi(argv[5]);
config->device = argv[6]; //NULL as last argv argument, or device path


input->seconds = atoi(argv[4]);
cout << "Parsed arguments:" << endl;
cout << "width: " << config->width << endl;
cout << "height: " << config->height << endl;
cout << "framerate: " << config->framerate << endl;
cout << "depth units: " << input->depth_units << endl;
cout << "seconds: " << input->seconds << endl;

config->device = argv[5]; //NULL as last argv argument, or device path
cout << "device: " << (config->device ? config->device : "default") << endl;

return 0;
}

0 comments on commit b5a8f3d

Please sign in to comment.