43 #include <opencv2/imgproc/imgproc.hpp> 53 ImagePlugin::ImagePlugin() :
54 config_widget_(new QWidget()),
61 transport_(
"default"),
65 original_aspect_ratio_(1.0)
71 p.setColor(QPalette::Background, Qt::white);
75 QPalette p3(
ui_.status->palette());
76 p3.setColor(QPalette::Text, Qt::red);
77 ui_.status->setPalette(p3);
79 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
80 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
81 QObject::connect(
ui_.anchor, SIGNAL(activated(QString)),
this, SLOT(
SetAnchor(QString)));
82 QObject::connect(
ui_.units, SIGNAL(activated(QString)),
this, SLOT(
SetUnits(QString)));
83 QObject::connect(
ui_.offsetx, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetX(
int)));
84 QObject::connect(
ui_.offsety, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetY(
int)));
85 QObject::connect(
ui_.width, SIGNAL(valueChanged(
double)),
this, SLOT(
SetWidth(
double)));
86 QObject::connect(
ui_.height, SIGNAL(valueChanged(
double)),
this, SLOT(
SetHeight(
double)));
88 QObject::connect(
ui_.keep_ratio, SIGNAL(toggled(
bool)),
this, SLOT(
KeepRatioChanged(
bool)));
89 QObject::connect(
ui_.transport_combo_box, SIGNAL(activated(
const QString&)),
92 ui_.width->setKeyboardTracking(
false);
93 ui_.height->setKeyboardTracking(
false);
122 if (anchor ==
"top left")
126 else if (anchor ==
"top center")
130 else if (anchor ==
"top right")
134 else if (anchor ==
"center left")
138 else if (anchor ==
"center")
142 else if (anchor ==
"center right")
146 else if (anchor ==
"bottom left")
150 else if (anchor ==
"bottom center")
154 else if (anchor ==
"bottom right")
163 ui_.width->setMaximum(10000);
164 ui_.height->setMaximum(10000);
166 if (units ==
"pixels")
168 ui_.width->setDecimals(0);
169 ui_.height->setDecimals(0);
173 ui_.width->setSuffix(
" px");
174 ui_.height->setSuffix(
" px");
176 else if (units ==
"percent")
178 ui_.width->setDecimals(1);
179 ui_.height->setDecimals(1);
183 ui_.width->setSuffix(
" %");
184 ui_.height->setSuffix(
" %");
191 ui_.width->setMaximum(100);
192 ui_.height->setMaximum(100);
218 ROS_INFO(
"Changing image_transport to %s.", transport.toStdString().c_str());
225 ui_.height->setEnabled( !checked );
234 if (
transport_ == QString::fromStdString(
"default"))
244 "sensor_msgs/Image");
246 if(topic.
name.empty())
252 if (!topic.
name.empty())
254 ui_.topic->setText(QString::fromStdString(topic.
name));
261 std::string topic =
ui_.topic->text().trimmed().toStdString();
291 if (
transport_ == QString::fromStdString(
"default"))
294 it = boost::make_shared<image_transport::ImageTransport>(
node_);
299 ROS_DEBUG(
"Setting transport to %s on %s.",
303 it = boost::make_shared<image_transport::ImageTransport>(
local_node_);
339 if(
ui_.keep_ratio->isChecked() )
346 ui_.height->setValue(height);
395 if (image ==
NULL || image->cols == 0 || image->rows == 0)
401 switch (image->channels())
404 format = GL_LUMINANCE;
407 format = GL_LUMINANCE_ALPHA;
416 glPixelZoom(1.0
f, -1.0
f);
417 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
418 glDrawPixels(image->cols, image->rows, format, GL_UNSIGNED_BYTE, image->ptr());
439 if(
ui_.keep_ratio->isChecked() )
460 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
465 x_pos =
canvas_->width() - width - x_offset;
471 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
475 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
476 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
480 x_pos =
canvas_->width() - width - x_offset;
481 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
486 y_pos =
canvas_->height() - height - y_offset;
490 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
491 y_pos =
canvas_->height() - height - y_offset;
495 x_pos =
canvas_->width() - width - x_offset;
496 y_pos =
canvas_->height() - height - y_offset;
499 glMatrixMode(GL_PROJECTION);
504 glRasterPos2d(x_pos, y_pos);
519 if (node[
"image_transport"])
521 std::string transport;
522 node[
"image_transport"] >> transport;
523 transport_ = QString::fromStdString(transport);
527 ui_.transport_combo_box->setCurrentIndex(index);
531 ROS_WARN(
"Saved image transport %s is unavailable.",
539 node[
"topic"] >> topic;
540 ui_.topic->setText(topic.c_str());
547 node[
"anchor"] >> anchor;
548 ui_.anchor->setCurrentIndex(
ui_.anchor->findText(anchor.c_str()));
555 node[
"units"] >> units;
556 ui_.units->setCurrentIndex(
ui_.units->findText(units.c_str()));
560 if (node[
"offset_x"])
563 ui_.offsetx->setValue(offset_x_);
566 if (node[
"offset_y"])
569 ui_.offsety->setValue(offset_y_);
575 ui_.width->setValue(width_);
581 ui_.height->setValue(height_);
584 if (node[
"keep_ratio"])
587 node[
"keep_ratio"] >> keep;
588 ui_.keep_ratio->setChecked( keep );
594 emitter << YAML::Key <<
"topic" << YAML::Value <<
ui_.topic->text().toStdString();
597 emitter << YAML::Key <<
"offset_x" << YAML::Value <<
offset_x_;
598 emitter << YAML::Key <<
"offset_y" << YAML::Value <<
offset_y_;
599 emitter << YAML::Key <<
"width" << YAML::Value <<
width_;
600 emitter << YAML::Key <<
"height" << YAML::Value <<
height_;
601 emitter << YAML::Key <<
"keep_ratio" << YAML::Value <<
ui_.keep_ratio->isChecked();
602 emitter << YAML::Key <<
"image_transport" << YAML::Value <<
transport_.toStdString();
607 std::string anchor_string =
"top left";
611 anchor_string =
"top left";
615 anchor_string =
"top center";
619 anchor_string =
"top right";
623 anchor_string =
"center left";
625 else if (anchor ==
CENTER)
627 anchor_string =
"center";
631 anchor_string =
"center right";
635 anchor_string =
"bottom left";
639 anchor_string =
"bottom center";
643 anchor_string =
"bottom right";
646 return anchor_string;
651 std::string units_string =
"pixels";
655 units_string =
"pixels";
659 units_string =
"percent";
672 snprintf(buf,
sizeof(buf),
"image_%llu", (
unsigned long long)
ros::WallTime::now().toNSec());
684 Q_FOREACH (
const std::string& transport, transports)
686 QString qtransport = QString::fromStdString(transport).replace(
"image_transport/",
"");
687 ui_.transport_combo_box->addItem(qtransport);
void KeepRatioChanged(bool checked)
void PrintInfo(const std::string &message)
std::vector< std::string > getLoadableTransports() const
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
ros::NodeHandle local_node_
void DrawIplImage(cv::Mat *image)
bool Initialize(QGLWidget *canvas)
virtual void SetNode(const ros::NodeHandle &node)
void SetOffsetY(int offset)
void SetOffsetX(int offset)
sensor_msgs::Image image_
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void PrintError(const std::string &message)
void SetWidth(double width)
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void ScaleImage(double width, double height)
void SetAnchor(QString anchor)
image_transport::Subscriber image_sub_
std::string getTransport() const
void SetUnits(QString units)
double original_aspect_ratio_
void LoadConfig(const YAML::Node &node, const std::string &path)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
const std::string & getNamespace() const
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
void SetSubscription(bool visible)
std::string AnchorToString(Anchor anchor)
void SetTransport(const QString &transport)
void VisibleChanged(bool visible)
void PrintWarning(const std::string &message)
QWidget * GetConfigWidget(QWidget *parent)
cv_bridge::CvImagePtr cv_image_
std::string UnitsToString(Units units)
void SetHeight(double height)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void imageCallback(const sensor_msgs::ImageConstPtr &image)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
void Draw(double x, double y, double scale)