From 982b4adaefce91ec5bde979f1d4368917dcadbb8 Mon Sep 17 00:00:00 2001 From: "Bojan Rosko (MRAI)" Date: Mon, 5 Jul 2021 11:52:53 +0200 Subject: [PATCH 1/3] Added more color options --- tools/k4arecorder/main.cpp | 71 ++++++++++++++++++++++++++++++ tools/k4arecorder/recorder.cpp | 79 +++++++++++++++++++++------------- tools/k4arecorder/recorder.h | 10 +++++ 3 files changed, 131 insertions(+), 29 deletions(-) diff --git a/tools/k4arecorder/main.cpp b/tools/k4arecorder/main.cpp index 9bcb83d4b..a15849882 100644 --- a/tools/k4arecorder/main.cpp +++ b/tools/k4arecorder/main.cpp @@ -123,6 +123,11 @@ int main(int argc, char **argv) int32_t depth_delay_off_color_usec = 0; uint32_t subordinate_delay_off_master_usec = 0; int absoluteExposureValue = defaultExposureAuto; + int whiteBalance = defaultWhiteBalance; + int brightness = defaultBrightness; + int contrast = defaultContrast; + int saturation = defaultSaturation; + int sharpness = defaultSharpness; int gain = defaultGainAuto; char *recording_filename; @@ -346,6 +351,67 @@ int main(int argc, char **argv) throw std::runtime_error("Exposure value range is 2 to 5s, or -11 to 1."); } }); + cmd_parser.RegisterOption("-w|--white-balance", + "Set manual white balance from 2500K to 12500K for the RGB camera (default: \n" + "auto white balance). The value has to be divisible by 10.", + 1, + [&](const std::vector &args) { + int whiteBalanceSetting = std::stoi(args[0]); + if (whiteBalanceSetting < 2500 || whiteBalanceSetting > 12500 || + whiteBalanceSetting % 10 != 0) + { + throw std::runtime_error("White balance setting has invalid value."); + } + whiteBalance = whiteBalanceSetting; + }); + cmd_parser.RegisterOption("--brightness", + "Set brightness from 0 to 255 for the RGB camera (default: \n" + "previously set value, non deterministic).", + 1, + [&](const std::vector &args) { + int brightnessSetting = std::stoi(args[0]); + if (brightnessSetting < 0 || brightnessSetting > 255) + { + throw std::runtime_error("Brightness setting has invalid value."); + } + brightness = brightnessSetting; + }); + cmd_parser.RegisterOption("--contrast", + "Set contrast from 0 to 10 for the RGB camera (default: \n" + "previously set value, non deterministic).", + 1, + [&](const std::vector &args) { + int contrastSetting = std::stoi(args[0]); + if (contrastSetting < 0 || contrastSetting > 10) + { + throw std::runtime_error("Contrast setting has invalid value."); + } + contrast = contrastSetting; + }); + cmd_parser.RegisterOption("--saturation", + "Set saturation from 0 to 63 for the RGB camera (default: \n" + "previously set value, non deterministic).", + 1, + [&](const std::vector &args) { + int saturationSetting = std::stoi(args[0]); + if (saturationSetting < 0 || saturationSetting > 63) + { + throw std::runtime_error("Saturation setting has invalid value."); + } + saturation = saturationSetting; + }); + cmd_parser.RegisterOption("--sharpness", + "Set sharpness from 0 to 4 for the RGB camera (default: \n" + "previously set value, non deterministic).", + 1, + [&](const std::vector &args) { + int sharpnessSetting = std::stoi(args[0]); + if (sharpnessSetting < 0 || sharpnessSetting > 4) + { + throw std::runtime_error("Sharpness setting has invalid value."); + } + sharpness = sharpnessSetting; + }); cmd_parser.RegisterOption("-g|--gain", "Set cameras manual gain. The valid range is 0 to 255. (default: auto)", 1, @@ -433,5 +499,10 @@ int main(int argc, char **argv) &device_config, recording_imu_enabled, absoluteExposureValue, + whiteBalance, + brightness, + contrast, + saturation, + sharpness, gain); } diff --git a/tools/k4arecorder/recorder.cpp b/tools/k4arecorder/recorder.cpp index 163f620df..6eb2bcf5e 100644 --- a/tools/k4arecorder/recorder.cpp +++ b/tools/k4arecorder/recorder.cpp @@ -48,12 +48,50 @@ inline static uint32_t k4a_convert_fps_to_uint(k4a_fps_t fps) std::atomic_bool exiting(false); +void set_color_param(k4a_device_t &device, + k4a_color_control_command_t command, + const char *command_name, + int32_t value, + int32_t defaultValue, + bool defaultAuto) +{ + k4a_color_control_mode_t read_mode; + int32_t read_value; + + if (value != defaultValue) + { + if (K4A_FAILED(k4a_device_set_color_control(device, command, + K4A_COLOR_CONTROL_MODE_MANUAL, value))) + { + std::cerr << "Runtime error: k4a_device_set_color_control() failed for manual " << command_name << std::endl; + } + } + else if (defaultAuto) + { + if (K4A_FAILED(k4a_device_set_color_control(device, command, + K4A_COLOR_CONTROL_MODE_AUTO, + 0))) + { + std::cerr << "Runtime error: k4a_device_set_color_control() failed for auto " << command_name << std::endl; + } + } + + k4a_device_get_color_control(device, command, &read_mode, &read_value); + std::cout << "Current " << (read_mode == K4A_COLOR_CONTROL_MODE_AUTO ? "AUTO" : "MANUAL") << command_name << " value: " << read_value + << std::endl; +} + int do_recording(uint8_t device_index, char *recording_filename, int recording_length, k4a_device_configuration_t *device_config, bool record_imu, int32_t absoluteExposureValue, + int32_t whiteBalance, + int32_t brightness, + int32_t contrast, + int32_t saturation, + int32_t sharpness, int32_t gain) { seconds recording_length_seconds(recording_length); @@ -96,35 +134,18 @@ int do_recording(uint8_t device_index, return 1; } - if (absoluteExposureValue != defaultExposureAuto) - { - if (K4A_FAILED(k4a_device_set_color_control(device, - K4A_COLOR_CONTROL_EXPOSURE_TIME_ABSOLUTE, - K4A_COLOR_CONTROL_MODE_MANUAL, - absoluteExposureValue))) - { - std::cerr << "Runtime error: k4a_device_set_color_control() for manual exposure failed " << std::endl; - } - } - else - { - if (K4A_FAILED(k4a_device_set_color_control(device, - K4A_COLOR_CONTROL_EXPOSURE_TIME_ABSOLUTE, - K4A_COLOR_CONTROL_MODE_AUTO, - 0))) - { - std::cerr << "Runtime error: k4a_device_set_color_control() for auto exposure failed " << std::endl; - } - } - - if (gain != defaultGainAuto) - { - if (K4A_FAILED( - k4a_device_set_color_control(device, K4A_COLOR_CONTROL_GAIN, K4A_COLOR_CONTROL_MODE_MANUAL, gain))) - { - std::cerr << "Runtime error: k4a_device_set_color_control() for manual gain failed " << std::endl; - } - } + set_color_param(device, + K4A_COLOR_CONTROL_EXPOSURE_TIME_ABSOLUTE, + "exposure", + absoluteExposureValue, + defaultExposureAuto, + true); + set_color_param(device, K4A_COLOR_CONTROL_WHITEBALANCE, "white balance", whiteBalance, defaultWhiteBalance, true); + set_color_param(device, K4A_COLOR_CONTROL_BRIGHTNESS, "brightness", brightness, defaultBrightness, false); + set_color_param(device, K4A_COLOR_CONTROL_CONTRAST, "contrast", contrast, defaultContrast, false); + set_color_param(device, K4A_COLOR_CONTROL_SATURATION, "saturation", saturation, defaultSaturation, false); + set_color_param(device, K4A_COLOR_CONTROL_SHARPNESS, "brightness", sharpness, defaultSharpness, false); + set_color_param(device, K4A_COLOR_CONTROL_GAIN, "gain", gain, defaultGainAuto, false); CHECK(k4a_device_start_cameras(device, device_config), device); if (record_imu) diff --git a/tools/k4arecorder/recorder.h b/tools/k4arecorder/recorder.h index c9db471d6..2736cde0d 100644 --- a/tools/k4arecorder/recorder.h +++ b/tools/k4arecorder/recorder.h @@ -10,6 +10,11 @@ extern std::atomic_bool exiting; static const int32_t defaultExposureAuto = -12; +static const int32_t defaultWhiteBalance = -1; +static const int32_t defaultBrightness = -1; +static const int32_t defaultContrast = -1; +static const int32_t defaultSaturation = -1; +static const int32_t defaultSharpness = -1; static const int32_t defaultGainAuto = -1; int do_recording(uint8_t device_index, @@ -18,6 +23,11 @@ int do_recording(uint8_t device_index, k4a_device_configuration_t *device_config, bool record_imu, int32_t absoluteExposureValue, + int32_t whiteBalance, + int32_t brightness, + int32_t contrast, + int32_t saturation, + int32_t sharpness, int32_t gain); #endif /* RECORDER_H */ From 6ed5a88ef7c2fd3c8c62f9ad80f77d927c7d3030 Mon Sep 17 00:00:00 2001 From: "Bojan Rosko (MRAI)" Date: Mon, 5 Jul 2021 15:43:35 +0200 Subject: [PATCH 2/3] minor fix --- tools/k4arecorder/recorder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/k4arecorder/recorder.cpp b/tools/k4arecorder/recorder.cpp index 6eb2bcf5e..2a3c8d510 100644 --- a/tools/k4arecorder/recorder.cpp +++ b/tools/k4arecorder/recorder.cpp @@ -77,8 +77,8 @@ void set_color_param(k4a_device_t &device, } k4a_device_get_color_control(device, command, &read_mode, &read_value); - std::cout << "Current " << (read_mode == K4A_COLOR_CONTROL_MODE_AUTO ? "AUTO" : "MANUAL") << command_name << " value: " << read_value - << std::endl; + std::cout << "Current " << command_name << " set to " << (read_mode == K4A_COLOR_CONTROL_MODE_AUTO ? "AUTO" : "MANUAL") << " mode and has value " << read_value + << std::endl; } int do_recording(uint8_t device_index, @@ -144,7 +144,7 @@ int do_recording(uint8_t device_index, set_color_param(device, K4A_COLOR_CONTROL_BRIGHTNESS, "brightness", brightness, defaultBrightness, false); set_color_param(device, K4A_COLOR_CONTROL_CONTRAST, "contrast", contrast, defaultContrast, false); set_color_param(device, K4A_COLOR_CONTROL_SATURATION, "saturation", saturation, defaultSaturation, false); - set_color_param(device, K4A_COLOR_CONTROL_SHARPNESS, "brightness", sharpness, defaultSharpness, false); + set_color_param(device, K4A_COLOR_CONTROL_SHARPNESS, "sharpness", sharpness, defaultSharpness, false); set_color_param(device, K4A_COLOR_CONTROL_GAIN, "gain", gain, defaultGainAuto, false); CHECK(k4a_device_start_cameras(device, device_config), device); From 77c5a40766306df7661835e912344f7c0ce0540b Mon Sep 17 00:00:00 2001 From: Bojan Rosko Date: Thu, 30 Dec 2021 12:12:56 +0100 Subject: [PATCH 3/3] clang format --- tools/k4arecorder/recorder.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/k4arecorder/recorder.cpp b/tools/k4arecorder/recorder.cpp index 2a3c8d510..5c870909f 100644 --- a/tools/k4arecorder/recorder.cpp +++ b/tools/k4arecorder/recorder.cpp @@ -50,7 +50,7 @@ std::atomic_bool exiting(false); void set_color_param(k4a_device_t &device, k4a_color_control_command_t command, - const char *command_name, + const char *command_name, int32_t value, int32_t defaultValue, bool defaultAuto) @@ -60,25 +60,24 @@ void set_color_param(k4a_device_t &device, if (value != defaultValue) { - if (K4A_FAILED(k4a_device_set_color_control(device, command, - K4A_COLOR_CONTROL_MODE_MANUAL, value))) + if (K4A_FAILED(k4a_device_set_color_control(device, command, K4A_COLOR_CONTROL_MODE_MANUAL, value))) { - std::cerr << "Runtime error: k4a_device_set_color_control() failed for manual " << command_name << std::endl; + std::cerr << "Runtime error: k4a_device_set_color_control() failed for manual " << command_name + << std::endl; } } else if (defaultAuto) { - if (K4A_FAILED(k4a_device_set_color_control(device, command, - K4A_COLOR_CONTROL_MODE_AUTO, - 0))) + if (K4A_FAILED(k4a_device_set_color_control(device, command, K4A_COLOR_CONTROL_MODE_AUTO, 0))) { std::cerr << "Runtime error: k4a_device_set_color_control() failed for auto " << command_name << std::endl; } } k4a_device_get_color_control(device, command, &read_mode, &read_value); - std::cout << "Current " << command_name << " set to " << (read_mode == K4A_COLOR_CONTROL_MODE_AUTO ? "AUTO" : "MANUAL") << " mode and has value " << read_value - << std::endl; + std::cout << "Current " << command_name << " set to " + << (read_mode == K4A_COLOR_CONTROL_MODE_AUTO ? "AUTO" : "MANUAL") << " mode and has value " << read_value + << std::endl; } int do_recording(uint8_t device_index,