Commit f2e9bf0e59c10a75dadde89514ab531d841484a4

Authored by Josh Klontz
1 parent d7c2fb94

simplified lmGallery to make use of newly introduced helper functions

Showing 1 changed file with 4 additions and 34 deletions
openbr/plugins/gallery/lm.cpp
... ... @@ -23,37 +23,7 @@ class lmGallery : public Gallery
23 23 {
24 24 if (mats.empty())
25 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   -
  26 + likely_const_mat m = likelyFromOpenCVMats(mats.toVector().toStdVector());
57 27 if (!likely_write(m, qPrintable(file.name)))
58 28 qFatal("Write failed");
59 29 likely_release_mat(m);
... ... @@ -64,9 +34,9 @@ class lmGallery : public Gallery
64 34 *done = true;
65 35 TemplateList templates;
66 36 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());
  37 + foreach (const cv::Mat &mat, likelyToOpenCVMats(m))
  38 + templates.append(mat);
  39 + likely_release_mat(m);
70 40 return templates;
71 41 }
72 42  
... ...