Skip to content
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
2 changes: 1 addition & 1 deletion image_view/cfg/ImageView.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edit_method_colormap = gen.enum([
gen.const("HOT", int_t, 11, "COLORMAP_HOT"),
], "colormap")

gen.add('do_dynamic_scaling', bool_t, 0, 'Do dynamic scaling about pixel values or not', False)
gen.add('do_dynamic_scaling', bool_t, 0, 'Do dynamic scaling about pixel values or not', True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please turn back to false, don't change default behavior please

gen.add('colormap', int_t, 0, "colormap", -1, -1, 11, edit_method=edit_method_colormap);
gen.add('min_image_value', double_t, 0, "Minimum image value for scaling depth/float image.", default=0, min=0);
gen.add('max_image_value', double_t, 0, "Maximum image value for scaling depth/float image.", default=0, min=0);
Expand Down
53 changes: 51 additions & 2 deletions image_view/src/nodelets/image_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
#include <image_view/ImageViewConfig.h>

#include <ros/ros.h>
#include <nodelet/nodelet.h>
#include <image_transport/image_transport.h>
#include <dynamic_reconfigure/server.h>

#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
Expand Down Expand Up @@ -100,9 +103,19 @@ class ImageNodelet : public nodelet::Nodelet
bool autosize_;
boost::format filename_format_;
int count_;

ros::Publisher pub_;

dynamic_reconfigure::Server<image_view::ImageViewConfig> srv_;
bool do_dynamic_scaling_;
int colormap_;
double min_image_value_;
double max_image_value_;

virtual void onInit();

void reconfigureCb(image_view::ImageViewConfig &config, uint32_t level);

void imageCb(const sensor_msgs::ImageConstPtr& msg);

static void mouseCb(int event, int x, int y, int flags, void* param);
Expand Down Expand Up @@ -167,23 +180,57 @@ void ImageNodelet::onInit()
image_transport::ImageTransport it(nh);
image_transport::TransportHints hints(transport, ros::TransportHints(), getPrivateNodeHandle());
sub_ = it.subscribe(topic, 1, &ImageNodelet::imageCb, this, hints);
pub_ = local_nh.advertise<sensor_msgs::Image>("output", 1);

dynamic_reconfigure::Server<image_view::ImageViewConfig>::CallbackType f =
boost::bind(&ImageNodelet::reconfigureCb, this, _1, _2);
srv_.setCallback(f);
}

void ImageNodelet::reconfigureCb(image_view::ImageViewConfig &config, uint32_t level)
{
do_dynamic_scaling_ = config.do_dynamic_scaling;
colormap_ = config.colormap;
min_image_value_ = config.min_image_value;
max_image_value_ = config.max_image_value;
}

void ImageNodelet::imageCb(const sensor_msgs::ImageConstPtr& msg)
{
// We want to scale floating point images so that they display nicely
bool do_dynamic_scaling = (msg->encoding.find("F") != std::string::npos);
bool do_dynamic_scaling = do_dynamic_scaling_ & (msg->encoding.find("F") != std::string::npos);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you intend to do a bitwise operation, or do you actually mean &&?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the message is asking for scaling because its a float image, shouldn't we always do it? Maybe the logic should be that it does scaling for floats, but then it checks the do_dynamic_scaling_ for non-float images to do scalling on those?


// Convert to OpenCV native BGR color
cv_bridge::CvImageConstPtr cv_ptr;
try {
cv_bridge::CvtColorForDisplayOptions options;
options.do_dynamic_scaling = do_dynamic_scaling;
queued_image_.set(cvtColorForDisplay(cv_bridge::toCvShare(msg), "", options)->image);
options.colormap = colormap_;
// Set min/max value for scaling to visualize depth/float image.
if (min_image_value_ == max_image_value_) {
// Not specified by rosparam, then set default value.
// Because of current sensor limitation, we use 10m as default of max range of depth
// with consistency to the configuration in rqt_image_view.
options.min_image_value = 0;
if (msg->encoding == "32FC1") {
options.max_image_value = 10; // 10 [m]
} else if (msg->encoding == "16UC1") {
options.max_image_value = 10 * 1000; // 10 * 1000 [mm]
}
} else {
options.min_image_value = min_image_value_;
options.max_image_value = max_image_value_;
}
cv_ptr = cvtColorForDisplay(cv_bridge::toCvShare(msg), "", options);
queued_image_.set(cv_ptr->image);
}
catch (cv_bridge::Exception& e) {
NODELET_ERROR_THROTTLE(30, "Unable to convert '%s' image for display: '%s'",
msg->encoding.c_str(), e.what());
}
if (pub_.getNumSubscribers() > 0) {
pub_.publish(cv_ptr);
}
}

void ImageNodelet::mouseCb(int event, int x, int y, int flags, void* param)
Expand Down Expand Up @@ -247,6 +294,8 @@ void ImageNodelet::windowThread()

cv::destroyWindow(window_name_);

pub_.shutdown();

if (ros::ok())
{
ros::shutdown();
Expand Down