Skip to content

Commit

Permalink
realsense-viewer with OpenVINO face detection
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Mar 11, 2020
1 parent 7f2474d commit 0ad230b
Show file tree
Hide file tree
Showing 17 changed files with 1,097 additions and 134 deletions.
106 changes: 81 additions & 25 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "fw-update-helper.h"
#include "on-chip-calib.h"
#include "viewer.h"
#include "post-processing-filters-list.h"
#include "post-processing-block-model.h"
#include <imgui_internal.h>
#include <time.h>

Expand Down Expand Up @@ -856,7 +858,7 @@ namespace rs2
std::shared_ptr<rs2::filter> block,
std::function<rs2::frame(rs2::frame)> invoker,
std::string& error_message, bool enable)
: _owner(owner), _name(name), _block(block), _invoker(invoker), enabled(enable)
: _owner(owner), _name(name), _block(block), _invoker(invoker), _enabled(enable)
{
std::stringstream ss;
ss << "##" << ((owner) ? owner->dev.get_info(RS2_CAMERA_INFO_NAME) : _name)
Expand All @@ -868,15 +870,15 @@ namespace rs2
else
_full_name = _name;

enabled = restore_processing_block(_full_name.c_str(),
block, enabled);
_enabled = restore_processing_block(_full_name.c_str(),
block, _enabled);

populate_options(ss.str().c_str(), owner, owner ? &owner->_options_invalidated : nullptr, error_message);
}

void processing_block_model::save_to_config_file()
{
save_processing_block_to_config_file(_full_name.c_str(), _block, enabled);
save_processing_block_to_config_file(_full_name.c_str(), _block, _enabled);
}

option_model& processing_block_model::get_option(rs2_option opt)
Expand All @@ -902,24 +904,34 @@ namespace rs2

subdevice_model::subdevice_model(
device& dev,
std::shared_ptr<sensor> s, std::string& error_message, viewer_model& viewer)
: s(s), dev(dev), tm2(), ui(), last_valid_ui(),
std::shared_ptr<sensor> s,
std::shared_ptr< atomic_objects_in_frame > device_detected_objects,
std::string& error_message,
viewer_model& viewer
)
: s( s ), dev( dev ), tm2(), ui(), last_valid_ui(),
streaming(false), _pause(false),
depth_colorizer(std::make_shared<rs2::gl::colorizer>()),
yuy2rgb(std::make_shared<rs2::gl::yuy_decoder>()),
depth_decoder(std::make_shared<rs2::depth_huffman_decoder>()),
viewer(viewer)
viewer(viewer),
detected_objects( device_detected_objects )
{
supported_options = s->get_supported_options();
restore_processing_block("colorizer", depth_colorizer);
restore_processing_block("yuy2rgb", yuy2rgb);

std::string device_name( dev.get_info( RS2_CAMERA_INFO_NAME ));
std::string sensor_name( s->get_info( RS2_CAMERA_INFO_NAME ));

std::stringstream ss;
ss << configurations::viewer::post_processing
<< "." << dev.get_info(RS2_CAMERA_INFO_NAME)
<< "." << s->get_info(RS2_CAMERA_INFO_NAME);
<< "." << device_name
<< "." << sensor_name;
auto key = ss.str();

bool const is_rgb_camera = s->is< color_sensor >();

if (config_file::instance().contains(key.c_str()))
{
post_processing_enabled = config_file::instance().get(key.c_str());
Expand Down Expand Up @@ -978,22 +990,39 @@ namespace rs2
viewer.zo_sensors++;
}
else
model->enabled = false;
model->enable( false );
}

if (shared_filter->is<hole_filling_filter>())
model->enabled = false;
model->enable( false );

if (shared_filter->is<decimation_filter>())
{
std::string sn_name(s->get_info(RS2_CAMERA_INFO_NAME));
if (sn_name == "RGB Camera")
model->enabled = false;
if( is_rgb_camera )
model->enable( false );
}

post_processing.push_back(model);
}

if( is_rgb_camera )
{
for( auto & create_filter : post_processing_filters_list::get() )
{
auto filter = create_filter();
if( !filter )
continue;
filter->start( *this );
std::shared_ptr< processing_block_model > model(
new post_processing_block_model {
this, filter,
[=]( rs2::frame f ) { return filter->process( f ); },
error_message
} );
post_processing.push_back( model );
}
}

auto colorizer = std::make_shared<processing_block_model>(
this, "Depth Visualization", depth_colorizer,
[=](rs2::frame f) { return depth_colorizer->colorize(f); }, error_message);
Expand Down Expand Up @@ -1753,6 +1782,13 @@ namespace rs2

streaming = false;
_pause = false;

if( profiles[0].stream_type() == RS2_STREAM_COLOR )
{
std::lock_guard< std::mutex > lock( detected_objects->mutex );
detected_objects->clear();
detected_objects->sensor_is_on = false;
}

s->stop();

Expand Down Expand Up @@ -1799,7 +1835,7 @@ namespace rs2
//The function decides if specific frame should be sent to the syncer
bool subdevice_model::is_synchronized_frame(viewer_model& viewer, const frame& f)
{
if(zero_order_artifact_fix && zero_order_artifact_fix->enabled &&
if(zero_order_artifact_fix && zero_order_artifact_fix->is_enabled() &&
(f.get_profile().stream_type() == RS2_STREAM_DEPTH || f.get_profile().stream_type() == RS2_STREAM_INFRARED || f.get_profile().stream_type() == RS2_STREAM_CONFIDENCE))
return true;
if (!viewer.is_3d_view || viewer.is_3d_depth_source(f) || viewer.is_3d_texture_source(f))
Expand All @@ -1810,7 +1846,7 @@ namespace rs2

void subdevice_model::play(const std::vector<stream_profile>& profiles, viewer_model& viewer, std::shared_ptr<rs2::asynchronous_syncer> syncer)
{
if (post_processing_enabled && zero_order_artifact_fix && zero_order_artifact_fix->enabled)
if (post_processing_enabled && zero_order_artifact_fix && zero_order_artifact_fix->is_enabled())
{
verify_zero_order_conditions();
}
Expand Down Expand Up @@ -1861,6 +1897,11 @@ namespace rs2

_options_invalidated = true;
streaming = true;
if( s->is< color_sensor >() )
{
std::lock_guard< std::mutex > lock( detected_objects->mutex );
detected_objects->sensor_is_on = true;
}
}
void subdevice_model::update(std::string& error_message, notifications_model& notifications)
{
Expand Down Expand Up @@ -3334,13 +3375,14 @@ namespace rs2
: dev(dev),
syncer(viewer.syncer),
_update_readonly_options_timer(std::chrono::seconds(6))
, _detected_objects( std::make_shared< atomic_objects_in_frame >() )
{
auto name = get_device_name(dev);
id = to_string() << name.first << ", " << name.second;

for (auto&& sub : dev.query_sensors())
{
auto model = std::make_shared<subdevice_model>(dev, std::make_shared<sensor>(sub), error_message, viewer);
auto model = std::make_shared<subdevice_model>(dev, std::make_shared<sensor>(sub), _detected_objects, error_message, viewer);
subdevices.push_back(model);
}

Expand Down Expand Up @@ -3445,7 +3487,7 @@ namespace rs2
continue;

for(auto&& pp : sub->post_processing)
if (pp->enabled)
if (pp->is_enabled())
res = pp->invoke(res);
}

Expand Down Expand Up @@ -3768,7 +3810,7 @@ namespace rs2
fps = s.second.profile.fps();
}
auto curr_frame = p.get_position();
uint64_t step = 1000.0 / (float)fps * 1e6;
uint64_t step = uint64_t( 1000.0 / (float)fps * 1e6 );
p.seek(std::chrono::nanoseconds(curr_frame - step));
}
if (ImGui::IsItemHovered())
Expand Down Expand Up @@ -3868,7 +3910,7 @@ namespace rs2
fps = s.second.profile.fps();
}
auto curr_frame = p.get_position();
uint64_t step = 1000.0 / (float)fps * 1e6;
uint64_t step = uint64_t( 1000.0 / (float)fps * 1e6 );
p.seek(std::chrono::nanoseconds(curr_frame + step));
}
if (ImGui::IsItemHovered())
Expand Down Expand Up @@ -5780,11 +5822,18 @@ namespace rs2

if (ImGui::Button(label.c_str(), { 30,24 }))
{
if (sub->zero_order_artifact_fix && sub->zero_order_artifact_fix->enabled)
if (sub->zero_order_artifact_fix && sub->zero_order_artifact_fix->is_enabled())
sub->verify_zero_order_conditions();
sub->post_processing_enabled = true;
config_file::instance().set(get_device_sensor_name(sub.get()).c_str(),
sub->post_processing_enabled);
for( auto&& pb : sub->post_processing )
{
if( !pb->visible )
continue;
if( pb->is_enabled() )
pb->processing_block_enable_disable( true );
}
}
if (ImGui::IsItemHovered())
{
Expand All @@ -5803,6 +5852,13 @@ namespace rs2
sub->post_processing_enabled = false;
config_file::instance().set(get_device_sensor_name(sub.get()).c_str(),
sub->post_processing_enabled);
for( auto&& pb : sub->post_processing )
{
if( !pb->visible )
continue;
if( pb->is_enabled() )
pb->processing_block_enable_disable( false );
}
}
if (ImGui::IsItemHovered())
{
Expand Down Expand Up @@ -5848,7 +5904,7 @@ namespace rs2

if (!sub->post_processing_enabled)
{
if (!pb->enabled)
if (!pb->is_enabled())
{
std::string label = to_string() << " " << textual_icons::toggle_off << "##" << id << "," << sub->s->get_info(RS2_CAMERA_INFO_NAME) << "," << pb->get_name();

Expand All @@ -5866,7 +5922,7 @@ namespace rs2
}
else
{
if (!pb->enabled)
if (!pb->is_enabled())
{
std::string label = to_string() << " " << textual_icons::toggle_off << "##" << id << "," << sub->s->get_info(RS2_CAMERA_INFO_NAME) << "," << pb->get_name();

Expand All @@ -5877,7 +5933,7 @@ namespace rs2
{
if (pb->get_block()->is<zero_order_invalidation>())
sub->verify_zero_order_conditions();
pb->enabled = true;
pb->enable( true );
pb->save_to_config_file();
}
if (ImGui::IsItemHovered())
Expand All @@ -5895,7 +5951,7 @@ namespace rs2

if (ImGui::Button(label.c_str(), { 25,24 }))
{
pb->enabled = false;
pb->enable( false );
pb->save_to_config_file();
}
if (ImGui::IsItemHovered())
Expand Down
50 changes: 8 additions & 42 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "imgui-fonts-karla.hpp"
#include "imgui-fonts-fontawesome.hpp"
#include "../third-party/json.hpp"
#include "objects-in-frame.h"
#include "processing-block-model.h"

#include "realsense-ui-advanced-mode.h"
#include "fw-update-helper.h"
Expand Down Expand Up @@ -379,47 +381,6 @@ namespace rs2
void save_processing_block_to_config_file(const char* name,
std::shared_ptr<rs2::processing_block> pb, bool enable = true);

class processing_block_model
{
public:
processing_block_model(subdevice_model* owner,
const std::string& name,
std::shared_ptr<rs2::filter> block,
std::function<rs2::frame(rs2::frame)> invoker,
std::string& error_message,
bool enabled = true);

const std::string& get_name() const { return _name; }

option_model& get_option(rs2_option opt);

rs2::frame invoke(rs2::frame f) const { return _invoker(f); }

void save_to_config_file();

std::vector<rs2_option> get_option_list()
{
return _block->get_supported_options();
}

void populate_options(const std::string& opt_base_label,
subdevice_model* model,
bool* options_invalidated,
std::string& error_message);

std::shared_ptr<rs2::filter> get_block() { return _block; }

bool enabled = true;
bool visible = true;
private:
std::shared_ptr<rs2::filter> _block;
std::map<int, option_model> options_metadata;
std::string _name;
std::string _full_name;
std::function<rs2::frame(rs2::frame)> _invoker;
subdevice_model* _owner;
};

class syncer_model
{
public:
Expand Down Expand Up @@ -597,7 +558,7 @@ namespace rs2
bool* options_invalidated,
std::string& error_message);

subdevice_model(device& dev, std::shared_ptr<sensor> s, std::string& error_message, viewer_model& viewer);
subdevice_model(device& dev, std::shared_ptr<sensor> s, std::shared_ptr< atomic_objects_in_frame > objects, std::string& error_message, viewer_model& viewer);
~subdevice_model();

bool is_there_common_fps() ;
Expand Down Expand Up @@ -665,6 +626,7 @@ namespace rs2
std::shared_ptr<sensor> s;
device dev;
tm2_model tm2;
std::shared_ptr< atomic_objects_in_frame > detected_objects;

std::map<int, option_model> options_metadata;
std::vector<std::string> resolutions;
Expand Down Expand Up @@ -725,6 +687,7 @@ 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 @@ -815,6 +778,8 @@ namespace rs2
viewer_model& viewer, std::string& error_message);
void begin_update_unsigned(viewer_model& viewer, std::string& error_message);

std::shared_ptr< atomic_objects_in_frame > get_detected_objects() const { return _detected_objects; }

std::vector<std::shared_ptr<subdevice_model>> subdevices;
std::shared_ptr<syncer_model> syncer;
std::shared_ptr<rs2::asynchronous_syncer> dev_syncer;
Expand Down Expand Up @@ -868,6 +833,7 @@ namespace rs2
std::vector<std::shared_ptr<subdevice_model>> live_subdevices;
periodic_timer _update_readonly_options_timer;
bool pause_required = false;
std::shared_ptr< atomic_objects_in_frame > _detected_objects;
};

class viewer_model;
Expand Down
Loading

0 comments on commit 0ad230b

Please sign in to comment.