35 #include <opencv2/highgui/highgui.hpp> 38 #include <QContextMenuEvent> 40 #include <QFileDialog> 42 #include <QGraphicsView> 43 #include <QGraphicsScene> 44 #include <QVBoxLayout> 45 #include <QGraphicsRectItem> 46 #include <QInputDialog> 49 #include <QColorDialog> 51 #include <QtCore/QDir> 61 graphicsViewInitialized_(false),
73 color_(QColor((Qt::GlobalColor)((id % 10 + 7)==Qt::yellow?Qt::darkYellow:(id % 10 + 7))))
87 graphicsView_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
91 label_->setAlignment(Qt::AlignCenter);
92 label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
94 this->setLayout(
new QVBoxLayout(
this));
96 this->layout()->addWidget(
label_);
97 this->layout()->setContentsMargins(0,0,0,0);
99 menu_ =
new QMenu(tr(
""),
this);
119 menu_->addSeparator();
122 menu_->addSeparator();
124 menu_->addSeparator();
130 graphicsView_->setRubberBandSelectionMode(Qt::ContainsItemShape);
138 color_ = QColor((Qt::GlobalColor)((
id % 10 + 7)==Qt::yellow?Qt::darkYellow:(
id % 10 + 7)));
208 float radius = size*1.2f/9.0f*2.0f;
234 if(alpha>=0 && alpha<=255)
249 QColor
color = pen.color();
273 pixmap_ = QPixmap::fromImage(image);
276 label_->setVisible(image.isNull());
304 for(QMultiMap<int,int>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
306 words_.insert(iter.value(), iter.key());
370 words_.insert(index, wordID);
384 QPen pen = rect->pen();
385 QColor
color = pen.color();
419 delete_->setEnabled(deletable);
456 float w =
rect_.width();
457 float h =
rect_.height();
458 float widthRatio = float(this->rect().width()) / w;
459 float heightRatio = float(this->rect().height()) / h;
462 if(widthRatio < heightRatio)
476 if(w < this->rect().width())
478 offsetX = (this->rect().width() - w)/2.0
f;
480 if(h < this->rect().height())
482 offsetY = (this->rect().height() - h)/2.0
f;
492 QWidget::paintEvent(event);
499 float ratio, offsetX, offsetY;
501 QPainter painter(
this);
505 painter.translate(offsetX+
rect_.width()*ratio, offsetY);
506 painter.scale(-ratio, ratio);
510 painter.translate(offsetX, offsetY);
511 painter.scale(ratio, ratio);
516 painter.drawPixmap(QPoint(0,0),
pixmap_);
527 painter.setTransform(
rectItems_.at(i)->transform(),
true);
536 int left, top, right, bottom;
544 left = qAbs(right -
rect_.width());
545 right = qAbs(l -
rect_.width());
547 painter.setPen(Qt::NoPen);
548 painter.setBrush(QBrush(QColor(0,0,0,100)));
549 painter.drawRect(0, 0,
rect_.width(), top);
550 painter.drawRect(0, top, left, bottom-top);
551 painter.drawRect(right, top,
rect_.width()-right, bottom-top);
552 painter.drawRect(0, bottom,
rect_.width(),
rect_.height()-bottom);
561 QWidget::resizeEvent(event);
570 float scale, offsetX, offsetY;
576 QWidget::mousePressEvent(event);
581 float scale, offsetX, offsetY;
586 QWidget::mouseMoveEvent(event);
593 int left,top,bottom,right;
603 left = qAbs(right -
rect_.width());
604 right = qAbs(l -
rect_.width());
607 Q_EMIT
roiChanged(cv::Rect(left, top, right-left, bottom-top));
609 QWidget::mouseReleaseEvent(event);
614 QAction *
action =
menu_->exec(event->globalPos());
622 text = QFileDialog::getSaveFileName(
this, tr(
"Save figure to ..."),
savedFileName_,
"*.png *.xpm *.jpg *.pdf");
625 if(!text.endsWith(
".png") && !text.endsWith(
".xpm") && !text.endsWith(
".jpg") && !text.endsWith(
".pdf"))
666 QColor
color = QColorDialog::getColor(
color_,
this);
696 int newAlpha = QInputDialog::getInt(
this, tr(
"Set alpha"), tr(
"Alpha:"),
alpha_, 0, 255, 5, &ok);
715 return QPixmap::grabWidget(
this);
721 QList<QGraphicsItem*> items =
graphicsView_->scene()->items();
722 for(
int i=0; i<items.size(); ++i)
724 if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
728 else if(qgraphicsitem_cast<QGraphicsPixmapItem*>(items.at(i)))
730 items.at(i)->setVisible(
showImage_->isChecked());
737 QList<KeypointItem *> items;
741 for(std::vector<cv::KeyPoint>::const_iterator iter =
keypoints_.begin(); iter !=
keypoints_.end(); ++iter, ++i )
743 const cv::KeyPoint & r = *iter;
749 float radius = size*1.2f/9.0f*2.0f;
766 painter->setPen(
color);
767 painter->setBrush(
color);
768 painter->drawEllipse(r.pt.x-radius, r.pt.y-radius, radius*2, radius*2);
776 QColor
color(
id >= 0 ? Qt::yellow : Qt::white);
783 std::vector<cv::KeyPoint> selected;
786 QList<QGraphicsItem*> items =
graphicsView_->scene()->selectedItems();
787 for(
int i=0; i<items.size(); ++i)
789 if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
804 QList<KeypointItem*> items;
void setColor(const QColor &color)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
static QString workingDirectory()
ULogger class and convenient macros.