lm.cpp
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <openbr/plugins/openbr_internal.h>
#include <openbr/core/opencvutils.h>
#include <likely.h>
#include <likely/opencv.hpp>
namespace br
{
/*!
* \ingroup formats
* \brief Likely matrix format
*
* www.liblikely.org
* \author Josh Klontz \cite jklontz
*/
class lmGallery : public Gallery
{
Q_OBJECT
QList<cv::Mat> mats;
~lmGallery()
{
if (mats.empty())
return;
if (!mats.first().data)
qFatal("Null first matrix");
const int depth = mats.first().depth();
const int channels = mats.first().channels();
const int columns = mats.first().cols;
const int rows = mats.first().rows;
const int frames = mats.size();
likely_type type = likelyFromOpenCVDepth(depth);
if (channels > 1) type |= likely_multi_channel;
if (columns > 1) type |= likely_multi_column;
if (rows > 1) type |= likely_multi_row;
if (frames > 1) type |= likely_multi_frame;
const likely_mat m = likely_new(type, channels, columns, rows, frames, NULL);
const size_t step = (type & likely_depth) * channels * columns * rows / 8;
for (size_t i=0; i<size_t(frames); i++) {
const cv::Mat &mat = mats[i];
if (!mat.isContinuous())
qFatal("Expected continuous matrix data");
if (mat.depth() != depth)
qFatal("Depth mismatch");
if (mat.channels() != channels)
qFatal("Channel mismatch");
if (mat.cols != columns)
qFatal("Columns mismatch");
if (mat.rows != rows)
qFatal("Rows mismatch");
memcpy(m->data + i * step, mat.data, step);
}
if (!likely_write(m, qPrintable(file.name)))
qFatal("Write failed");
likely_release_mat(m);
}
TemplateList readBlock(bool *done)
{
*done = true;
TemplateList templates;
const likely_const_mat m = likely_read(qPrintable(file.name), likely_file_matrix, likely_void);
const size_t step = (m->type & likely_depth) * m->channels * m->columns * m->rows / 8;
for (size_t i=0; i<m->frames; i++)
templates.append(cv::Mat(m->rows, m->columns, CV_MAKETYPE(likelyToOpenCVDepth(m->type), m->channels), (void*)(m->data + i * step)).clone());
return templates;
}
void write(const Template &t)
{
mats.append(t);
}
};
BR_REGISTER(Gallery, lmGallery)
} // namespace br
#include "gallery/lm.moc"