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
|
// Actions
|
||||||
connect(ui_->actionAdd_object, SIGNAL(triggered()), this, SLOT(addObject()));
|
connect(ui_->actionAdd_object, SIGNAL(triggered()), this, SLOT(addObject()));
|
||||||
connect(ui_->actionStart_camera, SIGNAL(triggered()), this, SLOT(startCamera()));
|
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_->actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
connect(ui_->actionSave_objects, SIGNAL(triggered()), this, SLOT(saveObjects()));
|
connect(ui_->actionSave_objects, SIGNAL(triggered()), this, SLOT(saveObjects()));
|
||||||
connect(ui_->actionLoad_objects, SIGNAL(triggered()), this, SLOT(loadObjects()));
|
connect(ui_->actionLoad_objects, SIGNAL(triggered()), this, SLOT(loadObjects()));
|
||||||
@ -86,38 +86,55 @@ void MainWindow::closeEvent(QCloseEvent * event)
|
|||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadObjects(const QString & fileName)
|
||||||
|
{
|
||||||
|
QFile file(fileName);
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
QDataStream in(&file);
|
||||||
|
while(!in.atEnd())
|
||||||
|
{
|
||||||
|
ObjWidget * obj = new ObjWidget();
|
||||||
|
obj->load(in);
|
||||||
|
bool alreadyLoaded = false;
|
||||||
|
for(int i=0; i<objects_.size(); ++i)
|
||||||
|
{
|
||||||
|
if(objects_.at(i)->id() == obj->id())
|
||||||
|
{
|
||||||
|
alreadyLoaded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!alreadyLoaded)
|
||||||
|
{
|
||||||
|
objects_.append(obj);
|
||||||
|
showObject(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()
|
void MainWindow::loadObjects()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Load objects..."), Settings::workingDirectory(), "*.obj");
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Load objects..."), Settings::workingDirectory(), "*.obj");
|
||||||
if(!fileName.isEmpty())
|
if(!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
loadObjects(fileName);
|
||||||
file.open(QIODevice::ReadOnly);
|
|
||||||
QDataStream in(&file);
|
|
||||||
while(!in.atEnd())
|
|
||||||
{
|
|
||||||
ObjWidget * obj = new ObjWidget();
|
|
||||||
obj->load(in);
|
|
||||||
bool alreadyLoaded = false;
|
|
||||||
for(int i=0; i<objects_.size(); ++i)
|
|
||||||
{
|
|
||||||
if(objects_.at(i)->id() == obj->id())
|
|
||||||
{
|
|
||||||
alreadyLoaded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!alreadyLoaded)
|
|
||||||
{
|
|
||||||
objects_.append(obj);
|
|
||||||
showObject(obj);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MainWindow::saveObjects()
|
void MainWindow::saveObjects()
|
||||||
@ -129,15 +146,7 @@ void MainWindow::saveObjects()
|
|||||||
{
|
{
|
||||||
fileName.append(".obj");//default
|
fileName.append(".obj");//default
|
||||||
}
|
}
|
||||||
|
saveObjects(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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +162,7 @@ void MainWindow::removeObject(ObjWidget * object)
|
|||||||
|
|
||||||
void MainWindow::addObject()
|
void MainWindow::addObject()
|
||||||
{
|
{
|
||||||
this->stopCamera();
|
this->stopProcessing();
|
||||||
AddObjectDialog dialog(camera_, &objects_, this);
|
AddObjectDialog dialog(camera_, &objects_, this);
|
||||||
if(dialog.exec() == QDialog::Accepted)
|
if(dialog.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
@ -255,7 +264,7 @@ void MainWindow::updateData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::startCamera()
|
void MainWindow::startProcessing()
|
||||||
{
|
{
|
||||||
if(camera_->start())
|
if(camera_->start())
|
||||||
{
|
{
|
||||||
@ -269,7 +278,7 @@ void MainWindow::startCamera()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::stopCamera()
|
void MainWindow::stopProcessing()
|
||||||
{
|
{
|
||||||
if(camera_)
|
if(camera_)
|
||||||
{
|
{
|
||||||
@ -354,11 +363,15 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
|
|
||||||
|
|
||||||
// PROCESS RESULTS
|
// PROCESS RESULTS
|
||||||
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
if(this->isVisible())
|
||||||
|
{
|
||||||
|
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
||||||
|
}
|
||||||
int j=0;
|
int j=0;
|
||||||
std::vector<cv::Point2f> mpts_1, mpts_2;
|
std::vector<cv::Point2f> mpts_1, mpts_2;
|
||||||
std::vector<int> indexes_1, indexes_2;
|
std::vector<int> indexes_1, indexes_2;
|
||||||
std::vector<uchar> outlier_mask;
|
std::vector<uchar> outlier_mask;
|
||||||
|
QMap<int, QPoint> objectsPos;
|
||||||
for(int i=0; i<dataTree_.rows; ++i)
|
for(int i=0; i<dataTree_.rows; ++i)
|
||||||
{
|
{
|
||||||
// Check if this descriptor matches with those of the objects
|
// 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);
|
mpts_1.push_back(objects_.at(j)->keypoints().at(i).pt);
|
||||||
indexes_1.push_back(i);
|
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));
|
indexes_2.push_back(results.at<int>(i,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,31 +420,43 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
// COLORIZE
|
// COLORIZE
|
||||||
if(inliers >= Settings::getHomography_minimumInliers().toInt())
|
if(inliers >= Settings::getHomography_minimumInliers().toInt())
|
||||||
{
|
{
|
||||||
for(unsigned int k=0; k<mpts_1.size();++k)
|
if(this->isVisible())
|
||||||
{
|
{
|
||||||
if(outlier_mask.at(k))
|
for(unsigned int k=0; k<mpts_1.size();++k)
|
||||||
{
|
{
|
||||||
objects_.at(j)->setKptColor(indexes_1.at(k), color);
|
if(outlier_mask.at(k))
|
||||||
ui_->imageView_source->setKptColor(indexes_2.at(k), color);
|
{
|
||||||
}
|
objects_.at(j)->setKptColor(indexes_1.at(k), color);
|
||||||
else
|
ui_->imageView_source->setKptColor(indexes_2.at(k), color);
|
||||||
{
|
}
|
||||||
objects_.at(j)->setKptColor(indexes_1.at(k), QColor(0,0,0,alpha));
|
else
|
||||||
|
{
|
||||||
|
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(
|
QTransform hTransform(
|
||||||
H.at<double>(0,0), H.at<double>(1,0), H.at<double>(2,0),
|
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,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));
|
H.at<double>(0,2), H.at<double>(1,2), H.at<double>(2,2));
|
||||||
QPen rectPen(color);
|
|
||||||
rectPen.setWidth(4);
|
|
||||||
QGraphicsRectItem * rectItem = new QGraphicsRectItem(objects_.at(j)->image().rect());
|
|
||||||
rectItem->setPen(rectPen);
|
|
||||||
rectItem->setTransform(hTransform);
|
|
||||||
ui_->imageView_source->addRect(rectItem);
|
|
||||||
|
|
||||||
|
// 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(rect);
|
||||||
|
rectItem->setPen(rectPen);
|
||||||
|
rectItem->setTransform(hTransform);
|
||||||
|
ui_->imageView_source->addRect(rectItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -450,16 +475,24 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(objectsPos.size())
|
||||||
|
{
|
||||||
|
emit objectsFound(objectsPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else if(this->isVisible())
|
||||||
{
|
{
|
||||||
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update object pictures
|
if(this->isVisible())
|
||||||
for(int i=0; i<objects_.size(); ++i)
|
|
||||||
{
|
{
|
||||||
objects_[i]->update();
|
//Update object pictures
|
||||||
|
for(int i=0; i<objects_.size(); ++i)
|
||||||
|
{
|
||||||
|
objects_[i]->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_->label_nfeatures->setText(QString::number(keypoints.size()));
|
ui_->label_nfeatures->setText(QString::number(keypoints.size()));
|
||||||
|
|||||||
@ -26,21 +26,27 @@ public:
|
|||||||
MainWindow(Camera * camera = 0, QWidget * parent = 0);
|
MainWindow(Camera * camera = 0, QWidget * parent = 0);
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
|
void loadObjects(const QString & fileName);
|
||||||
|
void saveObjects(const QString & fileName);
|
||||||
|
void startProcessing();
|
||||||
|
void stopProcessing();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent * event);
|
virtual void closeEvent(QCloseEvent * event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addObject();
|
|
||||||
void startCamera();
|
|
||||||
void stopCamera();
|
|
||||||
void loadObjects();
|
void loadObjects();
|
||||||
void saveObjects();
|
void saveObjects();
|
||||||
void update(const cv::Mat & image);
|
|
||||||
void updateData();
|
|
||||||
void removeObject(ObjWidget * object);
|
void removeObject(ObjWidget * object);
|
||||||
|
void update(const cv::Mat & image);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void objectsFound(const QMap<int, QPoint> &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addObject();
|
||||||
void showObject(ObjWidget * obj);
|
void showObject(ObjWidget * obj);
|
||||||
|
void updateData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_mainWindow * ui_;
|
Ui_mainWindow * ui_;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user