2011-12-02 18:34:08 +00:00
|
|
|
/*
|
2014-08-06 13:43:29 +00:00
|
|
|
Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2014-08-11 15:49:53 +00:00
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
2014-08-06 13:43:29 +00:00
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-07-31 20:11:46 +00:00
|
|
|
#include "find_object/Settings.h"
|
|
|
|
|
#include "find_object/utilite/ULogger.h"
|
|
|
|
|
#include "find_object/ObjWidget.h"
|
|
|
|
|
#include "find_object/QtOpenCV.h"
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
#include "KeypointItem.h"
|
|
|
|
|
|
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
|
|
2015-11-29 18:39:20 -05:00
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QGraphicsRectItem>
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QPen>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QColorDialog>
|
2011-10-25 15:48:19 +00:00
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
namespace find_object {
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
ObjWidget::ObjWidget(QWidget * parent) :
|
2011-10-25 15:48:19 +00:00
|
|
|
QWidget(parent),
|
|
|
|
|
id_(0),
|
2014-07-31 19:02:31 +00:00
|
|
|
graphicsView_(0),
|
2011-11-18 16:09:23 +00:00
|
|
|
graphicsViewInitialized_(false),
|
2014-08-03 22:23:02 +00:00
|
|
|
alpha_(100),
|
|
|
|
|
color_(Qt::red)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
setupUi();
|
|
|
|
|
}
|
2015-06-24 18:07:52 -04:00
|
|
|
ObjWidget::ObjWidget(int id, const std::vector<cv::KeyPoint> & keypoints, const QMultiMap<int,int> & words, const QImage & image, QWidget * parent) :
|
2011-10-25 15:48:19 +00:00
|
|
|
QWidget(parent),
|
|
|
|
|
id_(id),
|
2014-07-31 19:02:31 +00:00
|
|
|
graphicsView_(0),
|
2011-11-18 16:09:23 +00:00
|
|
|
graphicsViewInitialized_(false),
|
2014-08-03 22:23:02 +00:00
|
|
|
alpha_(100),
|
2015-07-07 16:49:38 -04:00
|
|
|
color_(QColor((Qt::GlobalColor)((id % 10 + 7)==Qt::yellow?Qt::darkYellow:(id % 10 + 7))))
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
setupUi();
|
2015-06-24 18:07:52 -04:00
|
|
|
this->updateImage(image);
|
|
|
|
|
this->updateData(keypoints, words);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2011-11-15 16:37:40 +00:00
|
|
|
ObjWidget::~ObjWidget()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::setupUi()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
graphicsView_ = new QGraphicsView(this);
|
2011-11-17 20:31:08 +00:00
|
|
|
graphicsView_->setVisible(false);
|
2011-10-25 15:48:19 +00:00
|
|
|
graphicsView_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
|
|
|
|
graphicsView_->setScene(new QGraphicsScene(graphicsView_));
|
|
|
|
|
|
2012-02-04 22:15:32 +00:00
|
|
|
label_ = new QLabel();
|
|
|
|
|
label_->setAlignment(Qt::AlignCenter);
|
2014-07-08 20:12:42 +00:00
|
|
|
label_->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2012-02-04 22:15:32 +00:00
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
this->setLayout(new QVBoxLayout(this));
|
2011-10-25 15:48:19 +00:00
|
|
|
this->layout()->addWidget(graphicsView_);
|
2012-02-04 22:15:32 +00:00
|
|
|
this->layout()->addWidget(label_);
|
2011-10-25 15:48:19 +00:00
|
|
|
this->layout()->setContentsMargins(0,0,0,0);
|
|
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
menu_ = new QMenu(tr(""), this);
|
|
|
|
|
showImage_ = menu_->addAction(tr("Show image"));
|
|
|
|
|
showImage_->setCheckable(true);
|
|
|
|
|
showImage_->setChecked(true);
|
|
|
|
|
showFeatures_ = menu_->addAction(tr("Show features"));
|
|
|
|
|
showFeatures_->setCheckable(true);
|
|
|
|
|
showFeatures_->setChecked(true);
|
|
|
|
|
mirrorView_ = menu_->addAction(tr("Mirror view"));
|
|
|
|
|
mirrorView_->setCheckable(true);
|
|
|
|
|
mirrorView_->setChecked(false);
|
|
|
|
|
graphicsViewMode_ = menu_->addAction(tr("Graphics view"));
|
|
|
|
|
graphicsViewMode_->setCheckable(true);
|
|
|
|
|
graphicsViewMode_->setChecked(false);
|
|
|
|
|
autoScale_ = menu_->addAction(tr("Scale view"));
|
|
|
|
|
autoScale_->setCheckable(true);
|
|
|
|
|
autoScale_->setChecked(true);
|
|
|
|
|
autoScale_->setEnabled(false);
|
|
|
|
|
sizedFeatures_ = menu_->addAction(tr("Sized features"));
|
|
|
|
|
sizedFeatures_->setCheckable(true);
|
|
|
|
|
sizedFeatures_->setChecked(false);
|
|
|
|
|
menu_->addSeparator();
|
2014-08-03 22:23:02 +00:00
|
|
|
setColor_ = menu_->addAction(tr("Set color..."));
|
2012-04-04 18:15:51 +00:00
|
|
|
setAlpha_ = menu_->addAction(tr("Set alpha..."));
|
|
|
|
|
menu_->addSeparator();
|
|
|
|
|
saveImage_ = menu_->addAction(tr("Save picture..."));
|
|
|
|
|
menu_->addSeparator();
|
|
|
|
|
delete_ = menu_->addAction(tr("Delete"));
|
|
|
|
|
delete_->setEnabled(false);
|
2011-10-25 15:48:19 +00:00
|
|
|
|
|
|
|
|
this->setId(id_);
|
|
|
|
|
|
|
|
|
|
graphicsView_->setRubberBandSelectionMode(Qt::ContainsItemShape);
|
|
|
|
|
graphicsView_->setDragMode(QGraphicsView::RubberBandDrag);
|
2011-11-09 15:07:19 +00:00
|
|
|
|
|
|
|
|
connect(graphicsView_->scene(), SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::setId(int id)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-07 16:49:38 -04:00
|
|
|
color_ = QColor((Qt::GlobalColor)((id % 10 + 7)==Qt::yellow?Qt::darkYellow:(id % 10 + 7)));
|
2011-10-25 15:48:19 +00:00
|
|
|
id_=id;
|
|
|
|
|
if(id_)
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
savedFileName_ = QString("object_%1.png").arg(id_);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::setGraphicsViewMode(bool on)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
graphicsViewMode_->setChecked(on);
|
2014-08-28 17:54:29 +00:00
|
|
|
graphicsView_->setVisible(on && graphicsView_->scene()->items().size());
|
2012-04-04 18:15:51 +00:00
|
|
|
autoScale_->setEnabled(on);
|
2011-10-25 15:48:19 +00:00
|
|
|
//update items' color
|
|
|
|
|
if(on)
|
|
|
|
|
{
|
2011-11-17 20:31:08 +00:00
|
|
|
if(!graphicsViewInitialized_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
this->setupGraphicsView();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<keypointItems_.size(); ++i)
|
|
|
|
|
{
|
2012-02-05 16:18:18 +00:00
|
|
|
QColor color = kptColors_.at(i);
|
|
|
|
|
color.setAlpha(alpha_);
|
|
|
|
|
keypointItems_[i]->setColor(color);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
if(autoScale_->isChecked())
|
2011-11-17 20:31:08 +00:00
|
|
|
{
|
|
|
|
|
graphicsView_->fitInView(graphicsView_->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->resetTransform();
|
2014-08-28 17:54:29 +00:00
|
|
|
graphicsView_->setTransform(QTransform().scale(this->isMirrorView()?-1.0:1.0, 1.0));
|
2011-11-17 20:31:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjWidget::setAutoScale(bool autoScale)
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
autoScale_->setChecked(autoScale);
|
|
|
|
|
if(graphicsViewMode_)
|
2011-11-17 20:31:08 +00:00
|
|
|
{
|
|
|
|
|
if(autoScale)
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->fitInView(graphicsView_->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->resetTransform();
|
2014-08-28 17:54:29 +00:00
|
|
|
graphicsView_->setTransform(QTransform().scale(this->isMirrorView()?-1.0:1.0, 1.0));
|
2011-11-17 20:31:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-18 16:09:23 +00:00
|
|
|
void ObjWidget::setSizedFeatures(bool on)
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
sizedFeatures_->setChecked(on);
|
2011-11-18 16:09:23 +00:00
|
|
|
if(graphicsViewInitialized_)
|
|
|
|
|
{
|
2011-11-23 18:08:33 +00:00
|
|
|
for(unsigned int i=0; i<(unsigned int)keypointItems_.size() && i<keypoints_.size(); ++i)
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
|
|
|
|
float size = 14;
|
|
|
|
|
if(on && keypoints_[i].size>14.0f)
|
|
|
|
|
{
|
|
|
|
|
size = keypoints_[i].size;
|
|
|
|
|
}
|
|
|
|
|
float radius = size*1.2f/9.0f*2.0f;
|
|
|
|
|
keypointItems_.at(i)->setRect(keypoints_[i].pt.x-radius, keypoints_[i].pt.y-radius, radius*2, radius*2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
if(!graphicsViewMode_->isChecked())
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 01:00:23 +00:00
|
|
|
void ObjWidget::setMirrorView(bool on)
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
mirrorView_->setChecked(on);
|
2012-01-28 01:00:23 +00:00
|
|
|
graphicsView_->setTransform(QTransform().scale(this->isMirrorView()?-1.0:1.0, 1.0));
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked() && autoScale_->isChecked())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
|
|
|
|
graphicsView_->fitInView(graphicsView_->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(!graphicsViewMode_->isChecked())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 16:09:23 +00:00
|
|
|
void ObjWidget::setAlpha(int alpha)
|
|
|
|
|
{
|
|
|
|
|
if(alpha>=0 && alpha<=255)
|
|
|
|
|
{
|
|
|
|
|
alpha_ = alpha;
|
|
|
|
|
if(graphicsViewInitialized_)
|
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<keypointItems_.size() && i<kptColors_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
QColor color = kptColors_.at(i);
|
|
|
|
|
color.setAlpha(alpha_);
|
|
|
|
|
keypointItems_.at(i)->setColor(color);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
for(int i=0; i<rectItems_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
QPen pen = rectItems_.at(i)->pen();
|
|
|
|
|
QColor color = pen.color();
|
|
|
|
|
color.setAlpha(alpha_);
|
|
|
|
|
pen.setColor(color);
|
|
|
|
|
rectItems_.at(i)->setPen(pen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!graphicsViewMode_->isChecked())
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-04 22:15:32 +00:00
|
|
|
void ObjWidget::setTextLabel(const QString & text)
|
|
|
|
|
{
|
|
|
|
|
label_->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 18:07:52 -04:00
|
|
|
void ObjWidget::updateImage(const QImage & image)
|
|
|
|
|
{
|
|
|
|
|
pixmap_ = QPixmap::fromImage(image);
|
|
|
|
|
rect_ = pixmap_.rect();
|
|
|
|
|
label_->setVisible(image.isNull());
|
|
|
|
|
}
|
|
|
|
|
void ObjWidget::updateData(const std::vector<cv::KeyPoint> & keypoints, const QMultiMap<int, int> & words)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
keypoints_ = keypoints;
|
2015-07-07 16:49:38 -04:00
|
|
|
kptColors_ = QVector<QColor>((int)keypoints.size(), defaultColor(0));
|
2011-10-25 15:48:19 +00:00
|
|
|
keypointItems_.clear();
|
2011-11-09 15:07:19 +00:00
|
|
|
rectItems_.clear();
|
2015-06-24 18:07:52 -04:00
|
|
|
this->updateWords(words);
|
2011-11-17 20:31:08 +00:00
|
|
|
graphicsView_->scene()->clear();
|
|
|
|
|
graphicsViewInitialized_ = false;
|
2012-02-04 22:15:32 +00:00
|
|
|
mouseCurrentPos_ = mousePressedPos_; // this will reset roi selection
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2012-05-07 22:36:59 +00:00
|
|
|
//this->setMinimumSize(image_.size());
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
this->setupGraphicsView();
|
|
|
|
|
}
|
2015-06-24 18:07:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjWidget::updateWords(const QMultiMap<int,int> & words)
|
|
|
|
|
{
|
|
|
|
|
words_.clear();
|
|
|
|
|
for(QMultiMap<int,int>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
words_.insert(iter.value(), iter.key());
|
|
|
|
|
}
|
2015-07-07 16:49:38 -04:00
|
|
|
for(int i=0; i<kptColors_.size(); ++i)
|
2015-06-24 18:07:52 -04:00
|
|
|
{
|
2015-07-07 16:49:38 -04:00
|
|
|
kptColors_[i] = defaultColor(words_.size()?words_.value(i,-1):0);
|
|
|
|
|
if(keypointItems_.size() == kptColors_.size())
|
|
|
|
|
{
|
|
|
|
|
keypointItems_[i]->setWordID(words_.value(i,-1));
|
|
|
|
|
keypointItems_[i]->setColor(defaultColor(words_.size()?keypointItems_[i]->wordID():0));
|
|
|
|
|
}
|
2015-06-24 18:07:52 -04:00
|
|
|
}
|
2014-05-11 23:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::resetKptsColor()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
for(int i=0; i<kptColors_.size(); ++i)
|
|
|
|
|
{
|
2015-07-07 16:49:38 -04:00
|
|
|
if(keypointItems_.size() == kptColors_.size())
|
|
|
|
|
{
|
|
|
|
|
kptColors_[i] = defaultColor(keypointItems_[i]->wordID());
|
|
|
|
|
keypointItems_[i]->setColor(this->defaultColor(keypointItems_[i]->wordID()));
|
|
|
|
|
}
|
|
|
|
|
else
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-07 16:49:38 -04:00
|
|
|
kptColors_[i] = defaultColor(words_.value(i,-1));
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-17 20:31:08 +00:00
|
|
|
qDeleteAll(rectItems_.begin(), rectItems_.end());
|
2011-11-09 15:07:19 +00:00
|
|
|
rectItems_.clear();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-24 18:07:52 -04:00
|
|
|
void ObjWidget::resetKptsWordID()
|
|
|
|
|
{
|
|
|
|
|
words_.clear();
|
|
|
|
|
for(int i=0; i<keypointItems_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
keypointItems_[i]->setWordID(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 18:08:33 +00:00
|
|
|
void ObjWidget::setKptColor(int index, const QColor & color)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
if(index < kptColors_.size())
|
|
|
|
|
{
|
|
|
|
|
kptColors_[index] = color;
|
|
|
|
|
}
|
2012-08-28 13:44:57 +00:00
|
|
|
else
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UWARN("PROBLEM index =%d > size=%d\n", index, kptColors_.size());
|
2012-08-28 13:44:57 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
if(index < keypointItems_.size())
|
|
|
|
|
{
|
2012-02-05 16:18:18 +00:00
|
|
|
QColor c = color;
|
|
|
|
|
c.setAlpha(alpha_);
|
|
|
|
|
keypointItems_.at(index)->setColor(c);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 18:07:52 -04:00
|
|
|
void ObjWidget::setKptWordID(int index, int wordID)
|
|
|
|
|
{
|
|
|
|
|
words_.insert(index, wordID);
|
|
|
|
|
if(index < keypointItems_.size())
|
|
|
|
|
{
|
|
|
|
|
keypointItems_.at(index)->setWordID(wordID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::addRect(QGraphicsRectItem * rect)
|
2011-11-09 15:07:19 +00:00
|
|
|
{
|
2011-11-17 20:31:08 +00:00
|
|
|
if(graphicsViewInitialized_)
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->scene()->addItem(rect);
|
|
|
|
|
}
|
2014-05-13 17:47:59 +00:00
|
|
|
rect->setZValue(1);
|
2012-01-05 00:31:29 +00:00
|
|
|
QPen pen = rect->pen();
|
|
|
|
|
QColor color = pen.color();
|
|
|
|
|
color.setAlpha(alpha_);
|
|
|
|
|
pen.setColor(color);
|
|
|
|
|
rect->setPen(pen);
|
2011-11-09 15:07:19 +00:00
|
|
|
rectItems_.append(rect);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
QList<QGraphicsItem*> ObjWidget::selectedItems() const
|
2011-11-09 15:07:19 +00:00
|
|
|
{
|
|
|
|
|
return graphicsView_->scene()->selectedItems();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
bool ObjWidget::isImageShown() const
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
return showImage_->isChecked();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
bool ObjWidget::isFeaturesShown() const
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
return showFeatures_->isChecked();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-28 01:00:23 +00:00
|
|
|
bool ObjWidget::isSizedFeatures() const
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
return sizedFeatures_->isChecked();
|
2012-01-28 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
bool ObjWidget::isMirrorView() const
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
return mirrorView_->isChecked();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::setDeletable(bool deletable)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
delete_->setEnabled(deletable);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-28 13:44:57 +00:00
|
|
|
void ObjWidget::setImageShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
showImage_->setChecked(shown);
|
|
|
|
|
if(graphicsViewMode_->isChecked())
|
|
|
|
|
{
|
|
|
|
|
this->updateItemsShown();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjWidget::setFeaturesShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
showFeatures_->setChecked(shown);
|
|
|
|
|
if(graphicsViewMode_->isChecked())
|
|
|
|
|
{
|
|
|
|
|
this->updateItemsShown();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 01:00:23 +00:00
|
|
|
void ObjWidget::computeScaleOffsets(float & scale, float & offsetX, float & offsetY)
|
|
|
|
|
{
|
|
|
|
|
scale = 1.0f;
|
|
|
|
|
offsetX = 0.0f;
|
|
|
|
|
offsetY = 0.0f;
|
|
|
|
|
|
2015-06-09 21:41:34 -04:00
|
|
|
if(!rect_.isNull())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
2015-06-09 21:41:34 -04:00
|
|
|
float w = rect_.width();
|
|
|
|
|
float h = rect_.height();
|
2012-01-28 01:00:23 +00:00
|
|
|
float widthRatio = float(this->rect().width()) / w;
|
|
|
|
|
float heightRatio = float(this->rect().height()) / h;
|
|
|
|
|
|
|
|
|
|
//printf("w=%f, h=%f, wR=%f, hR=%f, sW=%d, sH=%d\n", w, h, widthRatio, heightRatio, this->rect().width(), this->rect().height());
|
|
|
|
|
if(widthRatio < heightRatio)
|
|
|
|
|
{
|
|
|
|
|
scale = widthRatio;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
scale = heightRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//printf("ratio=%f\n",ratio);
|
|
|
|
|
|
|
|
|
|
w *= scale;
|
|
|
|
|
h *= scale;
|
|
|
|
|
|
|
|
|
|
if(w < this->rect().width())
|
|
|
|
|
{
|
|
|
|
|
offsetX = (this->rect().width() - w)/2.0f;
|
|
|
|
|
}
|
|
|
|
|
if(h < this->rect().height())
|
|
|
|
|
{
|
|
|
|
|
offsetY = (this->rect().height() - h)/2.0f;
|
|
|
|
|
}
|
|
|
|
|
//printf("offsetX=%f, offsetY=%f\n",offsetX, offsetY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::paintEvent(QPaintEvent *event)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-06-09 21:41:34 -04:00
|
|
|
if(!rect_.isNull())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
//Scale
|
2012-01-28 01:00:23 +00:00
|
|
|
float ratio, offsetX, offsetY;
|
|
|
|
|
this->computeScaleOffsets(ratio, offsetX, offsetY);
|
2011-10-25 15:48:19 +00:00
|
|
|
QPainter painter(this);
|
|
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
if(mirrorView_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-09 21:41:34 -04:00
|
|
|
painter.translate(offsetX+rect_.width()*ratio, offsetY);
|
2011-10-25 15:48:19 +00:00
|
|
|
painter.scale(-ratio, ratio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
painter.translate(offsetX, offsetY);
|
|
|
|
|
painter.scale(ratio, ratio);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 21:41:34 -04:00
|
|
|
if(!pixmap_.isNull() && showImage_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
painter.drawPixmap(QPoint(0,0), pixmap_);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2011-11-17 20:31:08 +00:00
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
if(showFeatures_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
drawKeypoints(&painter);
|
|
|
|
|
}
|
2011-11-09 15:07:19 +00:00
|
|
|
|
|
|
|
|
for(int i=0; i<rectItems_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
painter.save();
|
|
|
|
|
painter.setTransform(rectItems_.at(i)->transform(), true);
|
|
|
|
|
painter.setPen(rectItems_.at(i)->pen());
|
|
|
|
|
painter.drawRect(rectItems_.at(i)->rect());
|
|
|
|
|
painter.restore();
|
|
|
|
|
}
|
2011-11-17 20:31:08 +00:00
|
|
|
|
2012-01-28 01:00:23 +00:00
|
|
|
if(mouseCurrentPos_ != mousePressedPos_)
|
|
|
|
|
{
|
|
|
|
|
painter.save();
|
|
|
|
|
int left, top, right, bottom;
|
|
|
|
|
left = mousePressedPos_.x() < mouseCurrentPos_.x() ? mousePressedPos_.x():mouseCurrentPos_.x();
|
|
|
|
|
top = mousePressedPos_.y() < mouseCurrentPos_.y() ? mousePressedPos_.y():mouseCurrentPos_.y();
|
|
|
|
|
right = mousePressedPos_.x() > mouseCurrentPos_.x() ? mousePressedPos_.x():mouseCurrentPos_.x();
|
|
|
|
|
bottom = mousePressedPos_.y() > mouseCurrentPos_.y() ? mousePressedPos_.y():mouseCurrentPos_.y();
|
2012-04-04 18:15:51 +00:00
|
|
|
if(mirrorView_->isChecked())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
|
|
|
|
int l = left;
|
2015-06-09 21:41:34 -04:00
|
|
|
left = qAbs(right - rect_.width());
|
|
|
|
|
right = qAbs(l - rect_.width());
|
2012-01-28 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
|
painter.setBrush(QBrush(QColor(0,0,0,100)));
|
2015-06-09 21:41:34 -04:00
|
|
|
painter.drawRect(0, 0, rect_.width(), top);
|
2012-01-28 01:00:23 +00:00
|
|
|
painter.drawRect(0, top, left, bottom-top);
|
2015-06-09 21:41:34 -04:00
|
|
|
painter.drawRect(right, top, rect_.width()-right, bottom-top);
|
|
|
|
|
painter.drawRect(0, bottom, rect_.width(), rect_.height()-bottom);
|
2012-01-28 01:00:23 +00:00
|
|
|
painter.restore();
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::resizeEvent(QResizeEvent* event)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2011-11-15 16:37:40 +00:00
|
|
|
QWidget::resizeEvent(event);
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked() && autoScale_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
graphicsView_->fitInView(graphicsView_->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-28 01:00:23 +00:00
|
|
|
void ObjWidget::mousePressEvent(QMouseEvent * event)
|
|
|
|
|
{
|
|
|
|
|
float scale, offsetX, offsetY;
|
|
|
|
|
this->computeScaleOffsets(scale, offsetX, offsetY);
|
|
|
|
|
mousePressedPos_.setX((event->pos().x()-offsetX)/scale);
|
|
|
|
|
mousePressedPos_.setY((event->pos().y()-offsetY)/scale);
|
|
|
|
|
mouseCurrentPos_ = mousePressedPos_;
|
|
|
|
|
this->update();
|
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjWidget::mouseMoveEvent(QMouseEvent * event)
|
|
|
|
|
{
|
|
|
|
|
float scale, offsetX, offsetY;
|
|
|
|
|
this->computeScaleOffsets(scale, offsetX, offsetY);
|
|
|
|
|
mouseCurrentPos_.setX((event->pos().x()-offsetX)/scale);
|
|
|
|
|
mouseCurrentPos_.setY((event->pos().y()-offsetY)/scale);
|
|
|
|
|
this->update();
|
|
|
|
|
QWidget::mouseMoveEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjWidget::mouseReleaseEvent(QMouseEvent * event)
|
|
|
|
|
{
|
2015-06-09 21:41:34 -04:00
|
|
|
if(!rect_.isNull())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
|
|
|
|
int left,top,bottom,right;
|
|
|
|
|
|
|
|
|
|
left = mousePressedPos_.x() < mouseCurrentPos_.x() ? mousePressedPos_.x():mouseCurrentPos_.x();
|
|
|
|
|
top = mousePressedPos_.y() < mouseCurrentPos_.y() ? mousePressedPos_.y():mouseCurrentPos_.y();
|
|
|
|
|
right = mousePressedPos_.x() > mouseCurrentPos_.x() ? mousePressedPos_.x():mouseCurrentPos_.x();
|
|
|
|
|
bottom = mousePressedPos_.y() > mouseCurrentPos_.y() ? mousePressedPos_.y():mouseCurrentPos_.y();
|
|
|
|
|
|
2012-04-04 18:15:51 +00:00
|
|
|
if(mirrorView_->isChecked())
|
2012-01-28 01:00:23 +00:00
|
|
|
{
|
|
|
|
|
int l = left;
|
2015-06-09 21:41:34 -04:00
|
|
|
left = qAbs(right - rect_.width());
|
|
|
|
|
right = qAbs(l - rect_.width());
|
2012-01-28 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
Q_EMIT roiChanged(cv::Rect(left, top, right-left, bottom-top));
|
2012-01-28 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
QWidget::mouseReleaseEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::contextMenuEvent(QContextMenuEvent * event)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
QAction * action = menu_->exec(event->globalPos());
|
|
|
|
|
if(action == saveImage_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QString text;
|
2012-04-04 18:15:51 +00:00
|
|
|
if(savedFileName_.isEmpty())
|
2011-11-09 20:48:04 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
savedFileName_=Settings::workingDirectory()+"/figure.png";
|
2011-11-09 20:48:04 +00:00
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
text = QFileDialog::getSaveFileName(this, tr("Save figure to ..."), savedFileName_, "*.png *.xpm *.jpg *.pdf");
|
2011-10-25 15:48:19 +00:00
|
|
|
if(!text.isEmpty())
|
|
|
|
|
{
|
2011-11-09 20:48:04 +00:00
|
|
|
if(!text.endsWith(".png") && !text.endsWith(".xpm") && !text.endsWith(".jpg") && !text.endsWith(".pdf"))
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
text.append(".png");//default
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
savedFileName_ = text;
|
2011-10-25 15:48:19 +00:00
|
|
|
getSceneAsPixmap().save(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == showFeatures_ || action == showImage_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
this->updateItemsShown();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == mirrorView_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
this->setMirrorView(mirrorView_->isChecked());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == delete_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT removalTriggered(this);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == graphicsViewMode_)
|
2011-11-17 20:31:08 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
this->setGraphicsViewMode(graphicsViewMode_->isChecked());
|
2011-11-17 20:31:08 +00:00
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == autoScale_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
this->setAutoScale(autoScale_->isChecked());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == sizedFeatures_)
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
this->setSizedFeatures(sizedFeatures_->isChecked());
|
2011-11-18 16:09:23 +00:00
|
|
|
}
|
2014-08-03 22:23:02 +00:00
|
|
|
else if(action == setColor_)
|
|
|
|
|
{
|
|
|
|
|
QColor color = QColorDialog::getColor(color_, this);
|
|
|
|
|
if(color.isValid())
|
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<kptColors_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(kptColors_[i] == color_)
|
|
|
|
|
{
|
|
|
|
|
kptColors_[i] = color;
|
|
|
|
|
if(graphicsViewMode_->isChecked())
|
|
|
|
|
{
|
|
|
|
|
keypointItems_[i]->setColor(color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(int i=0; i<rectItems_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(rectItems_[i]->pen().color() == color_)
|
|
|
|
|
{
|
|
|
|
|
QPen p = rectItems_[i]->pen();
|
|
|
|
|
p.setColor(color);
|
|
|
|
|
rectItems_[i]->setPen(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
color_ = color;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 18:15:51 +00:00
|
|
|
else if(action == setAlpha_)
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
|
|
|
|
bool ok;
|
|
|
|
|
int newAlpha = QInputDialog::getInt(this, tr("Set alpha"), tr("Alpha:"), alpha_, 0, 255, 5, &ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
this->setAlpha(newAlpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
QPixmap ObjWidget::getSceneAsPixmap()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QPixmap img(graphicsView_->sceneRect().width(), graphicsView_->sceneRect().height());
|
|
|
|
|
QPainter p(&img);
|
|
|
|
|
graphicsView_->scene()->render(&p, graphicsView_->sceneRect(), graphicsView_->sceneRect());
|
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return QPixmap::grabWidget(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::updateItemsShown()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QList<QGraphicsItem*> items = graphicsView_->scene()->items();
|
|
|
|
|
for(int i=0; i<items.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
items.at(i)->setVisible(showFeatures_->isChecked());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
else if(qgraphicsitem_cast<QGraphicsPixmapItem*>(items.at(i)))
|
|
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
items.at(i)->setVisible(showImage_->isChecked());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::drawKeypoints(QPainter * painter)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QList<KeypointItem *> items;
|
|
|
|
|
KeypointItem * item = 0;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(std::vector<cv::KeyPoint>::const_iterator iter = keypoints_.begin(); iter != keypoints_.end(); ++iter, ++i )
|
|
|
|
|
{
|
|
|
|
|
const cv::KeyPoint & r = *iter;
|
2011-11-18 16:09:23 +00:00
|
|
|
float size = 14;
|
2012-04-04 18:15:51 +00:00
|
|
|
if(r.size>14.0f && sizedFeatures_->isChecked())
|
2011-11-18 16:09:23 +00:00
|
|
|
{
|
|
|
|
|
size = r.size;
|
|
|
|
|
}
|
|
|
|
|
float radius = size*1.2f/9.0f*2.0f;
|
|
|
|
|
QColor color(kptColors_.at(i).red(), kptColors_.at(i).green(), kptColors_.at(i).blue(), alpha_);
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
// YELLOW = NEW and multiple times
|
2015-06-24 18:07:52 -04:00
|
|
|
item = new KeypointItem(i, r.pt.x-radius, r.pt.y-radius, radius*2, r, words_.value(i, -1), color);
|
2011-10-25 15:48:19 +00:00
|
|
|
item->setVisible(this->isFeaturesShown());
|
2014-05-13 17:47:59 +00:00
|
|
|
item->setZValue(2);
|
2011-10-25 15:48:19 +00:00
|
|
|
graphicsView_->scene()->addItem(item);
|
2015-07-07 16:49:38 -04:00
|
|
|
item->setColor(defaultColor(item->wordID()));
|
|
|
|
|
kptColors_[i] = defaultColor(item->wordID());
|
2011-10-25 15:48:19 +00:00
|
|
|
keypointItems_.append(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(painter)
|
|
|
|
|
{
|
|
|
|
|
painter->save();
|
2011-11-18 16:09:23 +00:00
|
|
|
painter->setPen(color);
|
|
|
|
|
painter->setBrush(color);
|
2011-10-25 15:48:19 +00:00
|
|
|
painter->drawEllipse(r.pt.x-radius, r.pt.y-radius, radius*2, radius*2);
|
|
|
|
|
painter->restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 16:49:38 -04:00
|
|
|
QColor ObjWidget::defaultColor(int id) const
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-07 16:49:38 -04:00
|
|
|
QColor color(id >= 0 ? Qt::yellow : Qt::white);
|
2011-11-18 16:09:23 +00:00
|
|
|
color.setAlpha(alpha_);
|
|
|
|
|
return color;
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
std::vector<cv::KeyPoint> ObjWidget::selectedKeypoints() const
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
std::vector<cv::KeyPoint> selected;
|
2012-04-04 18:15:51 +00:00
|
|
|
if(graphicsViewMode_->isChecked())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QList<QGraphicsItem*> items = graphicsView_->scene()->selectedItems();
|
|
|
|
|
for(int i=0; i<items.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
|
|
|
|
|
{
|
2015-06-24 18:07:52 -04:00
|
|
|
selected.push_back(keypoints_.at(((KeypointItem*)items.at(i))->id()));
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return selected;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:37:40 +00:00
|
|
|
void ObjWidget::setupGraphicsView()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-09 21:41:34 -04:00
|
|
|
if(!rect_.isNull())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
graphicsView_->setVisible(true);
|
2015-06-09 21:41:34 -04:00
|
|
|
graphicsView_->scene()->setSceneRect(rect_);
|
2011-11-15 16:37:40 +00:00
|
|
|
QList<KeypointItem*> items;
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
QRectF sceneRect = graphicsView_->sceneRect();
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
QGraphicsPixmapItem * pixmapItem = graphicsView_->scene()->addPixmap(pixmap_);
|
|
|
|
|
pixmapItem->setVisible(this->isImageShown());
|
|
|
|
|
this->drawKeypoints();
|
2011-11-17 20:31:08 +00:00
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
for(int i=0; i<rectItems_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->scene()->addItem(rectItems_.at(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(autoScale_->isChecked())
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->fitInView(sceneRect, Qt::KeepAspectRatio);
|
2011-11-15 16:37:40 +00:00
|
|
|
}
|
2011-11-17 20:31:08 +00:00
|
|
|
graphicsViewInitialized_ = true;
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
graphicsView_->setVisible(false);
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
} // namespace find_object
|
|
|
|
|
|