diff --git a/include/find_object/MainWindow.h b/include/find_object/MainWindow.h index bf3a1ad9..e888fe31 100644 --- a/include/find_object/MainWindow.h +++ b/include/find_object/MainWindow.h @@ -86,7 +86,9 @@ private Q_SLOTS: void loadObjects(); bool saveObjects(); void addObjectFromScene(); + void addObjectsFromFiles(const QStringList & fileNames); void addObjectsFromFiles(); + void loadSceneFromFile(const QStringList & fileNames); void loadSceneFromFile(); void setupCameraFromVideoFile(); void setupCameraFromImagesDirectory(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be8cdc5c..92f7b0f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ SET(headers_ui ./ParametersToolBox.h ./AboutDialog.h ./RectItem.h + ./ImageDropWidget.h ./rtabmap/PdfPlot.h ./utilite/UPlot.h ) @@ -47,6 +48,7 @@ SET(SRC_FILES ./ParametersToolBox.cpp ./Settings.cpp ./ObjWidget.cpp + ./ImageDropWidget.cpp ./FindObject.cpp ./AboutDialog.cpp ./TcpServer.cpp diff --git a/src/ImageDropWidget.cpp b/src/ImageDropWidget.cpp new file mode 100644 index 00000000..373c6b83 --- /dev/null +++ b/src/ImageDropWidget.cpp @@ -0,0 +1,65 @@ +/* + * ImageDropWidget.cpp + * + * Created on: Dec 22, 2014 + * Author: mathieu + */ + +#include +#include +#include +#include +#include + +namespace find_object { + +ImageDropWidget::ImageDropWidget(QWidget *parent, Qt::WindowFlags flags) : + QWidget(parent, flags) +{ + setAcceptDrops(true); +} + +ImageDropWidget::~ImageDropWidget() +{ +} + +void ImageDropWidget::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) + { + event->acceptProposedAction(); + } +} + +void ImageDropWidget::dropEvent(QDropEvent *event) +{ + QStringList fileNames; + + QStringList extensions = Settings::getGeneral_imageFormats().split(" "); + + QList urls = event->mimeData()->urls(); + for(int i=0; iacceptProposedAction(); +} + +} + diff --git a/src/ImageDropWidget.h b/src/ImageDropWidget.h new file mode 100644 index 00000000..74ef8ce5 --- /dev/null +++ b/src/ImageDropWidget.h @@ -0,0 +1,34 @@ +/* + * ImageDropWidget.h + * + * Created on: Dec 22, 2014 + * Author: mathieu + */ + +#ifndef IMAGEDROPWIDGET_H_ +#define IMAGEDROPWIDGET_H_ + +#include + +namespace find_object { + +class ImageDropWidget : public QWidget { + + Q_OBJECT; + +public: + ImageDropWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0); + virtual ~ImageDropWidget(); + +Q_SIGNALS: + void imagesReceived(const QStringList &); + + +protected: + virtual void dragEnterEvent(QDragEnterEvent *event); + virtual void dropEvent(QDropEvent *event); +}; + +} + +#endif /* IMAGEDROPWIDGET_H_ */ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e1fb8471..879705b1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -246,6 +246,10 @@ MainWindow::MainWindow(FindObject * findObject, Camera * camera, QWidget * paren // Set 1 msec to see state on the status bar. QTimer::singleShot(1, this, SLOT(startProcessing())); } + + //Setup drag and drop images + connect(ui_->imageDrop_objects, SIGNAL(imagesReceived(const QStringList &)), this, SLOT(addObjectsFromFiles(const QStringList &))); + connect(ui_->imageDrop_scene, SIGNAL(imagesReceived(const QStringList &)), this, SLOT(loadSceneFromFile(const QStringList &))); } MainWindow::~MainWindow() @@ -570,9 +574,8 @@ void MainWindow::addObjectFromScene() delete dialog; } -void MainWindow::addObjectsFromFiles() +void MainWindow::addObjectsFromFiles(const QStringList & fileNames) { - QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Add objects..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats())); if(fileNames.size()) { for(int i=0; iaddObject(filePath); @@ -602,6 +610,20 @@ bool MainWindow::addObjectFromFile(const QString & filePath) } } +void MainWindow::loadSceneFromFile(const QStringList & fileNames) +{ + //take the first + if(fileNames.size()) + { + cv::Mat img = cv::imread(fileNames.first().toStdString().c_str()); + if(!img.empty()) + { + this->update(img); + ui_->label_timeRefreshRate->setVisible(false); + } + } +} + void MainWindow::loadSceneFromFile() { QString fileName = QFileDialog::getOpenFileName(this, tr("Load scene..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats())); diff --git a/src/ui/mainWindow.ui b/src/ui/mainWindow.ui index 5e9de9f8..ad6548d9 100644 --- a/src/ui/mainWindow.ui +++ b/src/ui/mainWindow.ui @@ -6,7 +6,7 @@ 0 0 - 826 + 881 523 @@ -18,7 +18,7 @@ :/images/resources/Find-Object.png:/images/resources/Find-Object.png - + 0 @@ -26,171 +26,183 @@ 0 - - - - - - 75 - true - - - - Camera - - - - - - - (0 Hz - 0 Hz) - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - features - - - - - - - - - - - - - - - 0 - + + + + 0 + + + 0 + + + - - - - 0 - 0 - - - - - 24 - 24 - + + + + 75 + true + - - - - - :/images/resources/TheWorkingGroup_video_play.ico:/images/resources/TheWorkingGroup_video_play.ico + Camera - - - - 24 - 24 - - + - - - - - :/images/resources/TheWorkingGroup_video_pause.ico:/images/resources/TheWorkingGroup_video_pause.ico + (0 Hz - 0 Hz) - - - - 24 - 24 - - - - - - - - :/images/resources/TheWorkingGroup_video_stop.ico:/images/resources/TheWorkingGroup_video_stop.ico - - - - - - - Qt::ClickFocus - - - 0 - + Qt::Horizontal + + + 40 + 20 + + + + + + + + + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + 0 + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + features + - - - + + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + + + + :/images/resources/TheWorkingGroup_video_play.ico:/images/resources/TheWorkingGroup_video_play.ico + + + + + + + + 24 + 24 + + + + + + + + :/images/resources/TheWorkingGroup_video_pause.ico:/images/resources/TheWorkingGroup_video_pause.ico + + + + + + + + 24 + 24 + + + + + + + + :/images/resources/TheWorkingGroup_video_stop.ico:/images/resources/TheWorkingGroup_video_stop.ico + + + + + + + Qt::ClickFocus + + + 0 + + + Qt::Horizontal + + + + + + + 0 + + + + + + + + + + @@ -199,8 +211,8 @@ 0 0 - 826 - 25 + 881 + 22 @@ -255,7 +267,7 @@ 360 - 156 + 168 @@ -285,8 +297,8 @@ 0 0 - 360 - 73 + 348 + 76 @@ -309,8 +321,8 @@ - 200 - 138 + 208 + 196 @@ -321,92 +333,104 @@ - - 0 - 0 - - - - 150 - 0 - - - - true - - - - - 0 - 0 - 198 - 393 - + + + + 0 - - - 0 - - - 0 - - - - - Qt::Vertical + + 0 + + + + + + 150 + 0 + + + + true + + + + + 0 + 0 + 206 + 396 + - - - 20 - 230 - - - - - - + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 230 + + + + + + + + + + + + 12 + + + + + Update objects + + + + + + + + 20 + 0 + + + + Qt::ClickFocus + + + 100 + + + 100 + + + Qt::Horizontal + + + + + + + + verticalSpacer + objects_area - - - - 12 - - - - - Update objects - - - - - - - - 20 - 0 - - - - Qt::ClickFocus - - - 100 - - - 100 - - - Qt::Horizontal - - - - - @@ -825,6 +849,12 @@
utilite/UPlot.h
1 + + find_object::ImageDropWidget + QWidget +
ImageDropWidget.h
+ 1 +