Skip to content

Commit

Permalink
Dynamic reconfigure of alpha blending
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermogb committed May 8, 2020
1 parent bef3f3c commit ea7d366
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ In another terminal open the dynamic reconfigure and play around with the parame

End the program execution with `Ctrl + C` keyboard shortcut.


### TO DO:
- Display events using a fixed number of them (currently we are displaying the events as arranged in messages)
- Display events using a fixed time interval
- Allow interaction, to change the number of events or the size of the time slice
- Add visualization of time surfaces
6 changes: 6 additions & 0 deletions cfg/dvs_displayer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ gen = ParameterGenerator()
gen.add("Event_colormap", int_t, 0,
"An Integer parameter", 0, 0, 12)

gen.add("Blending", bool_t, 0,
"Blend image? (True) or replace pixels (False)", True)

gen.add("Blend_alpha", double_t, 0,
"Blending factor. 0 -> show only events; 1 -> show only frame (if available)", 0.5, 0, 1)


exit(gen.generate(PACKAGE, "displayer_node", "dvs_displayer"))
2 changes: 2 additions & 0 deletions include/dvs_displayer/displayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Displayer {
dynamic_reconfigure::Server<dvs_displayer::dvs_displayerConfig>::CallbackType dynamic_reconfigure_callback_;

int event_colormap_idx_;
bool blend_enabled_;
double blend_alpha_;
};

} // namespace
25 changes: 22 additions & 3 deletions src/displayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,26 @@ void Displayer::eventsCallback(const dvs_msgs::EventArray::ConstPtr& msg)
cv::LUT(gray_image3ch, cmap_, cm_img);
}

// alpha-blending
const double alpha = 0.5;
cv::addWeighted( cv_image.image, alpha, cm_img, 1.-alpha, 0., cv_image.image);
// Fusion mode: blending or masking (pixel replacement)?
if (blend_enabled_)
{
// alpha-blending
cv::addWeighted( cv_image.image, blend_alpha_, cm_img, 1.-blend_alpha_, 0., cv_image.image);
}
else
{
// Pixel replacement
for (int ir=0; ir < cv_image.image.rows; ir++)
{
for (int ic=0; ic < cv_image.image.cols; ic++)
{
if(gray_image.at<uint8_t>(ir,ic) != 128)
{
cv_image.image.at<cv::Vec3b>(ir,ic) = cm_img.at<cv::Vec3b>(ir,ic);
}
}
}
}

}
else
Expand All @@ -190,6 +207,8 @@ void Displayer::seismic_cmap(cv::Mat& lut)
void Displayer::reconfigureCallback(dvs_displayer::dvs_displayerConfig &config, uint32_t level)
{
event_colormap_idx_ = config.Event_colormap;
blend_enabled_ = config.Blending;
blend_alpha_ = config.Blend_alpha;
}

} // namespace

0 comments on commit ea7d366

Please sign in to comment.