Fixed issue 3: added "Load objects from files..." and "Load scene from file..." actions.

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@75 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2012-01-30 00:54:23 +00:00
parent 27652b4f8f
commit 465e2d846e
4 changed files with 70 additions and 1 deletions

View File

@ -75,6 +75,8 @@ MainWindow::MainWindow(Camera * camera, QWidget * parent) :
// Actions
connect(ui_->actionAdd_object, SIGNAL(triggered()), this, SLOT(addObject()));
connect(ui_->actionAdd_objects_from_files, SIGNAL(triggered()), this, SLOT(addObjectsFromFiles()));
connect(ui_->actionLoad_scene_from_file, SIGNAL(triggered()), this, SLOT(loadSceneFromFile()));
connect(ui_->actionStart_camera, SIGNAL(triggered()), this, SLOT(startProcessing()));
connect(ui_->actionStop_camera, SIGNAL(triggered()), this, SLOT(stopProcessing()));
connect(ui_->actionExit, SIGNAL(triggered()), this, SLOT(close()));
@ -83,7 +85,11 @@ MainWindow::MainWindow(Camera * camera, QWidget * parent) :
connect(ui_->actionAbout, SIGNAL(triggered()), aboutDialog_ , SLOT(exec()));
connect(ui_->actionRestore_all_default_settings, SIGNAL(triggered()), ui_->toolBox, SLOT(resetAllPages()));
QTimer::singleShot(10, this, SLOT(startProcessing()));
if(Settings::getGeneral_autoStartCamera())
{
// Set 1 msec to see state on the status bar.
QTimer::singleShot(1, this, SLOT(startProcessing()));
}
}
MainWindow::~MainWindow()
@ -196,6 +202,41 @@ void MainWindow::addObject()
this->startProcessing();
}
void MainWindow::addObjectsFromFiles()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Add objects..."), Settings::workingDirectory(), tr("Image Files (*.png *.jpg *.bmp *.tiff)"));
if(fileNames.size())
{
for(int i=0; i<fileNames.size(); ++i)
{
IplImage * img = cvLoadImage(fileNames[i].toStdString().c_str(), CV_LOAD_IMAGE_GRAYSCALE);
if(img)
{
objects_.append(new ObjWidget(0, std::vector<cv::KeyPoint>(), cv::Mat(), img, "", ""));
this->showObject(objects_.last());
cvReleaseImage(&img);
}
}
updateObjects();
}
}
void MainWindow::loadSceneFromFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Load scene..."), Settings::workingDirectory(), tr("Image Files (*.png *.jpg *.bmp *.tiff)"));
if(!fileName.isEmpty())
{
IplImage * img = cvLoadImage(fileName.toStdString().c_str());
if(img)
{
cv::Mat imageMat(img);
this->update(imageMat);
cvReleaseImage(&img);
ui_->label_timeRefreshRate->setVisible(false);
}
}
}
void MainWindow::showObject(ObjWidget * obj)
{
if(obj)
@ -278,6 +319,8 @@ void MainWindow::updateObjects()
detectorDescriptorType->setText(QString("%1/%2").arg(objects_.at(i)->detectorType()).arg(objects_.at(i)->descriptorType()));
}
updateData();
notifyParametersChanged(); // this will update the scene if camera is stopped
}
this->statusBar()->clearMessage();
}
@ -341,6 +384,8 @@ void MainWindow::startProcessing()
connect(camera_, SIGNAL(imageReceived(const cv::Mat &)), this, SLOT(update(const cv::Mat &)));
ui_->actionStop_camera->setEnabled(true);
ui_->actionStart_camera->setEnabled(false);
ui_->actionLoad_scene_from_file->setEnabled(false);
ui_->label_timeRefreshRate->setVisible(true);
this->statusBar()->showMessage(tr("Camera started."), 2000);
}
else
@ -359,6 +404,7 @@ void MainWindow::stopProcessing()
}
ui_->actionStop_camera->setEnabled(false);
ui_->actionStart_camera->setEnabled(true);
ui_->actionLoad_scene_from_file->setEnabled(true);
}
void MainWindow::update(const cv::Mat & image)
@ -655,4 +701,10 @@ void MainWindow::notifyParametersChanged()
{
this->statusBar()->showMessage(tr("A parameter has changed... \"Update objects\" may be required."));
}
if(!camera_->isRunning() && ui_->imageView_source->iplImage())
{
cv::Mat image(ui_->imageView_source->iplImage(), true);
this->update(image);
ui_->label_timeRefreshRate->setVisible(false);
}
}

View File

@ -45,6 +45,8 @@ private slots:
void loadObjects();
void saveObjects();
void addObject();
void addObjectsFromFiles();
void loadSceneFromFile();
void removeObject(ObjWidget * object);
void update(const cv::Mat & image);
void updateObjects();

View File

@ -124,6 +124,7 @@ class Settings
PARAMETER(NearestNeighbor, minDistanceUsed, bool, false);
PARAMETER(NearestNeighbor, minDistance, float, 1.6f);
PARAMETER(General, autoStartCamera, bool, false);
PARAMETER(General, nextObjID, uint, 1);
PARAMETER(Homography, homographyComputed, bool, true);

View File

@ -148,6 +148,10 @@
<string>Edit</string>
</property>
<addaction name="actionAdd_object"/>
<addaction name="actionAdd_objects_from_files"/>
<addaction name="separator"/>
<addaction name="actionLoad_scene_from_file"/>
<addaction name="separator"/>
<addaction name="actionStart_camera"/>
<addaction name="actionStop_camera"/>
<addaction name="separator"/>
@ -481,6 +485,16 @@
<string>Restore all default settings</string>
</property>
</action>
<action name="actionAdd_objects_from_files">
<property name="text">
<string>Add objects from files...</string>
</property>
</action>
<action name="actionLoad_scene_from_file">
<property name="text">
<string>Load scene from file...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>