Commit d377e6d627661724549f530e44934b38f224c261
1 parent
04037199
Generalized Cat transform
Showing
1 changed file
with
17 additions
and
13 deletions
sdk/plugins/regions.cpp
| ... | ... | @@ -79,23 +79,27 @@ BR_REGISTER(Transform, ByRow) |
| 79 | 79 | class Cat : public UntrainableMetaTransform |
| 80 | 80 | { |
| 81 | 81 | Q_OBJECT |
| 82 | + Q_PROPERTY(int partitions READ get_partitions WRITE set_partitions RESET reset_partitions) | |
| 83 | + BR_PROPERTY(int, partitions, 1) | |
| 82 | 84 | |
| 83 | 85 | void project(const Template &src, Template &dst) const |
| 84 | 86 | { |
| 85 | - int vals = 0; | |
| 86 | - foreach (const cv::Mat &m, src) | |
| 87 | - vals += m.total() * m.channels(); | |
| 88 | - | |
| 89 | - Mat cat(1, (int)vals, CV_32FC1); | |
| 90 | - int offset = 0; | |
| 91 | - foreach (const cv::Mat &m, src) { | |
| 92 | - size_t size = m.total() * m.elemSize(); | |
| 93 | - memcpy(&cat.data[offset], m.ptr(), size); | |
| 94 | - offset += size; | |
| 95 | - } | |
| 96 | - | |
| 97 | 87 | dst.file = src.file; |
| 98 | - dst = cat; | |
| 88 | + | |
| 89 | + QVector<int> sizes(partitions, 0); | |
| 90 | + for (int i=0; i<src.size(); i++) | |
| 91 | + sizes[i%partitions] += src[i].total() * src[i].channels(); | |
| 92 | + | |
| 93 | + foreach (int size, sizes) | |
| 94 | + dst.append(Mat(1, size, CV_32FC1)); | |
| 95 | + | |
| 96 | + QVector<int> offsets(partitions, 0); | |
| 97 | + for (int i=0; i<src.size(); i++) { | |
| 98 | + size_t size = src[i].total() * src[i].elemSize(); | |
| 99 | + int j = i%partitions; | |
| 100 | + memcpy(&dst[j].data[offsets[j]], src[i].ptr(), size); | |
| 101 | + offsets[j] += size; | |
| 102 | + } | |
| 99 | 103 | } |
| 100 | 104 | }; |
| 101 | 105 | ... | ... |