From b5a8f3d19619135e8c6237ee0e1b3fa601aa45cb Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Wed, 1 Jan 2020 21:30:28 +0100 Subject: [PATCH] do not load settings from json file - set depth units via sensor.set_option instead - also notify user what range/precision the depth units result in --- high_accuracy.json | 94 ---------------------------------------------- main.cpp | 68 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 129 deletions(-) delete mode 100644 high_accuracy.json diff --git a/high_accuracy.json b/high_accuracy.json deleted file mode 100644 index 74ee83d..0000000 --- a/high_accuracy.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "aux-param-autoexposure-setpoint": "1536", - "aux-param-colorcorrection1": "0.298828", - "aux-param-colorcorrection10": "0", - "aux-param-colorcorrection11": "0", - "aux-param-colorcorrection12": "0", - "aux-param-colorcorrection2": "0.293945", - "aux-param-colorcorrection3": "0.293945", - "aux-param-colorcorrection4": "0.114258", - "aux-param-colorcorrection5": "0", - "aux-param-colorcorrection6": "0", - "aux-param-colorcorrection7": "0", - "aux-param-colorcorrection8": "0", - "aux-param-colorcorrection9": "0", - "aux-param-depthclampmax": "65536", - "aux-param-depthclampmin": "0", - "aux-param-disparityshift": "0", - "controls-autoexposure-auto": "True", - "controls-autoexposure-manual": "8500", - "controls-color-autoexposure-auto": "True", - "controls-color-autoexposure-manual": "166", - "controls-color-backlight-compensation": "0", - "controls-color-brightness": "0", - "controls-color-contrast": "50", - "controls-color-gain": "64", - "controls-color-gamma": "300", - "controls-color-hue": "0", - "controls-color-power-line-frequency": "3", - "controls-color-saturation": "64", - "controls-color-sharpness": "50", - "controls-color-white-balance-auto": "True", - "controls-color-white-balance-manual": "4600", - "controls-depth-gain": "16", - "controls-laserpower": "150", - "controls-laserstate": "on", - "ignoreSAD": "0", - "param-autoexposure-setpoint": "1536", - "param-censusenablereg-udiameter": "9", - "param-censusenablereg-vdiameter": "9", - "param-censususize": "9", - "param-censusvsize": "9", - "param-depthclampmax": "65536", - "param-depthclampmin": "0", - "param-depthunits": "100", - "param-disableraucolor": "0", - "param-disablesadcolor": "0", - "param-disablesadnormalize": "0", - "param-disablesloleftcolor": "0", - "param-disableslorightcolor": "1", - "param-disparitymode": "0", - "param-disparityshift": "0", - "param-lambdaad": "751", - "param-lambdacensus": "6", - "param-leftrightthreshold": "10", - "param-maxscorethreshb": "2893", - "param-medianthreshold": "796", - "param-minscorethresha": "4", - "param-neighborthresh": "108", - "param-raumine": "6", - "param-rauminn": "3", - "param-rauminnssum": "7", - "param-raumins": "2", - "param-rauminw": "2", - "param-rauminwesum": "12", - "param-regioncolorthresholdb": "0.785714", - "param-regioncolorthresholdg": "0.565558", - "param-regioncolorthresholdr": "0.985323", - "param-regionshrinku": "3", - "param-regionshrinkv": "0", - "param-robbinsmonrodecrement": "25", - "param-robbinsmonroincrement": "2", - "param-rsmdiffthreshold": "1.65625", - "param-rsmrauslodiffthreshold": "0.71875", - "param-rsmremovethreshold": "0.809524", - "param-scanlineedgetaub": "13", - "param-scanlineedgetaug": "15", - "param-scanlineedgetaur": "30", - "param-scanlinep1": "155", - "param-scanlinep1onediscon": "160", - "param-scanlinep1twodiscon": "59", - "param-scanlinep2": "190", - "param-scanlinep2onediscon": "507", - "param-scanlinep2twodiscon": "493", - "param-secondpeakdelta": "647", - "param-texturecountthresh": "0", - "param-texturedifferencethresh": "1722", - "param-usersm": "1", - "param-zunits": "100", - "stream-depth-format": "Z16", - "stream-fps": "30", - "stream-height": "480", - "stream-ir-format": "Y8", - "stream-width": "848" -} \ No newline at end of file diff --git a/main.cpp b/main.cpp index e37c165..4f7ffbf 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,7 @@ /* - * 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 + * Copyright 2019-2020 (C) Bartosz Meglicki * * 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 @@ -9,7 +9,7 @@ * */ -/* 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 @@ -25,13 +25,6 @@ // Realsense API #include -//loading json settings -#include -//#include -//#include -//#include -//end of json settings - #include #include using namespace std; @@ -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[]) @@ -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(); - 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(t)), std::istreambuf_iterator()); - 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] << " [device]" << endl; + cerr << "Usage: " << argv[0] << " [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; }