Added SetColor menu option to ObjWidget

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@367 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-08-03 22:23:02 +00:00
parent 9829b29dd0
commit 970b9e95aa
4 changed files with 51 additions and 16 deletions

View File

@ -47,6 +47,7 @@ public:
void clearRoiSelection() {mousePressedPos_ = mouseCurrentPos_ = QPoint();update();} void clearRoiSelection() {mousePressedPos_ = mouseCurrentPos_ = QPoint();update();}
int id() const {return id_;} int id() const {return id_;}
const QColor & color() const {return color_;}
const std::vector<cv::KeyPoint> keypoints() const {return keypoints_;} const std::vector<cv::KeyPoint> keypoints() const {return keypoints_;}
const QPixmap & pixmap() const {return pixmap_;} const QPixmap & pixmap() const {return pixmap_;}
QColor defaultColor() const; QColor defaultColor() const;
@ -91,6 +92,7 @@ private:
bool graphicsViewInitialized_; bool graphicsViewInitialized_;
int alpha_; int alpha_;
QLabel * label_; QLabel * label_;
QColor color_;
// menu stuff // menu stuff
QString savedFileName_; QString savedFileName_;
@ -104,6 +106,7 @@ private:
QAction * autoScale_; QAction * autoScale_;
QAction * sizedFeatures_; QAction * sizedFeatures_;
QAction * setAlpha_; QAction * setAlpha_;
QAction * setColor_;
// selection stuff // selection stuff
QPoint mousePressedPos_; QPoint mousePressedPos_;

View File

@ -663,6 +663,7 @@ bool FindObject::detect(const cv::Mat & image, QMultiMap<int,QPair<QRect,QTransf
detector_->detect(grayscaleImg, sceneKeypoints_); detector_->detect(grayscaleImg, sceneKeypoints_);
timeStamps_.insert(kTimeKeypointDetection, time.restart()); timeStamps_.insert(kTimeKeypointDetection, time.restart());
bool emptyScene = sceneKeypoints_.size() == 0;
if(sceneKeypoints_.size()) if(sceneKeypoints_.size())
{ {
int maxFeatures = Settings::getFeature2D_3MaxFeatures(); int maxFeatures = Settings::getFeature2D_3MaxFeatures();
@ -678,10 +679,6 @@ bool FindObject::detect(const cv::Mat & image, QMultiMap<int,QPair<QRect,QTransf
UERROR("kpt=%d != descriptors=%d", (int)sceneKeypoints_.size(), sceneDescriptors_.rows); UERROR("kpt=%d != descriptors=%d", (int)sceneKeypoints_.size(), sceneDescriptors_.rows);
} }
} }
else
{
UWARN("no features detected !?!");
}
timeStamps_.insert(kTimeDescriptorExtraction, time.restart()); timeStamps_.insert(kTimeDescriptorExtraction, time.restart());
bool consistentNNData = (vocabulary_->size()!=0 && vocabulary_->wordToObjects().begin().value()!=-1 && Settings::getGeneral_invertedSearch()) || bool consistentNNData = (vocabulary_->size()!=0 && vocabulary_->wordToObjects().begin().value()!=-1 && Settings::getGeneral_invertedSearch()) ||
@ -938,6 +935,12 @@ bool FindObject::detect(const cv::Mat & image, QMultiMap<int,QPair<QRect,QTransf
{ {
UWARN("Cannot search, objects must be updated"); UWARN("Cannot search, objects must be updated");
} }
else if(emptyScene)
{
// Accept but warn the user
UWARN("No features detected in the scene!?!");
success = true;
}
} }
objectsDetected_ = objectsDetected; objectsDetected_ = objectsDetected;

View File

@ -950,12 +950,10 @@ void MainWindow::update(const cv::Mat & image)
ObjWidget * obj = objWidgets_.value(id); ObjWidget * obj = objWidgets_.value(id);
Q_ASSERT(obj != 0); Q_ASSERT(obj != 0);
int nColor = id % 11 + 7;
QColor color((Qt::GlobalColor)(nColor==Qt::yellow?Qt::gray:nColor));
for(QMultiMap<int, int>::const_iterator iter = jter.value().constBegin(); iter!= jter.value().constEnd(); ++iter) for(QMultiMap<int, int>::const_iterator iter = jter.value().constBegin(); iter!= jter.value().constEnd(); ++iter)
{ {
obj->setKptColor(iter.key(), color); obj->setKptColor(iter.key(), obj->color());
ui_->imageView_source->setKptColor(iter.value(), color); ui_->imageView_source->setKptColor(iter.value(), obj->color());
} }
} }
else if(!objectsDetected.contains(id)) else if(!objectsDetected.contains(id))
@ -992,14 +990,11 @@ void MainWindow::update(const cv::Mat & image)
Q_ASSERT(obj != 0); Q_ASSERT(obj != 0);
// COLORIZE (should be done in the GUI thread) // COLORIZE (should be done in the GUI thread)
int nColor = id % 11 + 7;
QColor color((Qt::GlobalColor)(nColor==Qt::yellow?Qt::gray:nColor));
QTransform hTransform = iter.value().second; QTransform hTransform = iter.value().second;
QRect rect = obj->pixmap().rect(); QRect rect = obj->pixmap().rect();
// add rectangle // add rectangle
QPen rectPen(color); QPen rectPen(obj->color());
rectPen.setWidth(Settings::getHomography_rectBorderWidth()); rectPen.setWidth(Settings::getHomography_rectBorderWidth());
RectItem * rectItemScene = new RectItem(id, rect); RectItem * rectItemScene = new RectItem(id, rect);
connect(rectItemScene, SIGNAL(hovered(int)), this, SLOT(rectHovered(int))); connect(rectItemScene, SIGNAL(hovered(int)), this, SLOT(rectHovered(int)));
@ -1013,8 +1008,8 @@ void MainWindow::update(const cv::Mat & image)
for(QMultiMap<int, int>::const_iterator iter = inliersIter.value().constBegin(); iter!= inliersIter.value().constEnd(); ++iter) for(QMultiMap<int, int>::const_iterator iter = inliersIter.value().constBegin(); iter!= inliersIter.value().constEnd(); ++iter)
{ {
obj->setKptColor(iter.key(), color); obj->setKptColor(iter.key(), obj->color());
ui_->imageView_source->setKptColor(iter.value(), color); ui_->imageView_source->setKptColor(iter.value(), obj->color());
} }
QLabel * label = ui_->dockWidget_objects->findChild<QLabel*>(QString("%1detection").arg(id)); QLabel * label = ui_->dockWidget_objects->findChild<QLabel*>(QString("%1detection").arg(id));

View File

@ -24,6 +24,7 @@
#include <QtGui/QInputDialog> #include <QtGui/QInputDialog>
#include <QtGui/QPen> #include <QtGui/QPen>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QColorDialog>
#include <QtCore/QDir> #include <QtCore/QDir>
@ -34,7 +35,8 @@ ObjWidget::ObjWidget(QWidget * parent) :
id_(0), id_(0),
graphicsView_(0), graphicsView_(0),
graphicsViewInitialized_(false), graphicsViewInitialized_(false),
alpha_(100) alpha_(100),
color_(Qt::red)
{ {
setupUi(); setupUi();
} }
@ -43,7 +45,8 @@ ObjWidget::ObjWidget(int id, const std::vector<cv::KeyPoint> & keypoints, const
id_(id), id_(id),
graphicsView_(0), graphicsView_(0),
graphicsViewInitialized_(false), graphicsViewInitialized_(false),
alpha_(100) alpha_(100),
color_(QColor((Qt::GlobalColor)((id % 11 + 7)==Qt::yellow?Qt::gray:(id % 11 + 7))))
{ {
setupUi(); setupUi();
this->setData(keypoints, image); this->setData(keypoints, image);
@ -89,6 +92,7 @@ void ObjWidget::setupUi()
sizedFeatures_->setCheckable(true); sizedFeatures_->setCheckable(true);
sizedFeatures_->setChecked(false); sizedFeatures_->setChecked(false);
menu_->addSeparator(); menu_->addSeparator();
setColor_ = menu_->addAction(tr("Set color..."));
setAlpha_ = menu_->addAction(tr("Set alpha...")); setAlpha_ = menu_->addAction(tr("Set alpha..."));
menu_->addSeparator(); menu_->addSeparator();
saveImage_ = menu_->addAction(tr("Save picture...")); saveImage_ = menu_->addAction(tr("Save picture..."));
@ -106,6 +110,7 @@ void ObjWidget::setupUi()
void ObjWidget::setId(int id) void ObjWidget::setId(int id)
{ {
color_ = QColor((Qt::GlobalColor)((id % 11 + 7)==Qt::yellow?Qt::gray:(id % 11 + 7)));
id_=id; id_=id;
if(id_) if(id_)
{ {
@ -575,6 +580,35 @@ void ObjWidget::contextMenuEvent(QContextMenuEvent * event)
{ {
this->setSizedFeatures(sizedFeatures_->isChecked()); this->setSizedFeatures(sizedFeatures_->isChecked());
} }
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;
}
}
else if(action == setAlpha_) else if(action == setAlpha_)
{ {
bool ok; bool ok;