44 #include <opencv2/imgproc/imgproc.hpp> 56 DisparityPlugin::DisparityPlugin() :
57 config_widget_(new QWidget()),
72 p.setColor(QPalette::Background, Qt::white);
76 QPalette p3(
ui_.status->palette());
77 p3.setColor(QPalette::Text, Qt::red);
78 ui_.status->setPalette(p3);
80 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
81 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
82 QObject::connect(
ui_.anchor, SIGNAL(activated(QString)),
this, SLOT(
SetAnchor(QString)));
83 QObject::connect(
ui_.units, SIGNAL(activated(QString)),
this, SLOT(
SetUnits(QString)));
84 QObject::connect(
ui_.offsetx, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetX(
int)));
85 QObject::connect(
ui_.offsety, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetY(
int)));
86 QObject::connect(
ui_.width, SIGNAL(valueChanged(
int)),
this, SLOT(
SetWidth(
int)));
87 QObject::connect(
ui_.height, SIGNAL(valueChanged(
int)),
this, SLOT(
SetHeight(
int)));
117 if (anchor ==
"top left")
121 else if (anchor ==
"top center")
125 else if (anchor ==
"top right")
129 else if (anchor ==
"center left")
133 else if (anchor ==
"center")
137 else if (anchor ==
"center right")
141 else if (anchor ==
"bottom left")
145 else if (anchor ==
"bottom center")
149 else if (anchor ==
"bottom right")
157 if (units ==
"pixels")
161 else if (units ==
"percent")
187 "stereo_msgs/DisparityImage");
189 if(topic.
name.empty())
193 if (!topic.
name.empty())
195 ui_.topic->setText(QString::fromStdString(topic.
name));
202 std::string topic =
ui_.topic->text().trimmed().toStdString();
242 if (disparity->min_disparity == 0.0 && disparity->max_disparity == 0.0)
259 float min_disparity = disparity->min_disparity;
260 float max_disparity = disparity->max_disparity;
261 float multiplier = 255.0f / (max_disparity - min_disparity);
270 const float*
d = cv_disparity->image.ptr<
float>(row);
273 int index =
static_cast<int>((d[col] - min_disparity) * multiplier + 0.5);
274 index = std::min(255, std::max(0, index));
337 if (image->cols == 0 || image->rows == 0)
341 switch (image->channels())
344 format = GL_LUMINANCE;
347 format = GL_LUMINANCE_ALPHA;
356 glPixelZoom(1.0, -1.0
f);
357 glDrawPixels(image->cols, image->rows, format, GL_UNSIGNED_BYTE, image->ptr());
393 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
398 x_pos =
canvas_->width() - width - x_offset;
404 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
408 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
409 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
413 x_pos =
canvas_->width() - width - x_offset;
414 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
419 y_pos =
canvas_->height() - height - y_offset;
423 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
424 y_pos =
canvas_->height() - height - y_offset;
428 x_pos =
canvas_->width() - width - x_offset;
429 y_pos =
canvas_->height() - height - y_offset;
432 glMatrixMode(GL_PROJECTION);
437 glRasterPos2d(x_pos, y_pos);
452 node[
"topic"] >> topic;
453 ui_.topic->setText(topic.c_str());
460 node[
"anchor"] >> anchor;
461 ui_.anchor->setCurrentIndex(
ui_.anchor->findText(anchor.c_str()));
468 node[
"units"] >> units;
469 ui_.units->setCurrentIndex(
ui_.units->findText(units.c_str()));
473 if (node[
"offset_x"])
476 ui_.offsetx->setValue(static_cast<int>(offset_x_));
479 if (node[
"offset_y"])
482 ui_.offsety->setValue(static_cast<int>(offset_y_));
488 ui_.width->setValue(static_cast<int>(width_));
494 ui_.height->setValue(static_cast<int>(height_));
500 emitter << YAML::Key <<
"topic" << YAML::Value <<
ui_.topic->text().toStdString();
503 emitter << YAML::Key <<
"offset_x" << YAML::Value <<
offset_x_;
504 emitter << YAML::Key <<
"offset_y" << YAML::Value <<
offset_y_;
505 emitter << YAML::Key <<
"width" << YAML::Value <<
width_;
506 emitter << YAML::Key <<
"height" << YAML::Value <<
height_;
511 std::string anchor_string =
"top left";
515 anchor_string =
"top left";
519 anchor_string =
"top center";
523 anchor_string =
"top right";
527 anchor_string =
"center left";
529 else if (anchor ==
CENTER)
531 anchor_string =
"center";
535 anchor_string =
"center right";
539 anchor_string =
"bottom left";
543 anchor_string =
"bottom center";
547 anchor_string =
"bottom right";
550 return anchor_string;
555 std::string units_string =
"pixels";
559 units_string =
"pixels";
563 units_string =
"percent";
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
void PrintInfo(const std::string &message)
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void disparityCallback(const stereo_msgs::DisparityImageConstPtr &image)
void SetSubscription(bool visible)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void Draw(double x, double y, double scale)
void PrintError(const std::string &message)
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)
virtual ~DisparityPlugin()
void PrintWarning(const std::string &message)
std::string UnitsToString(Units units)
cv::Mat_< cv::Vec3b > disparity_color_
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void DrawIplImage(cv::Mat *image)
bool Initialize(QGLWidget *canvas)
void SetOffsetY(int offset)
std::string AnchorToString(Anchor anchor)
void ScaleImage(double width, double height)
const std::string TYPE_32FC1
ros::Subscriber disparity_sub_
static const unsigned char COLOR_MAP[]
void SetUnits(QString units)
void SetHeight(int height)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
stereo_msgs::DisparityImage disparity_
void VisibleChanged(bool visible)
void LoadConfig(const YAML::Node &node, const std::string &path)
void SetAnchor(QString anchor)
void SetOffsetX(int offset)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
QWidget * GetConfigWidget(QWidget *parent)