Added signal when an object is detected (id + pos)
git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@39 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
parent
541558a57a
commit
13f493aa5c
@ -64,7 +64,7 @@ MainWindow::MainWindow(Camera * camera, QWidget * parent) :
|
||||
// Actions
|
||||
connect(ui_->actionAdd_object, SIGNAL(triggered()), this, SLOT(addObject()));
|
||||
connect(ui_->actionStart_camera, SIGNAL(triggered()), this, SLOT(startCamera()));
|
||||
connect(ui_->actionStop_camera, SIGNAL(triggered()), this, SLOT(stopCamera()));
|
||||
connect(ui_->actionStop_camera, SIGNAL(triggered()), this, SLOT(stopProcessing()));
|
||||
connect(ui_->actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
connect(ui_->actionSave_objects, SIGNAL(triggered()), this, SLOT(saveObjects()));
|
||||
connect(ui_->actionLoad_objects, SIGNAL(triggered()), this, SLOT(loadObjects()));
|
||||
@ -86,11 +86,8 @@ void MainWindow::closeEvent(QCloseEvent * event)
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::loadObjects()
|
||||
void MainWindow::loadObjects(const QString & fileName)
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Load objects..."), Settings::workingDirectory(), "*.obj");
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QDataStream in(&file);
|
||||
@ -118,6 +115,26 @@ void MainWindow::loadObjects()
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void MainWindow::saveObjects(const QString & fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QDataStream out(&file);
|
||||
for(int i=0; i<objects_.size(); ++i)
|
||||
{
|
||||
objects_.at(i)->save(out);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void MainWindow::loadObjects()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Load objects..."), Settings::workingDirectory(), "*.obj");
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
loadObjects(fileName);
|
||||
}
|
||||
}
|
||||
void MainWindow::saveObjects()
|
||||
@ -129,15 +146,7 @@ void MainWindow::saveObjects()
|
||||
{
|
||||
fileName.append(".obj");//default
|
||||
}
|
||||
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QDataStream out(&file);
|
||||
for(int i=0; i<objects_.size(); ++i)
|
||||
{
|
||||
objects_.at(i)->save(out);
|
||||
}
|
||||
file.close();
|
||||
saveObjects(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +162,7 @@ void MainWindow::removeObject(ObjWidget * object)
|
||||
|
||||
void MainWindow::addObject()
|
||||
{
|
||||
this->stopCamera();
|
||||
this->stopProcessing();
|
||||
AddObjectDialog dialog(camera_, &objects_, this);
|
||||
if(dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
@ -255,7 +264,7 @@ void MainWindow::updateData()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::startCamera()
|
||||
void MainWindow::startProcessing()
|
||||
{
|
||||
if(camera_->start())
|
||||
{
|
||||
@ -269,7 +278,7 @@ void MainWindow::startCamera()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::stopCamera()
|
||||
void MainWindow::stopProcessing()
|
||||
{
|
||||
if(camera_)
|
||||
{
|
||||
@ -354,11 +363,15 @@ void MainWindow::update(const cv::Mat & image)
|
||||
|
||||
|
||||
// PROCESS RESULTS
|
||||
if(this->isVisible())
|
||||
{
|
||||
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
||||
}
|
||||
int j=0;
|
||||
std::vector<cv::Point2f> mpts_1, mpts_2;
|
||||
std::vector<int> indexes_1, indexes_2;
|
||||
std::vector<uchar> outlier_mask;
|
||||
QMap<int, QPoint> objectsPos;
|
||||
for(int i=0; i<dataTree_.rows; ++i)
|
||||
{
|
||||
// Check if this descriptor matches with those of the objects
|
||||
@ -375,7 +388,7 @@ void MainWindow::update(const cv::Mat & image)
|
||||
mpts_1.push_back(objects_.at(j)->keypoints().at(i).pt);
|
||||
indexes_1.push_back(i);
|
||||
}
|
||||
mpts_2.push_back(ui_->imageView_source->keypoints().at(results.at<int>(i,0)).pt);
|
||||
mpts_2.push_back(keypoints.at(results.at<int>(i,0)).pt);
|
||||
indexes_2.push_back(results.at<int>(i,0));
|
||||
}
|
||||
|
||||
@ -406,6 +419,8 @@ void MainWindow::update(const cv::Mat & image)
|
||||
|
||||
// COLORIZE
|
||||
if(inliers >= Settings::getHomography_minimumInliers().toInt())
|
||||
{
|
||||
if(this->isVisible())
|
||||
{
|
||||
for(unsigned int k=0; k<mpts_1.size();++k)
|
||||
{
|
||||
@ -419,19 +434,29 @@ void MainWindow::update(const cv::Mat & image)
|
||||
objects_.at(j)->setKptColor(indexes_1.at(k), QColor(0,0,0,alpha));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
label->setText(QString("%1 in %2 out").arg(inliers).arg(outliers));
|
||||
QTransform hTransform(
|
||||
H.at<double>(0,0), H.at<double>(1,0), H.at<double>(2,0),
|
||||
H.at<double>(0,1), H.at<double>(1,1), H.at<double>(2,1),
|
||||
H.at<double>(0,2), H.at<double>(1,2), H.at<double>(2,2));
|
||||
|
||||
// find center of object
|
||||
QRect rect = objects_.at(j)->image().rect();
|
||||
QPoint pos(rect.width()/2, rect.height()/2);
|
||||
objectsPos.insert(objects_.at(j)->id(), hTransform.map(pos));
|
||||
|
||||
// add rectangle
|
||||
if(this->isVisible())
|
||||
{
|
||||
label->setText(QString("%1 in %2 out").arg(inliers).arg(outliers));
|
||||
QPen rectPen(color);
|
||||
rectPen.setWidth(4);
|
||||
QGraphicsRectItem * rectItem = new QGraphicsRectItem(objects_.at(j)->image().rect());
|
||||
QGraphicsRectItem * rectItem = new QGraphicsRectItem(rect);
|
||||
rectItem->setPen(rectPen);
|
||||
rectItem->setTransform(hTransform);
|
||||
ui_->imageView_source->addRect(rectItem);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -450,17 +475,25 @@ void MainWindow::update(const cv::Mat & image)
|
||||
++j;
|
||||
}
|
||||
}
|
||||
|
||||
if(objectsPos.size())
|
||||
{
|
||||
emit objectsFound(objectsPos);
|
||||
}
|
||||
else
|
||||
}
|
||||
else if(this->isVisible())
|
||||
{
|
||||
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
||||
}
|
||||
|
||||
if(this->isVisible())
|
||||
{
|
||||
//Update object pictures
|
||||
for(int i=0; i<objects_.size(); ++i)
|
||||
{
|
||||
objects_[i]->update();
|
||||
}
|
||||
}
|
||||
|
||||
ui_->label_nfeatures->setText(QString::number(keypoints.size()));
|
||||
ui_->imageView_source->update();
|
||||
|
||||
@ -26,21 +26,27 @@ public:
|
||||
MainWindow(Camera * camera = 0, QWidget * parent = 0);
|
||||
virtual ~MainWindow();
|
||||
|
||||
void loadObjects(const QString & fileName);
|
||||
void saveObjects(const QString & fileName);
|
||||
void startProcessing();
|
||||
void stopProcessing();
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent * event);
|
||||
|
||||
private slots:
|
||||
void addObject();
|
||||
void startCamera();
|
||||
void stopCamera();
|
||||
void loadObjects();
|
||||
void saveObjects();
|
||||
void update(const cv::Mat & image);
|
||||
void updateData();
|
||||
void removeObject(ObjWidget * object);
|
||||
void update(const cv::Mat & image);
|
||||
|
||||
signals:
|
||||
void objectsFound(const QMap<int, QPoint> &);
|
||||
|
||||
private:
|
||||
void addObject();
|
||||
void showObject(ObjWidget * obj);
|
||||
void updateData();
|
||||
|
||||
private:
|
||||
Ui_mainWindow * ui_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user