Added rectangles to the plain view
git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@14 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
parent
883f1dd5bc
commit
ab8fb21b38
@ -33,7 +33,7 @@ AddObjectDialog::AddObjectDialog(QList<Object*> * 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);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtGui/QGraphicsRectItem>
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent) :
|
||||
QMainWindow(parent),
|
||||
@ -430,8 +431,11 @@ void MainWindow::update()
|
||||
H.at<double>(0,2), H.at<double>(1,2), H.at<double>(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
|
||||
{
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include <QtGui/QGraphicsView>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QGraphicsRectItem>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
|
||||
@ -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<cv::KeyPoint> & keypoints, const cv::Mat & descriptors, const IplImage * image)
|
||||
{
|
||||
keypoints_ = keypoints;
|
||||
descriptors_ = descriptors;
|
||||
kptColors_ = QVector<QColor>(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<QGraphicsItem*> 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; 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<cv::KeyPoint> & 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<cv::KeyPoint> selectedKeypoints() const;
|
||||
const QString & detectorType() const {return detectorType_;}
|
||||
const QString & descriptorType() const {return descriptorType_;}
|
||||
QList<QGraphicsItem*> selectedItems() const;
|
||||
|
||||
QPixmap getSceneAsPixmap();
|
||||
|
||||
@ -68,6 +72,7 @@ protected:
|
||||
|
||||
signals:
|
||||
void removalTriggered(Object *);
|
||||
void selectionChanged();
|
||||
|
||||
private:
|
||||
void setupGraphicsView();
|
||||
@ -87,6 +92,7 @@ private:
|
||||
QVector<QColor> kptColors_;
|
||||
QString detectorType_;
|
||||
QString descriptorType_;
|
||||
QList<QGraphicsRectItem*> rectItems_;
|
||||
|
||||
// menu stuff
|
||||
QString _savedFileName;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user