Commit d7c2fb941f2db2bfe9ae8cb969413fe4e94718d1
1 parent
b45ca310
rewrote lmGallery implementation
Showing
1 changed file
with
41 additions
and
3 deletions
openbr/plugins/gallery/lm.cpp
| @@ -21,15 +21,53 @@ class lmGallery : public Gallery | @@ -21,15 +21,53 @@ class lmGallery : public Gallery | ||
| 21 | 21 | ||
| 22 | ~lmGallery() | 22 | ~lmGallery() |
| 23 | { | 23 | { |
| 24 | - const likely_const_mat m = likelyFromOpenCVMat(OpenCVUtils::toMatByRow(mats)); | ||
| 25 | - likely_write(m, qPrintable(file.name)); | 24 | + if (mats.empty()) |
| 25 | + return; | ||
| 26 | + if (!mats.first().data) | ||
| 27 | + qFatal("Null first matrix"); | ||
| 28 | + | ||
| 29 | + const int depth = mats.first().depth(); | ||
| 30 | + const int channels = mats.first().channels(); | ||
| 31 | + const int columns = mats.first().cols; | ||
| 32 | + const int rows = mats.first().rows; | ||
| 33 | + const int frames = mats.size(); | ||
| 34 | + likely_type type = likelyFromOpenCVDepth(depth); | ||
| 35 | + if (channels > 1) type |= likely_multi_channel; | ||
| 36 | + if (columns > 1) type |= likely_multi_column; | ||
| 37 | + if (rows > 1) type |= likely_multi_row; | ||
| 38 | + if (frames > 1) type |= likely_multi_frame; | ||
| 39 | + | ||
| 40 | + const likely_mat m = likely_new(type, channels, columns, rows, frames, NULL); | ||
| 41 | + const size_t step = (type & likely_depth) * channels * columns * rows / 8; | ||
| 42 | + for (size_t i=0; i<size_t(frames); i++) { | ||
| 43 | + const cv::Mat &mat = mats[i]; | ||
| 44 | + if (!mat.isContinuous()) | ||
| 45 | + qFatal("Expected continuous matrix data"); | ||
| 46 | + if (mat.depth() != depth) | ||
| 47 | + qFatal("Depth mismatch"); | ||
| 48 | + if (mat.channels() != channels) | ||
| 49 | + qFatal("Channel mismatch"); | ||
| 50 | + if (mat.cols != columns) | ||
| 51 | + qFatal("Columns mismatch"); | ||
| 52 | + if (mat.rows != rows) | ||
| 53 | + qFatal("Rows mismatch"); | ||
| 54 | + memcpy(m->data + i * step, mat.data, step); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + if (!likely_write(m, qPrintable(file.name))) | ||
| 58 | + qFatal("Write failed"); | ||
| 26 | likely_release_mat(m); | 59 | likely_release_mat(m); |
| 27 | } | 60 | } |
| 28 | 61 | ||
| 29 | TemplateList readBlock(bool *done) | 62 | TemplateList readBlock(bool *done) |
| 30 | { | 63 | { |
| 31 | *done = true; | 64 | *done = true; |
| 32 | - qFatal("Not supported."); | 65 | + TemplateList templates; |
| 66 | + const likely_const_mat m = likely_read(qPrintable(file.name), likely_file_matrix, likely_void); | ||
| 67 | + const size_t step = (m->type & likely_depth) * m->channels * m->columns * m->rows / 8; | ||
| 68 | + for (size_t i=0; i<m->frames; i++) | ||
| 69 | + templates.append(cv::Mat(m->rows, m->columns, CV_MAKETYPE(likelyToOpenCVDepth(m->type), m->channels), (void*)(m->data + i * step)).clone()); | ||
| 70 | + return templates; | ||
| 33 | } | 71 | } |
| 34 | 72 | ||
| 35 | void write(const Template &t) | 73 | void write(const Template &t) |