Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IR Reflectivity report at 15% resolution #7872

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/reflectivity/reflectivity.h"
"${CMAKE_CURRENT_LIST_DIR}/reflectivity/reflectivity.cpp"
)

set(UTILITIES
"${CMAKE_CURRENT_LIST_DIR}/utilities/number/stabilized-value.h"
)
set(COMMON_SRC
${COMMON_SRC}
${SW_UPDATE_FILES}
${REFLECTIVITY_FILES})
${REFLECTIVITY_FILES}
${UTILITIES})

8 changes: 6 additions & 2 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,8 @@ namespace rs2

stream_model::stream_model()
: texture(std::unique_ptr<texture_buffer>(new texture_buffer())),
_stream_not_alive(std::chrono::milliseconds(1500))
_stream_not_alive(std::chrono::milliseconds(1500)),
_stabilized_reflectivity(10, 0.75f)
{
show_map_ruler = config_file::instance().get_or_default(
configurations::viewer::show_map_ruler, true);
Expand Down Expand Up @@ -2355,7 +2356,9 @@ namespace rs2
try
{
auto pixel_ref = _reflectivity->get_reflectivity( noise_est, max_usable_range, ir_val );
ref_str = to_string() << std::dec << round( pixel_ref * 100 ) << "%";
_stabilized_reflectivity.add(pixel_ref);
auto stabilized_pixel_ref = _stabilized_reflectivity.get();
ref_str = to_string() << std::dec << round(stabilized_pixel_ref * 100 ) << "%";
}
catch( ... )
{
Expand Down Expand Up @@ -3170,6 +3173,7 @@ namespace rs2
if (_reflectivity)
{
_reflectivity->reset_history();
_stabilized_reflectivity.reset();
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include "updates-model.h"
#include "calibration-model.h"
#include "cah-model.h"
#include "../common/utilities/time/periodic_timer.h"
#include <utilities/time/periodic_timer.h>
#include "reflectivity/reflectivity.h"
#include <utilities/number/stabilized-value.h>

ImVec4 from_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a, bool consistent_color = false);
ImVec4 operator+(const ImVec4& c, float v);
Expand Down Expand Up @@ -677,7 +678,6 @@ namespace rs2
void outline_rect(const rect& r);
void draw_rect(const rect& r, int line_width = 1);


class stream_model
{
public:
Expand Down Expand Up @@ -735,6 +735,7 @@ namespace rs2

private:
std::unique_ptr< reflectivity > _reflectivity;
utilities::number::stabilized_value<float> _stabilized_reflectivity;

};

Expand Down
14 changes: 14 additions & 0 deletions common/reflectivity/reflectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ float reflectivity::get_reflectivity( float raw_noise_estimation,

ref = ( i_ref * ref_from_ir + s_ref * ref_from_std ) / ( ref_from_ir + ref_from_std );

// Force 15% resolution
if (ref >= 0.85f)
ref = 0.85f;
else if (ref >= 0.7f)
ref = 0.7f;
else if (ref >= 0.55f)
ref = 0.55f;
else if (ref >= 0.4f)
ref = 0.4f;
else if (ref >= 0.25f)
ref = 0.25f;
else
ref = 0.1f;

return ref;
}

Expand Down
103 changes: 103 additions & 0 deletions common/utilities/number/stabilized-value.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#pragma once

#include <string>
#include <atomic>

namespace utilities {
namespace number {

// The stabilized value implement a history based stable value.
// It supply a way to define and get values with a required stabilization.
// When the user adds a value, the value is inserted into the history
// When the user call "get" the last stable value is returned
// Inputs: Template <value_type>
// required history size
// required stabilization percentage
template<typename T> class stabilized_value
{
maloel marked this conversation as resolved.
Show resolved Hide resolved
public:
stabilized_value( size_t history_size, float stabilize_percentage )
maloel marked this conversation as resolved.
Show resolved Hide resolved
: _history_size( history_size )
, _last_stable_value( 0 )
, _stabilize_percentage( stabilize_percentage )
{
if( ( stabilize_percentage <= 0.0f ) || ( stabilize_percentage > 1.0f ) )
throw std::runtime_error( "Illegal value for stabilize_percentage: "
+ std::to_string( stabilize_percentage ) );
}
maloel marked this conversation as resolved.
Show resolved Hide resolved

void add( T val )
{
_recalc_stable_val = true;
maloel marked this conversation as resolved.
Show resolved Hide resolved

if( _values.empty() )
{
_values.push_back( val );
_last_stable_value = val;
return;
maloel marked this conversation as resolved.
Show resolved Hide resolved
}

_values.push_back( val );
if( _values.size() > _history_size )
_values.pop_front();
}

T get()
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
if( _values.empty() )
{
throw std::runtime_error( "No stable value exist, history is empty" );
maloel marked this conversation as resolved.
Show resolved Hide resolved
}

if( _recalc_stable_val )
{
std::unordered_map< T, int > values_count_map;
std::pair< T, int > most_stable_value = { 0, 0 };
for( T val : _values )
{
if( values_count_map.find( val ) != values_count_map.end() )
maloel marked this conversation as resolved.
Show resolved Hide resolved
values_count_map[val]++;
else
values_count_map[val] = 1;

if( most_stable_value.second < values_count_map[val] )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
most_stable_value.first = val;
most_stable_value.second = values_count_map[val];
}
}

auto new_value_percentage
= most_stable_value.second / static_cast< float >( _values.size() );
if( new_value_percentage >= _stabilize_percentage )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
_last_stable_value = most_stable_value.first;
}

_recalc_stable_val = false;
maloel marked this conversation as resolved.
Show resolved Hide resolved
}

return _last_stable_value;
}

void reset()
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
_values.clear();
_last_stable_value = 0.0f;
maloel marked this conversation as resolved.
Show resolved Hide resolved
_recalc_stable_val = false;
}

private:
std::deque< T > _values;
const size_t _history_size;
T _last_stable_value;
const float _stabilize_percentage;
std::atomic_bool _recalc_stable_val = { true };
};


} // namespace value_stabilizer
} // namespace utilities
73 changes: 73 additions & 0 deletions unit-tests/utilities/number/stabilized/test-100-percente.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// License: Apache 2.0. See LICENSE file in root directory.
maloel marked this conversation as resolved.
Show resolved Hide resolved
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

//#cmake:add-file ../../../../common/utilities/number/stabilized-value.h


#include "../../../test.h"
#include "../common/utilities/number/stabilized-value.h"
maloel marked this conversation as resolved.
Show resolved Hide resolved

using namespace utilities::number;

// Test group description:
// * This tests group verifies stabilized_value class.
//
// Current test description:
// * Verify if history is full with a specific value, the stabilized value is always the same
// no matter what percentage is required
TEST_CASE( "stable value sanity - 100%", "[stabilized value]" )
{
try
{
stabilized_value< float > stab_value(5, 1.0f);
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));

CHECK(1.0f == stab_value.get());
}
catch(const std::exception &e)
{
FAIL(" Exception caught: " << e.what());
maloel marked this conversation as resolved.
Show resolved Hide resolved
}
}

TEST_CASE("stable value sanity - 40%", "[stabilized value]")
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
stabilized_value< float > stab_value(5, 0.4f);
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));

CHECK(1.0f == stab_value.get());
maloel marked this conversation as resolved.
Show resolved Hide resolved
}
catch (const std::exception &e)
{
FAIL(" Exception caught: " << e.what());
}
}

TEST_CASE("stable value sanity - 25%", "[stabilized value]")
{
try
{
stabilized_value< float > stab_value(5, 0.25f);
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));
CHECK_NOTHROW(stab_value.add(1.0f));

CHECK(1.0f == stab_value.get());
}
catch (const std::exception &e)
{
FAIL(" Exception caught: " << e.what());
}
}
40 changes: 40 additions & 0 deletions unit-tests/utilities/number/stabilized/test-60-percent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

//#cmake:add-file ../../../../common/utilities/number/stabilized-value.h


#include "../../../test.h"
#include "../common/utilities/number/stabilized-value.h"

using namespace utilities::number;
// Test group description:
// * This tests group verifies stabilized_value class.
//
// Current test description:
// * Verify if history is filled with a stable value at the required percentage , the user
// will get it when asked for even if other inputs exist in history

TEST_CASE( "get 60% stability", "[stabilized value]" )
{
try
{
stabilized_value< float > stab_value( 10, 0.6f );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 55.0f ) );
CHECK_NOTHROW( stab_value.add( 60.0f ) );
CHECK_NOTHROW( stab_value.add( 60.0f ) );
CHECK_NOTHROW( stab_value.add( 60.0f ) );
CHECK_NOTHROW( stab_value.add( 60.0f ) );

CHECK( 55.0f == stab_value.get() );
}
catch( const std::exception & e )
{
FAIL( "Exception caught: " << e.what() );
maloel marked this conversation as resolved.
Show resolved Hide resolved
}
}
54 changes: 54 additions & 0 deletions unit-tests/utilities/number/stabilized/test-illegal-input.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

//#cmake:add-file ../../../../common/utilities/number/stabilized-value.h


#include "../../../test.h"
#include "../common/utilities/number/stabilized-value.h"

using namespace utilities::number;

// Test group description:
// * This tests group verifies stabilized_value class.
//
// Current test description:
// * Verify stabilized_value percentage input is at range (0-100] % (zero not included)
TEST_CASE( "Illegal input - percentage value too high", "[stabilized value]" )
{
try
{
stabilized_value< float > stab_value1( 5, 1.1f );
FAIL( "percentage over 100% must throw" );
}
catch( ... )
{
SUCCEED();
}
}

TEST_CASE( "Illegal input - percentage value too low", "[stabilized value]" )
{
try
{
stabilized_value< float > stab_value3( 5, -1.1f );
FAIL( "negative percentage must throw" );
}
catch( ... )
{
SUCCEED();
}
}

TEST_CASE( "Illegal input - percentage value is zero", "[stabilized value]" )
{
try
{
stabilized_value< float > stab_value( 5, 0.0f );
FAIL( "zero percentage must throw" );
}
catch( ... )
{
SUCCEED();
}
}
Loading