2014-07-31 19:02:31 +00:00
|
|
|
/*
|
2014-08-06 13:43:29 +00:00
|
|
|
Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2014-08-11 15:49:53 +00:00
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
2014-08-06 13:43:29 +00:00
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
#ifndef FINDOBJECT_H_
|
|
|
|
|
#define FINDOBJECT_H_
|
|
|
|
|
|
2014-07-31 20:11:46 +00:00
|
|
|
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
|
|
|
|
|
2014-08-04 01:33:52 +00:00
|
|
|
#include "find_object/DetectionInfo.h"
|
|
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
|
#include <QtCore/QMap>
|
|
|
|
|
#include <QtCore/QMultiMap>
|
|
|
|
|
#include <QtCore/QPair>
|
|
|
|
|
#include <QtCore/QVector>
|
|
|
|
|
#include <QtGui/QTransform>
|
|
|
|
|
#include <QtCore/QRect>
|
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
namespace find_object {
|
|
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
class ObjSignature;
|
|
|
|
|
class Vocabulary;
|
2015-07-10 14:27:11 -04:00
|
|
|
class Feature2D;
|
2014-07-31 19:02:31 +00:00
|
|
|
|
2014-07-31 20:11:46 +00:00
|
|
|
class FINDOBJECT_EXP FindObject : public QObject
|
2014-07-31 19:02:31 +00:00
|
|
|
{
|
|
|
|
|
Q_OBJECT;
|
2014-08-22 22:36:09 +00:00
|
|
|
public:
|
|
|
|
|
static void affineSkew(float tilt,
|
|
|
|
|
float phi,
|
|
|
|
|
const cv::Mat & image,
|
|
|
|
|
cv::Mat & skewImage,
|
|
|
|
|
cv::Mat & skewMask,
|
|
|
|
|
cv::Mat & Ai);
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
public:
|
2015-06-09 21:41:34 -04:00
|
|
|
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
2014-07-31 19:02:31 +00:00
|
|
|
virtual ~FindObject();
|
|
|
|
|
|
2015-01-09 22:44:16 +00:00
|
|
|
bool loadSession(const QString & path);
|
2015-01-12 01:19:09 +00:00
|
|
|
bool saveSession(const QString & path);
|
|
|
|
|
bool isSessionModified() const {return sessionModified_;}
|
2015-01-09 22:44:16 +00:00
|
|
|
|
2015-07-07 16:49:38 -04:00
|
|
|
bool saveVocabulary(const QString & filePath) const;
|
|
|
|
|
bool loadVocabulary(const QString & filePath);
|
|
|
|
|
|
2015-06-03 21:46:35 -04:00
|
|
|
int loadObjects(const QString & dirPath, bool recursive = false); // call updateObjects()
|
2014-07-31 19:02:31 +00:00
|
|
|
const ObjSignature * addObject(const QString & filePath);
|
2015-06-03 21:46:35 -04:00
|
|
|
const ObjSignature * addObject(const cv::Mat & image, int id=0, const QString & filePath = QString());
|
2014-07-31 19:02:31 +00:00
|
|
|
bool addObject(ObjSignature * obj); // take ownership when true is returned
|
|
|
|
|
void removeObject(int id);
|
|
|
|
|
void removeAllObjects();
|
|
|
|
|
|
2015-11-30 00:27:57 -05:00
|
|
|
bool detect(const cv::Mat & image, find_object::DetectionInfo & info) const;
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
void updateDetectorExtractor();
|
2015-01-12 01:19:09 +00:00
|
|
|
void updateObjects(const QList<int> & ids = QList<int>());
|
2015-06-24 18:07:52 -04:00
|
|
|
void updateVocabulary(const QList<int> & ids = QList<int>());
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
const QMap<int, ObjSignature*> & objects() const {return objects_;}
|
|
|
|
|
const Vocabulary * vocabulary() const {return vocabulary_;}
|
|
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
2015-06-03 21:46:35 -04:00
|
|
|
void addObjectAndUpdate(const cv::Mat & image, int id=0, const QString & filePath = QString());
|
2015-01-12 01:19:09 +00:00
|
|
|
void removeObjectAndUpdate(int id);
|
2014-08-04 01:33:52 +00:00
|
|
|
void detect(const cv::Mat & image); // emit objectsFound()
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2014-08-06 14:09:55 +00:00
|
|
|
void objectsFound(const find_object::DetectionInfo &);
|
2014-07-31 19:02:31 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void clearVocabulary();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QMap<int, ObjSignature*> objects_;
|
|
|
|
|
Vocabulary * vocabulary_;
|
|
|
|
|
QMap<int, cv::Mat> objectsDescriptors_;
|
|
|
|
|
QMap<int, int> dataRange_; // <last id of object's descriptor, id>
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D * detector_;
|
|
|
|
|
Feature2D * extractor_;
|
2015-01-12 01:19:09 +00:00
|
|
|
bool sessionModified_;
|
2015-06-09 21:41:34 -04:00
|
|
|
bool keepImagesInRAM_;
|
2014-07-31 19:02:31 +00:00
|
|
|
};
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
} // namespace find_object
|
|
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
#endif /* FINDOBJECT_H_ */
|