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

Add color scheme for depth images #23

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.8.3)

project(rqt_image_view)

add_compile_options(-std=c++11)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should make the CI build pass for xenial, @dirk-thomas
I hope this is a valid approach, otherwise I'll have to re-implement things w/o C++11 features.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, using C++11 in Kinetic and higher is fine, see REP 3.


# Load catkin and all dependencies required for this package
find_package(catkin REQUIRED COMPONENTS rqt_gui rqt_gui_cpp image_transport sensor_msgs geometry_msgs cv_bridge)

Expand Down
2 changes: 2 additions & 0 deletions include/rqt_image_view/image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class ImageView

protected slots:

virtual void setColorSchemeList();

virtual void updateTopicList();

protected:
Expand Down
39 changes: 38 additions & 1 deletion src/rqt_image_view/image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void ImageView::initPlugin(qt_gui_cpp::PluginContext& context)
}
context.addWidget(widget_);

setColorSchemeList();
ui_.color_scheme_combo_box->setCurrentIndex(ui_.color_scheme_combo_box->findText("Gray"));

updateTopicList();
ui_.topics_combo_box->setCurrentIndex(ui_.topics_combo_box->findText(""));
connect(ui_.topics_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(onTopicChanged(int)));
Expand Down Expand Up @@ -180,6 +183,31 @@ void ImageView::restoreSettings(const qt_gui_cpp::Settings& plugin_settings, con
syncRotateLabel();
}

void ImageView::setColorSchemeList()
{
static const std::map<std::string, int> COLOR_SCHEME_MAP
{
{ "Gray", -1 }, // Special case: no color map
{ "Autumn", cv::COLORMAP_AUTUMN },
{ "Bone", cv::COLORMAP_BONE },
{ "Cool", cv::COLORMAP_COOL },
{ "Hot", cv::COLORMAP_HOT },
{ "Hsv", cv::COLORMAP_HSV },
{ "Jet", cv::COLORMAP_JET },
{ "Ocean", cv::COLORMAP_OCEAN },
{ "Pink", cv::COLORMAP_PINK },
{ "Rainbow", cv::COLORMAP_RAINBOW },
{ "Spring", cv::COLORMAP_SPRING },
{ "Summer", cv::COLORMAP_SUMMER },
{ "Winter", cv::COLORMAP_WINTER }
};

for (const auto& kv : COLOR_SCHEME_MAP)
{
ui_.color_scheme_combo_box->addItem(QString::fromStdString(kv.first), QVariant(kv.second));
}
}

void ImageView::updateTopicList()
{
QSet<QString> message_types;
Expand Down Expand Up @@ -568,7 +596,16 @@ void ImageView::callbackImage(const sensor_msgs::Image::ConstPtr& msg)
}
cv::Mat img_scaled_8u;
cv::Mat(cv_ptr->image-min).convertTo(img_scaled_8u, CV_8UC1, 255. / (max - min));
cv::cvtColor(img_scaled_8u, conversion_mat_, CV_GRAY2RGB);

const auto color_scheme_index = ui_.color_scheme_combo_box->currentIndex();
const auto color_scheme = ui_.color_scheme_combo_box->itemData(color_scheme_index).toInt();
if (color_scheme == -1) {
cv::cvtColor(img_scaled_8u, conversion_mat_, CV_GRAY2RGB);
} else {
cv::Mat img_color_scheme;
cv::applyColorMap(img_scaled_8u, img_color_scheme, color_scheme);
cv::cvtColor(img_color_scheme, conversion_mat_, CV_BGR2RGB);
}
} else {
qWarning("ImageView.callback_image() could not convert image from '%s' to 'rgb8' (%s)", msg->encoding.c_str(), e.what());
ui_.image_frame->setImage(QImage());
Expand Down
7 changes: 7 additions & 0 deletions src/rqt_image_view/image_view.ui
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="color_scheme_combo_box">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down