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)));
116 if (anchor ==
"top left")
120 else if (anchor ==
"top center")
124 else if (anchor ==
"top right")
128 else if (anchor ==
"center left")
132 else if (anchor ==
"center")
136 else if (anchor ==
"center right")
140 else if (anchor ==
"bottom left")
144 else if (anchor ==
"bottom center")
148 else if (anchor ==
"bottom right")
156 if (units ==
"pixels")
160 else if (units ==
"percent")
169 "stereo_msgs/DisparityImage");
171 if (!topic.
name.empty())
173 ui_.topic->setText(QString::fromStdString(topic.
name));
180 std::string topic =
ui_.topic->text().trimmed().toStdString();
219 if (disparity->min_disparity == 0.0 && disparity->max_disparity == 0.0)
236 float min_disparity = disparity->min_disparity;
237 float max_disparity = disparity->max_disparity;
238 float multiplier = 255.0f / (max_disparity - min_disparity);
247 const float*
d = cv_disparity->image.ptr<
float>(row);
250 int index =
static_cast<int>((d[col] - min_disparity) * multiplier + 0.5);
251 index = std::min(255, std::max(0, index));
314 if (image->cols == 0 || image->rows == 0)
318 switch (image->channels())
321 format = GL_LUMINANCE;
324 format = GL_LUMINANCE_ALPHA;
333 glPixelZoom(1.0, -1.0
f);
334 glDrawPixels(image->cols, image->rows, format, GL_UNSIGNED_BYTE, image->ptr());
370 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
375 x_pos =
canvas_->width() - width - x_offset;
381 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
385 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
386 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
390 x_pos =
canvas_->width() - width - x_offset;
391 y_pos = (
canvas_->height() - height) / 2.0 + y_offset;
396 y_pos =
canvas_->height() - height - y_offset;
400 x_pos = (
canvas_->width() - width) / 2.0 + x_offset;
401 y_pos =
canvas_->height() - height - y_offset;
405 x_pos =
canvas_->width() - width - x_offset;
406 y_pos =
canvas_->height() - height - y_offset;
409 glMatrixMode(GL_PROJECTION);
414 glRasterPos2d(x_pos, y_pos);
429 node[
"topic"] >> topic;
430 ui_.topic->setText(topic.c_str());
437 node[
"anchor"] >> anchor;
438 ui_.anchor->setCurrentIndex(
ui_.anchor->findText(anchor.c_str()));
445 node[
"units"] >> units;
446 ui_.units->setCurrentIndex(
ui_.units->findText(units.c_str()));
450 if (node[
"offset_x"])
453 ui_.offsetx->setValue(static_cast<int>(offset_x_));
456 if (node[
"offset_y"])
459 ui_.offsety->setValue(static_cast<int>(offset_y_));
465 ui_.width->setValue(static_cast<int>(width_));
471 ui_.height->setValue(static_cast<int>(height_));
477 emitter << YAML::Key <<
"topic" << YAML::Value <<
ui_.topic->text().toStdString();
480 emitter << YAML::Key <<
"offset_x" << YAML::Value <<
offset_x_;
481 emitter << YAML::Key <<
"offset_y" << YAML::Value <<
offset_y_;
482 emitter << YAML::Key <<
"width" << YAML::Value <<
width_;
483 emitter << YAML::Key <<
"height" << YAML::Value <<
height_;
488 std::string anchor_string =
"top left";
492 anchor_string =
"top left";
496 anchor_string =
"top center";
500 anchor_string =
"top right";
504 anchor_string =
"center left";
506 else if (anchor ==
CENTER)
508 anchor_string =
"center";
512 anchor_string =
"center right";
516 anchor_string =
"bottom left";
520 anchor_string =
"bottom center";
524 anchor_string =
"bottom right";
527 return anchor_string;
532 std::string units_string =
"pixels";
536 units_string =
"pixels";
540 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)
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 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)