Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Support for all color camera parameters in k4arecorder #1757

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tools/k4arecorder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<char *> &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<char *> &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<char *> &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<char *> &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<char *> &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,
Expand Down Expand Up @@ -433,5 +499,10 @@ int main(int argc, char **argv)
&device_config,
recording_imu_enabled,
absoluteExposureValue,
whiteBalance,
brightness,
contrast,
saturation,
sharpness,
gain);
}
78 changes: 49 additions & 29 deletions tools/k4arecorder/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,49 @@ 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 " << 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,
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);
Expand Down Expand Up @@ -96,35 +133,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, "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);
if (record_imu)
Expand Down
10 changes: 10 additions & 0 deletions tools/k4arecorder/recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 */