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();
269 pixmap_ = QPixmap::fromImage(image);
271 label_->setVisible(image.isNull());
299 for(QMultiMap<int,int>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
301 words_.insert(iter.value(), iter.key());
365 words_.insert(index, wordID);
379 QPen pen = rect->pen();
380 QColor
color = pen.color();
414 delete_->setEnabled(deletable);
452 float h =
rect_.height();
453 float widthRatio = float(this->rect().width()) / w;
454 float heightRatio = float(this->rect().height()) / h;
457 if(widthRatio < heightRatio)
471 if(w < this->rect().width())
473 offsetX = (this->rect().width() - w)/2.0
f;
475 if(h < this->rect().height())
477 offsetY = (this->rect().height() - h)/2.0
f;
487 QWidget::paintEvent(event);
494 float ratio, offsetX, offsetY;
496 QPainter painter(
this);
500 painter.translate(offsetX+
rect_.width()*ratio, offsetY);
501 painter.scale(-ratio, ratio);
505 painter.translate(offsetX, offsetY);
506 painter.scale(ratio, ratio);
511 painter.drawPixmap(QPoint(0,0),
pixmap_);
522 painter.setTransform(
rectItems_.at(i)->transform(),
true);
531 int left, top, right, bottom;
539 left = qAbs(right -
rect_.width());
540 right = qAbs(l -
rect_.width());
542 painter.setPen(Qt::NoPen);
543 painter.setBrush(QBrush(QColor(0,0,0,100)));
544 painter.drawRect(0, 0,
rect_.width(), top);
545 painter.drawRect(0, top, left, bottom-top);
546 painter.drawRect(right, top,
rect_.width()-right, bottom-top);
547 painter.drawRect(0, bottom,
rect_.width(),
rect_.height()-bottom);
556 QWidget::resizeEvent(event);
565 float scale, offsetX, offsetY;
571 QWidget::mousePressEvent(event);
576 float scale, offsetX, offsetY;
581 QWidget::mouseMoveEvent(event);
588 int left,top,bottom,right;
598 left = qAbs(right -
rect_.width());
599 right = qAbs(l -
rect_.width());
602 Q_EMIT
roiChanged(cv::Rect(left, top, right-left, bottom-top));
604 QWidget::mouseReleaseEvent(event);
609 QAction *
action =
menu_->exec(event->globalPos());
617 text = QFileDialog::getSaveFileName(
this, tr(
"Save figure to ..."),
savedFileName_,
"*.png *.xpm *.jpg *.pdf");
620 if(!text.endsWith(
".png") && !text.endsWith(
".xpm") && !text.endsWith(
".jpg") && !text.endsWith(
".pdf"))
661 QColor
color = QColorDialog::getColor(
color_,
this);
691 int newAlpha = QInputDialog::getInt(
this, tr(
"Set alpha"), tr(
"Alpha:"),
alpha_, 0, 255, 5, &ok);
710 return QPixmap::grabWidget(
this);
716 QList<QGraphicsItem*> items =
graphicsView_->scene()->items();
717 for(
int i=0; i<items.size(); ++i)
719 if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
723 else if(qgraphicsitem_cast<QGraphicsPixmapItem*>(items.at(i)))
725 items.at(i)->setVisible(
showImage_->isChecked());
732 QList<KeypointItem *> items;
736 for(std::vector<cv::KeyPoint>::const_iterator iter =
keypoints_.begin(); iter !=
keypoints_.end(); ++iter, ++i )
738 const cv::KeyPoint & r = *iter;
744 float radius = size*1.2f/9.0f*2.0f;
761 painter->setPen(
color);
762 painter->setBrush(
color);
763 painter->drawEllipse(r.pt.x-radius, r.pt.y-radius, radius*2, radius*2);
771 QColor
color(
id >= 0 ? Qt::yellow : Qt::white);
778 std::vector<cv::KeyPoint> selected;
781 QList<QGraphicsItem*> items =
graphicsView_->scene()->selectedItems();
782 for(
int i=0; i<items.size(); ++i)
784 if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
799 QList<KeypointItem*> items;
void setColor(const QColor &color)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
static QString workingDirectory()
TFSIMD_FORCE_INLINE const tfScalar & w() const
ULogger class and convenient macros.