Added DetectionInfo object for easier serialization/deserialization of the detection results.
Added filename property in json files Added JsonWritter class for convenience git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@369 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* DetectionInfo.h
|
||||
*
|
||||
* Created on: 2014-08-03
|
||||
* Author: mathieu
|
||||
*/
|
||||
|
||||
#ifndef DETECTIONINFO_H_
|
||||
#define DETECTIONINFO_H_
|
||||
|
||||
#include <QtCore/QMultiMap>
|
||||
#include <QtGui/QTransform>
|
||||
#include <QtCore/QSize>
|
||||
#include <QtCore/QString>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <vector>
|
||||
|
||||
class DetectionInfo
|
||||
{
|
||||
public:
|
||||
enum TimeStamp{kTimeKeypointDetection, kTimeDescriptorExtraction, kTimeIndexing, kTimeMatching, kTimeHomography, kTimeTotal};
|
||||
|
||||
public:
|
||||
DetectionInfo() :
|
||||
minMatchedDistance_(-1),
|
||||
maxMatchedDistance_(-1)
|
||||
{}
|
||||
|
||||
public:
|
||||
QMultiMap<int, QTransform> objDetected_;
|
||||
QMultiMap<int, QSize> objDetectedSizes_; // Object ID <width, height> match the number of detected objects
|
||||
QMultiMap<int, QString > objDetectedFilenames_; // Object ID <filename> match the number of detected objects
|
||||
QMultiMap<int, int> objDetectedInliersCount_; // ObjectID <count> match the number of detected objects
|
||||
QMultiMap<int, int> objDetectedOutliersCount_; // ObjectID <count> match the number of detected objects
|
||||
QMultiMap<int, QMultiMap<int, int> > objDetectedInliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of detected objects
|
||||
QMultiMap<int, QMultiMap<int, int> > objDetectedOutliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of detected objects
|
||||
|
||||
QMap<TimeStamp, float> timeStamps_;
|
||||
std::vector<cv::KeyPoint> sceneKeypoints_;
|
||||
cv::Mat sceneDescriptors_;
|
||||
QMultiMap<int, int> sceneWords_;
|
||||
QMap<int, QMultiMap<int, int> > matches_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of objects
|
||||
QMultiMap<int, QMultiMap<int, int> > rejectedInliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >
|
||||
QMultiMap<int, QMultiMap<int, int> > rejectedOutliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >
|
||||
float minMatchedDistance_;
|
||||
float maxMatchedDistance_;
|
||||
};
|
||||
|
||||
inline QDataStream & operator<<(QDataStream &out, const DetectionInfo & info)
|
||||
{
|
||||
out << quint32(info.objDetected_.size());
|
||||
|
||||
QMultiMap<int, int>::const_iterator iterInliers = info.objDetectedInliersCount_.constBegin();
|
||||
QMultiMap<int, int>::const_iterator iterOutliers = info.objDetectedOutliersCount_.constBegin();
|
||||
QMultiMap<int, QSize>::const_iterator iterSizes = info.objDetectedSizes_.constBegin();
|
||||
QMultiMap<int, QString>::const_iterator iterFilenames = info.objDetectedFilenames_.constBegin();
|
||||
for(QMultiMap<int, QTransform>::const_iterator iter=info.objDetected_.constBegin();
|
||||
iter!=info.objDetected_.constEnd();
|
||||
++iter)
|
||||
{
|
||||
// ID
|
||||
out << iter.key();
|
||||
|
||||
// Size
|
||||
out << iterSizes.value();
|
||||
|
||||
// Transform
|
||||
out << iter.value();
|
||||
|
||||
// Filename
|
||||
out << iterFilenames.value();
|
||||
|
||||
// inliers and outliers count
|
||||
out << iterInliers.value();
|
||||
out << iterOutliers.value();
|
||||
|
||||
++iterInliers;
|
||||
++iterOutliers;
|
||||
++iterSizes;
|
||||
++iterFilenames;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline QDataStream & operator>>(QDataStream &in, DetectionInfo & info)
|
||||
{
|
||||
QDataStream::Status oldStatus = in.status();
|
||||
in.resetStatus();
|
||||
info = DetectionInfo();
|
||||
|
||||
quint32 n;
|
||||
in >> n;
|
||||
|
||||
for (quint32 i = 0; i < n; ++i) {
|
||||
if (in.status() != QDataStream::Ok)
|
||||
break;
|
||||
|
||||
int id;
|
||||
QSize size;
|
||||
QTransform homography;
|
||||
QString filename;
|
||||
int inliers, outliers;
|
||||
in >> id >> size >> homography >> filename >> inliers >> outliers;
|
||||
info.objDetected_.insert(id, homography);
|
||||
info.objDetectedSizes_.insert(id, size);
|
||||
info.objDetectedFilenames_.insert(id, filename);
|
||||
info.objDetectedInliersCount_.insert(id, inliers);
|
||||
info.objDetectedOutliersCount_.insert(id, outliers);
|
||||
}
|
||||
if (in.status() != QDataStream::Ok)
|
||||
info = DetectionInfo();
|
||||
if (oldStatus != QDataStream::Ok)
|
||||
in.setStatus(oldStatus);
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
#endif /* DETECTIONINFO_H_ */
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
||||
|
||||
#include "find_object/DetectionInfo.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QMap>
|
||||
@@ -30,21 +32,18 @@ class FINDOBJECT_EXP FindObject : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
enum TimeStamp{kTimeKeypointDetection, kTimeDescriptorExtraction, kTimeIndexing, kTimeMatching, kTimeHomography, kTimeTotal};
|
||||
|
||||
public:
|
||||
FindObject(QObject * parent = 0);
|
||||
virtual ~FindObject();
|
||||
|
||||
int loadObjects(const QString & dirPath); // call updateObjects()
|
||||
const ObjSignature * addObject(const QString & filePath);
|
||||
const ObjSignature * addObject(const cv::Mat & image, int id=0);
|
||||
const ObjSignature * addObject(const cv::Mat & image, int id=0, const QString & filename = QString());
|
||||
bool addObject(ObjSignature * obj); // take ownership when true is returned
|
||||
void removeObject(int id);
|
||||
void removeAllObjects();
|
||||
|
||||
bool detect(const cv::Mat & image, QMultiMap<int,QPair<QRect,QTransform> > & objectsDetected);
|
||||
bool detect(const cv::Mat & image, DetectionInfo & info);
|
||||
|
||||
void updateDetectorExtractor();
|
||||
void updateObjects();
|
||||
@@ -53,24 +52,11 @@ public:
|
||||
const QMap<int, ObjSignature*> & objects() const {return objects_;}
|
||||
const Vocabulary * vocabulary() const {return vocabulary_;}
|
||||
|
||||
const QMultiMap<int,QPair<QRect,QTransform> > & objectsDetected() const {return objectsDetected_;}
|
||||
const QMap<TimeStamp, float> & timeStamps() const {return timeStamps_;}
|
||||
const std::vector<cv::KeyPoint> & sceneKeypoints() const {return sceneKeypoints_;}
|
||||
const cv::Mat & sceneDescriptors() const {return sceneDescriptors_;}
|
||||
const QMultiMap<int, int> & sceneWords() const {return sceneWords_;}
|
||||
const QMap<int, QMultiMap<int, int> > & matches() const {return matches_;}
|
||||
const QMultiMap<int, QMultiMap<int, int> > & inliers() const {return inliers_;}
|
||||
const QMultiMap<int, QMultiMap<int, int> > & outliers() const {return outliers_;}
|
||||
const QMultiMap<int, QMultiMap<int, int> > & rejectedInliers() const {return rejectedInliers_;}
|
||||
const QMultiMap<int, QMultiMap<int, int> > & rejectedOutliers() const {return rejectedOutliers_;}
|
||||
float minMatchedDistance() const {return minMatchedDistance_;}
|
||||
float maxMatchedDistance() const {return maxMatchedDistance_;}
|
||||
|
||||
public Q_SLOTS:
|
||||
void detect(const cv::Mat & image); // emit objectsfound()
|
||||
void detect(const cv::Mat & image); // emit objectsFound()
|
||||
|
||||
Q_SIGNALS:
|
||||
void objectsFound(const QMultiMap<int, QPair<QRect, QTransform> > &);
|
||||
void objectsFound(const DetectionInfo &);
|
||||
|
||||
private:
|
||||
void clearVocabulary();
|
||||
@@ -82,19 +68,6 @@ private:
|
||||
QMap<int, int> dataRange_; // <last id of object's descriptor, id>
|
||||
KeypointDetector * detector_;
|
||||
DescriptorExtractor * extractor_;
|
||||
|
||||
QMultiMap<int,QPair<QRect,QTransform> > objectsDetected_;
|
||||
QMap<TimeStamp, float> timeStamps_;
|
||||
std::vector<cv::KeyPoint> sceneKeypoints_;
|
||||
cv::Mat sceneDescriptors_;
|
||||
QMultiMap<int, int> sceneWords_;
|
||||
QMap<int, QMultiMap<int, int> > matches_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of objects
|
||||
QMultiMap<int, QMultiMap<int, int> > inliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of detected objects
|
||||
QMultiMap<int, QMultiMap<int, int> > outliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >, match the number of detected objects
|
||||
QMultiMap<int, QMultiMap<int, int> > rejectedInliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >
|
||||
QMultiMap<int, QMultiMap<int, int> > rejectedOutliers_; // ObjectID Map< ObjectDescriptorIndex, SceneDescriptorIndex >
|
||||
float minMatchedDistance_;
|
||||
float maxMatchedDistance_;
|
||||
};
|
||||
|
||||
#endif /* FINDOBJECT_H_ */
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* JsonWriter.h
|
||||
*
|
||||
* Created on: 2014-08-03
|
||||
* Author: mathieu
|
||||
*/
|
||||
|
||||
#ifndef JSONWRITER_H_
|
||||
#define JSONWRITER_H_
|
||||
|
||||
#include "find_object/DetectionInfo.h"
|
||||
|
||||
class JsonWriter
|
||||
{
|
||||
public:
|
||||
static bool available();
|
||||
static void write(const DetectionInfo & info, const QString & path);
|
||||
};
|
||||
|
||||
|
||||
#endif /* JSONWRITER_H_ */
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
||||
|
||||
#include "find_object/DetectionInfo.h"
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QTimer>
|
||||
@@ -74,7 +76,7 @@ private Q_SLOTS:
|
||||
void rectHovered(int objId);
|
||||
|
||||
Q_SIGNALS:
|
||||
void objectsFound(const QMultiMap<int, QPair<QRect, QTransform> > &);
|
||||
void objectsFound(const DetectionInfo &);
|
||||
|
||||
private:
|
||||
bool loadSettings(const QString & path);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
||||
|
||||
#include "find_object/DetectionInfo.h"
|
||||
|
||||
#include <QtNetwork/QTcpServer>
|
||||
|
||||
class QNetworkSession;
|
||||
@@ -25,7 +27,7 @@ public:
|
||||
quint16 getPort() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void publishObjects(const QMultiMap<int, QPair<QRect, QTransform> > & objects);
|
||||
void publishDetectionInfo(const DetectionInfo & info);
|
||||
|
||||
private Q_SLOTS:
|
||||
void addClient();
|
||||
|
||||
Reference in New Issue
Block a user