diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 95329020..c1de1ed4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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(), 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); + } } diff --git a/src/MainWindow.h b/src/MainWindow.h index af9835c6..e0ae63b0 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -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(); diff --git a/src/Settings.h b/src/Settings.h index e96801c3..762d4190 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -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); diff --git a/src/ui/mainWindow.ui b/src/ui/mainWindow.ui index 8dd5609b..f97582eb 100644 --- a/src/ui/mainWindow.ui +++ b/src/ui/mainWindow.ui @@ -148,6 +148,10 @@ Edit + + + + @@ -481,6 +485,16 @@ Restore all default settings + + + Add objects from files... + + + + + Load scene from file... + +