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);
222 ui_.height->setEnabled( !checked );
241 "sensor_msgs/Image");
243 if(topic.
name.empty())
249 if (!topic.
name.empty())
251 ui_.topic->setText(QString::fromStdString(topic.
name));
258 std::string topic =
ui_.topic->text().trimmed().toStdString();
296 ROS_DEBUG(
"Setting transport to %s on %s.",
336 if(
ui_.keep_ratio->isChecked() )
343 ui_.height->setValue(height);
392 if (image ==
NULL || image->cols == 0 || image->rows == 0)
398 switch (image->channels())
401 format = GL_LUMINANCE;
404 format = GL_LUMINANCE_ALPHA;
413 glPixelZoom(1.0
f, -1.0
f);
414 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
415 glDrawPixels(image->cols, image->rows, format, GL_UNSIGNED_BYTE, image->ptr());
416 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
438 if(
ui_.keep_ratio->isChecked() )
459 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
464 x_pos =
canvas_->width() - width - x_offset;
470 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
474 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
475 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
479 x_pos =
canvas_->width() - width - x_offset;
480 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
485 y_pos =
canvas_->height() - height - y_offset;
489 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
490 y_pos =
canvas_->height() - height - y_offset;
494 x_pos =
canvas_->width() - width - x_offset;
495 y_pos =
canvas_->height() - height - y_offset;
498 glMatrixMode(GL_PROJECTION);
503 glRasterPos2d(x_pos, y_pos);
518 if (node[
"image_transport"])
521 int index =
ui_.transport_combo_box->findText( QString::fromStdString(transport_) );
524 ui_.transport_combo_box->setCurrentIndex(index);
528 ROS_WARN(
"Saved image transport %s is unavailable.",
536 node[
"topic"] >> topic;
537 ui_.topic->setText(topic.c_str());
544 node[
"anchor"] >> anchor;
545 ui_.anchor->setCurrentIndex(
ui_.anchor->findText(anchor.c_str()));
552 node[
"units"] >> units;
553 ui_.units->setCurrentIndex(
ui_.units->findText(units.c_str()));
557 if (node[
"offset_x"])
560 ui_.offsetx->setValue(offset_x_);
563 if (node[
"offset_y"])
566 ui_.offsety->setValue(offset_y_);
572 ui_.width->setValue(width_);
578 ui_.height->setValue(height_);
581 if (node[
"keep_ratio"])
584 node[
"keep_ratio"] >> keep;
585 ui_.keep_ratio->setChecked( keep );
591 emitter << YAML::Key <<
"topic" << YAML::Value <<
ui_.topic->text().toStdString();
594 emitter << YAML::Key <<
"offset_x" << YAML::Value <<
offset_x_;
595 emitter << YAML::Key <<
"offset_y" << YAML::Value <<
offset_y_;
596 emitter << YAML::Key <<
"width" << YAML::Value <<
width_;
597 emitter << YAML::Key <<
"height" << YAML::Value <<
height_;
598 emitter << YAML::Key <<
"keep_ratio" << YAML::Value <<
ui_.keep_ratio->isChecked();
599 emitter << YAML::Key <<
"image_transport" << YAML::Value <<
transport_;
604 std::string anchor_string =
"top left";
608 anchor_string =
"top left";
612 anchor_string =
"top center";
616 anchor_string =
"top right";
620 anchor_string =
"center left";
622 else if (anchor ==
CENTER)
624 anchor_string =
"center";
628 anchor_string =
"center right";
632 anchor_string =
"bottom left";
636 anchor_string =
"bottom center";
640 anchor_string =
"bottom right";
643 return anchor_string;
648 std::string units_string =
"pixels";
652 units_string =
"pixels";
656 units_string =
"percent";
669 snprintf(buf,
sizeof(buf),
"image_%llu", (
unsigned long long)
ros::WallTime::now().toNSec());
681 Q_FOREACH (
const std::string& transport, transports)
683 QString qtransport = QString::fromStdString(transport).replace(
"image_transport/",
"");
684 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)