From ab8fb21b3827f061660c7d21b468b8dbedb97cd1 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Wed, 9 Nov 2011 15:07:19 +0000 Subject: [PATCH] Added rectangles to the plain view git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@14 620bd6b2-0a58-f614-fd9a-1bd335dccda9 --- src/AddObjectDialog.cpp | 4 ++-- src/MainWindow.cpp | 6 +++++- src/Object.cpp | 31 +++++++++++++++++++++++++------ src/Object.h | 8 +++++++- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/AddObjectDialog.cpp b/src/AddObjectDialog.cpp index a684bb2c..0983d61f 100644 --- a/src/AddObjectDialog.cpp +++ b/src/AddObjectDialog.cpp @@ -33,7 +33,7 @@ AddObjectDialog::AddObjectDialog(QList * objects, QWidget * parent, Qt: connect(ui_->pushButton_next, SIGNAL(clicked()), this, SLOT(next())); connect(ui_->pushButton_takePicture, SIGNAL(clicked()), this, SLOT(takePicture())); - connect(ui_->cameraView->scene(), SIGNAL(selectionChanged()), this, SLOT(updateNextButton())); + connect(ui_->cameraView, SIGNAL(selectionChanged()), this, SLOT(updateNextButton())); this->setState(kTakePicture); } @@ -77,7 +77,7 @@ void AddObjectDialog::updateNextButton() { if(state_ == kSelectFeatures) { - if(ui_->cameraView->scene()->selectedItems().size() > 0) + if(ui_->cameraView->selectedItems().size() > 0) { ui_->pushButton_next->setEnabled(true); } diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 77064999..e5334ff2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -20,6 +20,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent), @@ -430,8 +431,11 @@ void MainWindow::update() H.at(0,2), H.at(1,2), H.at(2,2)); QPen rectPen(color); rectPen.setWidth(4); - QGraphicsRectItem * rectItem = ui_->imageView_source->scene()->addRect(objects_.at(j)->image().rect(), rectPen); + QGraphicsRectItem * rectItem = new QGraphicsRectItem(objects_.at(j)->image().rect()); + rectItem->setPen(rectPen); rectItem->setTransform(hTransform); + ui_->imageView_source->addRect(rectItem); + } else { diff --git a/src/Object.cpp b/src/Object.cpp index 7ff154c3..4e5688a2 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -104,6 +105,8 @@ void Object::setupUi() graphicsView_->setRubberBandSelectionMode(Qt::ContainsItemShape); graphicsView_->setDragMode(QGraphicsView::RubberBandDrag); + + connect(graphicsView_->scene(), SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); } void Object::setId(int id) @@ -139,13 +142,13 @@ void Object::setGraphicsViewMode(bool on) this->update(); } -// ownership transferred void Object::setData(const std::vector & keypoints, const cv::Mat & descriptors, const IplImage * image) { keypoints_ = keypoints; descriptors_ = descriptors; kptColors_ = QVector(keypoints.size(), defaultColor()); keypointItems_.clear(); + rectItems_.clear(); if(iplImage_) { cvReleaseImage(&iplImage_); @@ -181,6 +184,7 @@ void Object::resetKptsColor() keypointItems_[i]->setColor(this->defaultColor()); } } + rectItems_.clear(); } void Object::setKptColor(unsigned int index, const QColor & color) @@ -199,6 +203,17 @@ void Object::setKptColor(unsigned int index, const QColor & color) } } +void Object::addRect(QGraphicsRectItem * rect) +{ + graphicsView_->scene()->addItem(rect); + rectItems_.append(rect); +} + +QList Object::selectedItems() const +{ + return graphicsView_->scene()->selectedItems(); +} + bool Object::isImageShown() const { return _showImage->isChecked(); @@ -214,11 +229,6 @@ bool Object::isMirrorView() const return _mirrorView->isChecked(); } -QGraphicsScene * Object::scene() const -{ - return graphicsView_->scene(); -} - void Object::setDeletable(bool deletable) { _delete->setEnabled(deletable); @@ -343,6 +353,15 @@ void Object::paintEvent(QPaintEvent *event) { drawKeypoints(&painter); } + + for(int i=0; itransform(), true); + painter.setPen(rectItems_.at(i)->pen()); + painter.drawRect(rectItems_.at(i)->rect()); + painter.restore(); + } } } } diff --git a/src/Object.h b/src/Object.h index d2cc0707..ced37db5 100644 --- a/src/Object.h +++ b/src/Object.h @@ -17,6 +17,8 @@ class QAction; class QMenu; class QGraphicsView; class QGraphicsScene; +class QGraphicsRectItem; +class QGraphicsItem; class Object : public QWidget { @@ -41,6 +43,7 @@ public: void setKptColor(unsigned int index, const QColor & color); void setGraphicsViewMode(bool on); void setDeletable(bool deletable); + void addRect(QGraphicsRectItem * rect); const std::vector & keypoints() const {return keypoints_;} const cv::Mat & descriptors() const {return descriptors_;} @@ -51,10 +54,11 @@ public: bool isImageShown() const; bool isFeaturesShown() const; bool isMirrorView() const; - QGraphicsScene * scene() const; + //QGraphicsScene * scene() const; std::vector selectedKeypoints() const; const QString & detectorType() const {return detectorType_;} const QString & descriptorType() const {return descriptorType_;} + QList selectedItems() const; QPixmap getSceneAsPixmap(); @@ -68,6 +72,7 @@ protected: signals: void removalTriggered(Object *); + void selectionChanged(); private: void setupGraphicsView(); @@ -87,6 +92,7 @@ private: QVector kptColors_; QString detectorType_; QString descriptorType_; + QList rectItems_; // menu stuff QString _savedFileName;