Commit 971dbf739384d9af4ddf3af07d960bf73e96cc7d
1 parent
564a4d82
Introduced GroupTransform
Showing
1 changed file
with
39 additions
and
0 deletions
openbr/plugins/regions.cpp
| @@ -112,6 +112,45 @@ BR_REGISTER(Transform, CatTransform) | @@ -112,6 +112,45 @@ BR_REGISTER(Transform, CatTransform) | ||
| 112 | 112 | ||
| 113 | /*! | 113 | /*! |
| 114 | * \ingroup transforms | 114 | * \ingroup transforms |
| 115 | + * \brief Group all input matrices into a single matrix. | ||
| 116 | + * | ||
| 117 | + * Similar to CatTransfrom but groups every _size_ adjacent matricies. | ||
| 118 | + * \author Josh Klontz \cite jklontz | ||
| 119 | + */ | ||
| 120 | +class GroupTransform : public UntrainableMetaTransform | ||
| 121 | +{ | ||
| 122 | + Q_OBJECT | ||
| 123 | + Q_PROPERTY(int size READ get_size WRITE set_size RESET reset_size) | ||
| 124 | + BR_PROPERTY(int, size, 1) | ||
| 125 | + | ||
| 126 | + void project(const Template &src, Template &dst) const | ||
| 127 | + { | ||
| 128 | + dst.file = src.file; | ||
| 129 | + | ||
| 130 | + if (src.size() % size != 0) | ||
| 131 | + qFatal("%d size does not evenly divide %d matrices.", size, src.size()); | ||
| 132 | + QVector<int> sizes(src.size() / size, 0); | ||
| 133 | + for (int i=0; i<src.size(); i++) | ||
| 134 | + sizes[i/size] += src[i].total(); | ||
| 135 | + | ||
| 136 | + if (!src.empty()) | ||
| 137 | + foreach (int size, sizes) | ||
| 138 | + dst.append(Mat(1, size, src.m().type())); | ||
| 139 | + | ||
| 140 | + QVector<int> offsets(src.size() / size, 0); | ||
| 141 | + for (int i=0; i<src.size(); i++) { | ||
| 142 | + size_t size = src[i].total() * src[i].elemSize(); | ||
| 143 | + int j = i / size; | ||
| 144 | + memcpy(&dst[j].data[offsets[j]], src[i].ptr(), size); | ||
| 145 | + offsets[j] += size; | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | +}; | ||
| 149 | + | ||
| 150 | +BR_REGISTER(Transform, GroupTransform) | ||
| 151 | + | ||
| 152 | +/*! | ||
| 153 | + * \ingroup transforms | ||
| 115 | * \brief Concatenates all input matrices by row into a single matrix. | 154 | * \brief Concatenates all input matrices by row into a single matrix. |
| 116 | * All matricies must have the same column counts. | 155 | * All matricies must have the same column counts. |
| 117 | * \author Josh Klontz \cite jklontz | 156 | * \author Josh Klontz \cite jklontz |