Skip to content

Commit

Permalink
Merge pull request #1411 from icarpis/AE_Step_ctrl
Browse files Browse the repository at this point in the history
Adding Fisheye auto-exposure converge step option
  • Loading branch information
ev-mp authored Mar 22, 2018
2 parents 6b8ba30 + 3ae4ed6 commit 48294a7
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 20 deletions.
10 changes: 10 additions & 0 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,19 @@ namespace rs2
}
else
{
auto step = fmod(range.step, 1);
int pow_val = 10;
while ((step *= 10.f) < 0.f)
{
pow_val *= 10;
}

if (ImGui::SliderFloat(id.c_str(), &value,
range.min, range.max, "%.4f"))
{
value = (value < range.min) ? range.min : value;
value = (value > range.max) ? range.max : value;
value = (int)(value * pow_val) / (float)(pow_val);
model.add_log(to_string() << "Setting " << opt << " to " << value);
endpoint->set_option(opt, value);
res = true;
Expand Down
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef enum rs2_option
RS2_OPTION_FILTER_SMOOTH_DELTA , /**< 2D-filter range/validity threshold*/
RS2_OPTION_HOLES_FILL , /**< Enhance depth data post-processing with holes filling where appropriate*/
RS2_OPTION_STEREO_BASELINE , /**< The distance in mm between the first and the second imagers in stereo-based depth cameras*/
RS2_OPTION_AUTO_EXPOSURE_CONVERGE_STEP , /**< Allows dynamically ajust the converge step value of the target exposure in Auto-Exposure algorithm*/
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_option;
const char* rs2_option_to_string(rs2_option option);
Expand Down
11 changes: 11 additions & 0 deletions src/algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ unsigned auto_exposure_state::get_auto_exposure_antiflicker_rate() const
return rate;
}

float auto_exposure_state::get_auto_exposure_step() const
{
return step;
}

void auto_exposure_state::set_enable_auto_exposure(bool value)
{
is_auto_exposure = value;
Expand All @@ -36,6 +41,10 @@ void auto_exposure_state::set_auto_exposure_antiflicker_rate(unsigned value)
rate = value;
}

void auto_exposure_state::set_auto_exposure_step(float value)
{
step = value;
}

auto_exposure_mechanism::auto_exposure_mechanism(option& gain_option, option& exposure_option, const auto_exposure_state& auto_exposure_state)
: _auto_exposure_algo(auto_exposure_state),
Expand Down Expand Up @@ -156,6 +165,7 @@ void auto_exposure_mechanism::add_frame(frame_holder frame, callback_invocation_
}

auto_exposure_algorithm::auto_exposure_algorithm(const auto_exposure_state& auto_exposure_state)
: exposure_step(ae_step_default_value)
{
update_options(auto_exposure_state);
}
Expand Down Expand Up @@ -274,6 +284,7 @@ void auto_exposure_algorithm::update_options(const auto_exposure_state& options)

state = options;
flicker_cycle = 1000.0f / (state.get_auto_exposure_antiflicker_rate() * 2.0f);
exposure_step = state.get_auto_exposure_step();
}

void auto_exposure_algorithm::update_roi(const region_of_interest& ae_roi)
Expand Down
11 changes: 9 additions & 2 deletions src/algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace librealsense
{
static const float ae_step_default_value = 0.5f;

enum class auto_exposure_modes {
static_auto_exposure = 0,
auto_exposure_anti_flicker,
Expand All @@ -27,16 +29,19 @@ namespace librealsense
auto_exposure_state() :
is_auto_exposure(true),
mode(auto_exposure_modes::auto_exposure_hybrid),
rate(60)
rate(60),
step(ae_step_default_value)
{}

bool get_enable_auto_exposure() const;
auto_exposure_modes get_auto_exposure_mode() const;
unsigned get_auto_exposure_antiflicker_rate() const;
float get_auto_exposure_step() const;

void set_enable_auto_exposure(bool value);
void set_auto_exposure_mode(auto_exposure_modes value);
void set_auto_exposure_antiflicker_rate(unsigned value);
void set_auto_exposure_step(float value);

static const unsigned sample_rate = 1;
static const unsigned skip_frames = 2;
Expand All @@ -45,6 +50,7 @@ namespace librealsense
bool is_auto_exposure;
auto_exposure_modes mode;
unsigned rate;
float step;
};


Expand Down Expand Up @@ -88,7 +94,8 @@ namespace librealsense
float exposure = 10.0f, gain = 2.0f, target_exposure = 0.0f;
uint8_t under_exposure_limit = 5, over_exposure_limit = 250; int under_exposure_noise_limit = 50, over_exposure_noise_limit = 50;
int direction = 0, prev_direction = 0; float hysteresis = 0.075f;// 05;
float eps = 0.01f, exposure_step = 0.1f, minimal_exposure_step = 0.01f;
float eps = 0.01f, minimal_exposure_step = 0.01f;
std::atomic<float> exposure_step;
auto_exposure_state state; float flicker_cycle; bool anti_flicker_mode = true;
region_of_interest roi{};
bool is_roi_initialized = false;
Expand Down
4 changes: 4 additions & 0 deletions src/ds5/ds5-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ namespace librealsense
std::map<float, std::string>{{0.f, "Static"},
{1.f, "Anti-Flicker"},
{2.f, "Hybrid"}}));
uvc_ep->register_option(RS2_OPTION_AUTO_EXPOSURE_CONVERGE_STEP,
std::make_shared<auto_exposure_step_option>(auto_exposure,
ae_state,
option_range{ 0.1f, 1.0f, 0.1f, ae_step_default_value }));
uvc_ep->register_option(RS2_OPTION_POWER_LINE_FREQUENCY,
std::make_shared<auto_exposure_antiflicker_rate_option>(auto_exposure,
ae_state,
Expand Down
23 changes: 23 additions & 0 deletions src/ds5/ds5-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,29 @@ namespace librealsense
}
}

auto_exposure_step_option::auto_exposure_step_option(std::shared_ptr<auto_exposure_mechanism> auto_exposure,
std::shared_ptr<auto_exposure_state> auto_exposure_state,
const option_range& opt_range)
: option_base(opt_range),
_auto_exposure_state(auto_exposure_state),
_auto_exposure(auto_exposure)
{}

void auto_exposure_step_option::set(float value)
{
if (!std::isnormal(_opt_range.step) || ((value < _opt_range.min) || (value > _opt_range.max)))
throw invalid_value_exception(to_string() << "set(auto_exposure_step_option) failed! Given value " << value << " is out of range.");

_auto_exposure_state->set_auto_exposure_step(value);
_auto_exposure->update_auto_exposure_state(*_auto_exposure_state);
_recording_function(*this);
}

float auto_exposure_step_option::query() const
{
return static_cast<float>(_auto_exposure_state->get_auto_exposure_step());
}

auto_exposure_antiflicker_rate_option::auto_exposure_antiflicker_rate_option(std::shared_ptr<auto_exposure_mechanism> auto_exposure,
std::shared_ptr<auto_exposure_state> auto_exposure_state,
const option_range& opt_range,
Expand Down
23 changes: 23 additions & 0 deletions src/ds5/ds5-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ namespace librealsense
std::shared_ptr<auto_exposure_mechanism> _auto_exposure;
};

class auto_exposure_step_option : public option_base
{
public:
auto_exposure_step_option(std::shared_ptr<auto_exposure_mechanism> auto_exposure,
std::shared_ptr<auto_exposure_state> auto_exposure_state,
const option_range& opt_range);

void set(float value) override;

float query() const override;

bool is_enabled() const override { return true; }

const char* get_description() const override
{
return "Auto-Exposure converge step";
}

private:
std::shared_ptr<auto_exposure_state> _auto_exposure_state;
std::shared_ptr<auto_exposure_mechanism> _auto_exposure;
};

class auto_exposure_antiflicker_rate_option : public option_base
{
public:
Expand Down
20 changes: 20 additions & 0 deletions src/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
#include "sensor.h"
#include "error-handling.h"

bool option_base::is_valid(float value) const
{
if (!std::isnormal(_opt_range.step))
throw invalid_value_exception(to_string() << "is_valid(...) failed! step is not properly defined. (" << _opt_range.step << ")");

if ((value < _opt_range.min) || (value > _opt_range.max))
return false;

auto n = (value - _opt_range.min) / _opt_range.step;
return (fabs(fmod(n, 1)) < std::numeric_limits<float>::min());
}

option_range option_base::get_range() const
{
return _opt_range;
}
void option_base::enable_recording(std::function<void(const option&)> recording_action)
{
_recording_function = recording_action;
}

void option::create_snapshot(std::shared_ptr<option>& snapshot) const
{
Expand Down
21 changes: 3 additions & 18 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,11 @@ namespace librealsense
: _opt_range(opt_range)
{}

bool is_valid(float value) const
{
if (!std::isnormal(_opt_range.step))
throw invalid_value_exception(to_string() << "is_valid(...) failed! step is not properly defined. (" << _opt_range.step << ")");

if ((value < _opt_range.min) || (value > _opt_range.max))
return false;
bool is_valid(float value) const;

auto n = (value - _opt_range.min)/_opt_range.step;
return (fabs(fmod(n, 1)) < std::numeric_limits<float>::min());
}
option_range get_range() const override;

option_range get_range() const override
{
return _opt_range;
}
virtual void enable_recording(std::function<void(const option&)> recording_action) override
{
_recording_function = recording_action;
}
virtual void enable_recording(std::function<void(const option&)> recording_action) override;
protected:
const option_range _opt_range;
std::function<void(const option&)> _recording_function = [](const option&) {};
Expand Down
1 change: 1 addition & 0 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ namespace librealsense
CASE(FILTER_SMOOTH_DELTA)
CASE(STEREO_BASELINE)
CASE(HOLES_FILL)
CASE(AUTO_EXPOSURE_CONVERGE_STEP)
default: assert(!is_valid(value)); return UNKNOWN_VALUE;
}
#undef CASE
Expand Down
1 change: 1 addition & 0 deletions wrappers/csharp/Intel.RealSense/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public enum Option
FilterSmoothDelta = 38,
HolesFill = 39,
StereoBaseline = 40,
AutoExposureConvergeStep = 41,
}

public enum Sr300VisualPreset
Expand Down

0 comments on commit 48294a7

Please sign in to comment.