Skip to content

Commit

Permalink
Merge pull request #752 from garaemon/overwrite-alpha
Browse files Browse the repository at this point in the history
[jsk_rviz_plugins/OverlayImage] Add property to ignore alpha channel of the image
  • Loading branch information
k-okada authored Dec 11, 2019
2 parents f7e874b + f2e9897 commit 93cd6b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 17 additions & 3 deletions jsk_rviz_plugins/src/overlay_image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace jsk_rviz_plugins

OverlayImageDisplay::OverlayImageDisplay()
: Display(), width_(128), height_(128), left_(128), top_(128), alpha_(0.8),
is_msg_available_(false), require_update_(false)
is_msg_available_(false), require_update_(false), overwrite_alpha_(false)
{
// setup properties
update_topic_property_ = new rviz::RosTopicProperty(
Expand Down Expand Up @@ -79,13 +79,18 @@ namespace jsk_rviz_plugins
alpha_property_ = new rviz::FloatProperty("alpha", 0.8,
"alpha belnding value",
this, SLOT(updateAlpha()));
overwrite_alpha_property_ = new rviz::BoolProperty("overwrite alpha value", false,
"overwrite alpha value by alpha property "
"and ignore alpha channel of the image",
this, SLOT(updateOverwriteAlpha()));
}

OverlayImageDisplay::~OverlayImageDisplay()
{
delete update_topic_property_;
delete transport_hint_property_;
delete keep_aspect_ratio_property_;
delete overwrite_alpha_property_;
delete width_property_;
delete height_property_;
delete left_property_;
Expand All @@ -105,6 +110,7 @@ namespace jsk_rviz_plugins
updateWidth();
updateHeight();
updateKeepAspectRatio();
updateOverwriteAlpha();
updateTop();
updateLeft();
updateAlpha();
Expand Down Expand Up @@ -202,8 +208,9 @@ namespace jsk_rviz_plugins
else {
cv::Mat mat; // mat should be BGRA8 image

if (msg_->encoding == sensor_msgs::image_encodings::BGRA8 ||
msg_->encoding == sensor_msgs::image_encodings::RGBA8) {
if ((msg_->encoding == sensor_msgs::image_encodings::BGRA8 ||
msg_->encoding == sensor_msgs::image_encodings::RGBA8) &&
!overwrite_alpha_) {
const cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(
msg_, sensor_msgs::image_encodings::BGRA8);
cv_ptr->image.copyTo(mat);
Expand Down Expand Up @@ -309,6 +316,13 @@ namespace jsk_rviz_plugins
require_update_ = true;
}

void OverlayImageDisplay::updateOverwriteAlpha()
{
boost::mutex::scoped_lock lock(mutex_);
overwrite_alpha_ = overwrite_alpha_property_->getBool();
require_update_ = true;
}

bool OverlayImageDisplay::isInRegion(int x, int y)
{
return (top_ < y && top_ + height_ > y &&
Expand Down
6 changes: 4 additions & 2 deletions jsk_rviz_plugins/src/overlay_image_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace jsk_rviz_plugins
virtual void setPosition(int x, int y);
virtual int getX() { return left_; };
virtual int getY() { return top_; };

protected:
boost::mutex mutex_;
OverlayObject::Ptr overlay_;
Expand All @@ -83,6 +83,7 @@ namespace jsk_rviz_plugins
rviz::IntProperty* left_property_;
rviz::IntProperty* top_property_;
rviz::FloatProperty* alpha_property_;
rviz::BoolProperty* overwrite_alpha_property_;
int width_, height_, left_, top_;
double alpha_;
#if ROS_VERSION_MINIMUM(1,12,0)
Expand All @@ -95,6 +96,7 @@ namespace jsk_rviz_plugins
bool is_msg_available_;
bool require_update_;
bool keep_aspect_ratio_;
bool overwrite_alpha_;

virtual void redraw();
virtual void onInitialize();
Expand All @@ -113,9 +115,9 @@ namespace jsk_rviz_plugins
void updateTop();
void updateAlpha();
void updateKeepAspectRatio();
void updateOverwriteAlpha();
};

}

#endif

0 comments on commit 93cd6b0

Please sign in to comment.