28 #ifndef OBJSIGNATURE_H_ 29 #define OBJSIGNATURE_H_ 31 #include <opencv2/opencv.hpp> 32 #include <QtCore/QString> 33 #include <QtCore/QMultiMap> 34 #include <QtCore/QRect> 35 #include <QtCore/QDataStream> 36 #include <QtCore/QByteArray> 37 #include <QtCore/QFileInfo> 50 rect_(0,0,image.cols, image.rows),
73 void save(QDataStream & streamPtr)
const 78 for(
unsigned int j=0; j<
keypoints_.size(); ++j)
91 qint64 dataSize = bytes.size();
93 if(dataSize <= std::numeric_limits<int>::max())
96 streamPtr << old << old << old << dataSize;
97 streamPtr << QByteArray::fromRawData((
const char*)bytes.data(), dataSize);
101 UERROR(
"Descriptors (compressed) are too large (%d MB) to be saved! Limit is 2 GB (based on max QByteArray size).",
102 dataSize/(1024*1024));
104 streamPtr << old << old << old << old;
105 streamPtr << QByteArray();
112 std::vector<unsigned char> bytes;
113 QString ext = QFileInfo(filePath_).suffix();
117 cv::imencode(
".png",
image_, bytes);
121 cv::imencode(std::string(
".")+ext.toStdString(),
image_, bytes);
123 streamPtr << QByteArray::fromRawData((
const char*)bytes.data(), (int)bytes.size());
127 streamPtr << QByteArray();
133 void load(QDataStream & streamPtr,
bool ignoreImage)
138 for(
int i=0;i<nKpts;++i)
152 streamPtr >> rows >> cols >> type >> dataSize;
153 if(rows == 0 && cols == 0 && type == 0)
156 UASSERT(dataSize <= std::numeric_limits<int>::max());
168 descriptors_ = cv::Mat(rows, cols, type, data.data()).clone();
172 UERROR(
"Error reading descriptor data for object=%d",
id_);
180 if(!ignoreImage && image.size())
182 std::vector<unsigned char> bytes(image.size());
183 memcpy(bytes.data(), image.data(), image.size());
184 image_ = cv::imdecode(bytes, cv::IMREAD_UNCHANGED);
QMultiMap< int, int > words_
void save(QDataStream &streamPtr) const
cv::Mat uncompressData(const unsigned char *bytes, unsigned long size)
const QString & filePath() const
const std::vector< cv::KeyPoint > & keypoints() const
const cv::Mat & image() const
void setWords(const QMultiMap< int, int > &words)
#define UASSERT(condition)
ObjSignature(int id, const cv::Mat &image, const QString &filePath)
std::vector< cv::KeyPoint > keypoints_
void setData(const std::vector< cv::KeyPoint > &keypoints, const cv::Mat &descriptors)
std::vector< unsigned char > compressData(const cv::Mat &data)
const cv::Mat & descriptors() const
void load(QDataStream &streamPtr, bool ignoreImage)
const QMultiMap< int, int > & words() const
const QRect & rect() const