From dc042fe418399c9bfe8ce621e23b3b95e92337dd Mon Sep 17 00:00:00 2001 From: matlabbe Date: Wed, 15 Mar 2017 11:48:36 -0400 Subject: [PATCH] Added General/autoScreenshotPath option --- include/find_object/Settings.h | 1 + src/MainWindow.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/find_object/Settings.h b/include/find_object/Settings.h index 1df5de64..fe00c9ec 100644 --- a/include/find_object/Settings.h +++ b/include/find_object/Settings.h @@ -283,6 +283,7 @@ class FINDOBJECT_EXP Settings PARAMETER(General, vocabularyUpdateMinWords, int, 2000, "When the vocabulary is incremental (see \"General/vocabularyIncremental\"), after X words added to vocabulary, the internal index is updated with new words. This parameter lets avoiding to reconstruct the whole nearest neighbor index after each time descriptors of an object are added to vocabulary. 0 means no incremental update."); PARAMETER(General, sendNoObjDetectedEvents, bool, true, "When there are no objects detected, send an empty object detection event."); PARAMETER(General, autoPauseOnDetection, bool, false, "Auto pause the camera when an object is detected."); + PARAMETER(General, autoScreenshotPath, QString, "", "Path to a directory to save screenshot of the current camera view when there is a detection."); PARAMETER(Homography, homographyComputed, bool, true, "Compute homography? On ROS, this is required to publish objects detected."); PARAMETER(Homography, method, QString, "1:LMEDS;RANSAC;RHO", "Type of the robust estimation algorithm: least-median algorithm or RANSAC algorithm."); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 670c8735..5271a543 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1362,7 +1362,7 @@ void MainWindow::update(const cv::Mat & image) } } - if(camera_->isRunning() && Settings::getGeneral_autoPauseOnDetection() && info.objDetected_.size()) + if(info.objDetected_.size() && camera_->isRunning() && Settings::getGeneral_autoPauseOnDetection()) { this->pauseProcessing(); } @@ -1426,6 +1426,30 @@ void MainWindow::update(const cv::Mat & image) } } + // save screenshot of the detection + if(info.objDetected_.size() && !Settings::getGeneral_autoScreenshotPath().isEmpty()) + { + QDir dir(Settings::getGeneral_autoScreenshotPath()); + if(!dir.exists()) + { + QMessageBox::warning(this, tr("Screenshot on detection"), tr("Directory \"%1\" doesn't " + "exist, screenshot of the detection cannot be taken. Parameter \"%2\" is cleared.").arg(Settings::getGeneral_autoScreenshotPath()).arg(Settings::kGeneral_autoScreenshotPath())); + Settings::setGeneral_autoScreenshotPath(""); + ui_->toolBox->updateParameter(Settings::kGeneral_autoScreenshotPath()); + } + else + { + QString path = Settings::getGeneral_autoScreenshotPath() + QDir::separator() + (QDateTime::currentDateTime().toString("yyMMddhhmmsszzz") + ".jpg"); + if(!ui_->imageView_source->getSceneAsPixmap().save(path)) + { + UDEBUG("Failed to save screenshot \"%s\"! (%s is set)", path.toStdString().c_str(), Settings::kGeneral_autoScreenshotPath().toStdString().c_str()); + } + else + { + UINFO("Save screenshot \"%s\"! (%s is set)", path.toStdString().c_str(), Settings::kGeneral_autoScreenshotPath().toStdString().c_str()); + } + } + } //update likelihood plot UDEBUG("Set likelihood score curve values (%d)", scores.size());