Added DragNDrop images directly in objects or scene zones.

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@415 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-12-22 21:56:10 +00:00
parent 807c8b5b43
commit a96ea6c4f5
6 changed files with 385 additions and 230 deletions

View File

@ -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();

View File

@ -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

65
src/ImageDropWidget.cpp Normal file
View File

@ -0,0 +1,65 @@
/*
* ImageDropWidget.cpp
*
* Created on: Dec 22, 2014
* Author: mathieu
*/
#include <ImageDropWidget.h>
#include <find_object/Settings.h>
#include <QtGui/QDragEnterEvent>
#include <QtCore/QRegExp>
#include <QtCore/QUrl>
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<QUrl> urls = event->mimeData()->urls();
for(int i=0; i<urls.size(); ++i)
{
QString path = urls.at(i).toLocalFile();
for(int j=0; j<extensions.size(); ++j)
{
QRegExp reg(extensions[j]);
reg.setPatternSyntax(QRegExp::Wildcard);
if(reg.exactMatch(path))
{
fileNames.push_back(path);
break;
}
}
}
if(fileNames.size())
{
Q_EMIT imagesReceived(fileNames);
}
event->acceptProposedAction();
}
}

34
src/ImageDropWidget.h Normal file
View File

@ -0,0 +1,34 @@
/*
* ImageDropWidget.h
*
* Created on: Dec 22, 2014
* Author: mathieu
*/
#ifndef IMAGEDROPWIDGET_H_
#define IMAGEDROPWIDGET_H_
#include <QtGui/QWidget>
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_ */

View File

@ -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; i<fileNames.size(); ++i)
@ -584,6 +587,11 @@ void MainWindow::addObjectsFromFiles()
}
}
void MainWindow::addObjectsFromFiles()
{
addObjectsFromFiles(QFileDialog::getOpenFileNames(this, tr("Add objects..."), Settings::workingDirectory(), tr("Image Files (%1)").arg(Settings::getGeneral_imageFormats())));
}
bool MainWindow::addObjectFromFile(const QString & filePath)
{
const ObjSignature * s = findObject_->addObject(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()));

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>826</width>
<width>881</width>
<height>523</height>
</rect>
</property>
@ -18,7 +18,7 @@
<normaloff>:/images/resources/Find-Object.png</normaloff>:/images/resources/Find-Object.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="spacing">
<number>0</number>
</property>
@ -26,171 +26,183 @@
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Camera</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_timeRefreshRate">
<property name="text">
<string> (0 Hz - 0 Hz)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_detectorDescriptorType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_nfeatures">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string> features</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="find_object::ObjWidget" name="imageView_source" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="widget_controls" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="margin">
<number>0</number>
</property>
<widget class="find_object::ImageDropWidget" name="imageDrop_scene" native="true">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_play">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_play.ico</normaloff>:/images/resources/TheWorkingGroup_video_play.ico</iconset>
<string>Camera</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_pause">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<widget class="QLabel" name="label_timeRefreshRate">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_pause.ico</normaloff>:/images/resources/TheWorkingGroup_video_pause.ico</iconset>
<string> (0 Hz - 0 Hz)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_stop">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_stop.ico</normaloff>:/images/resources/TheWorkingGroup_video_stop.ico</iconset>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_frames">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="minimum">
<number>0</number>
</property>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_detectorDescriptorType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_frame">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_nfeatures">
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string> features</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="find_object::ObjWidget" name="imageView_source" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="widget_controls" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_play">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_play.ico</normaloff>:/images/resources/TheWorkingGroup_video_play.ico</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_pause">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_pause.ico</normaloff>:/images/resources/TheWorkingGroup_video_pause.ico</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_stop">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/images/resources/TheWorkingGroup_video_stop.ico</normaloff>:/images/resources/TheWorkingGroup_video_stop.ico</iconset>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_frames">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_frame">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -199,8 +211,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>826</width>
<height>25</height>
<width>881</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -255,7 +267,7 @@
<property name="minimumSize">
<size>
<width>360</width>
<height>156</height>
<height>168</height>
</size>
</property>
<property name="floating">
@ -285,8 +297,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>73</height>
<width>348</width>
<height>76</height>
</rect>
</property>
<attribute name="label">
@ -309,8 +321,8 @@
<widget class="QDockWidget" name="dockWidget_objects">
<property name="minimumSize">
<size>
<width>200</width>
<height>138</height>
<width>208</width>
<height>196</height>
</size>
</property>
<property name="windowTitle">
@ -321,92 +333,104 @@
</attribute>
<widget class="QWidget" name="dockWidgetContents_2">
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="objects_area">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>198</width>
<height>393</height>
</rect>
<widget class="find_object::ImageDropWidget" name="imageDrop_objects" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_objects">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="objects_area">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>206</width>
<height>396</height>
</rect>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>230</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_objects">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>230</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>12</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_updateObjects">
<property name="text">
<string>Update objects</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_objectsSize">
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder></zorder>
<zorder>verticalSpacer</zorder>
<zorder>objects_area</zorder>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>12</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_updateObjects">
<property name="text">
<string>Update objects</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_objectsSize">
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
@ -825,6 +849,12 @@
<header>utilite/UPlot.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>find_object::ImageDropWidget</class>
<extends>QWidget</extends>
<header>ImageDropWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../resources.qrc"/>