Commit 05452b119e685f749465398309ff60fdb641968b
1 parent
cb608094
Updated Flip and added RandRotate
Showing
1 changed file
with
51 additions
and
3 deletions
openbr/plugins/register.cpp
| ... | ... | @@ -125,7 +125,7 @@ BR_REGISTER(Transform, AffineTransform) |
| 125 | 125 | * \brief Flips the image about an axis. |
| 126 | 126 | * \author Josh Klontz \cite jklontz |
| 127 | 127 | */ |
| 128 | -class FlipTransform : public UntrainableTransform | |
| 128 | +class FlipTransform : public UntrainableMetaTransform | |
| 129 | 129 | { |
| 130 | 130 | Q_OBJECT |
| 131 | 131 | Q_ENUMS(Axis) |
| ... | ... | @@ -140,14 +140,62 @@ public: |
| 140 | 140 | private: |
| 141 | 141 | BR_PROPERTY(Axis, axis, Y) |
| 142 | 142 | |
| 143 | - void project(const Template &src, Template &dst) const | |
| 143 | + void project(const TemplateList &src, TemplateList &dst) const | |
| 144 | 144 | { |
| 145 | - flip(src, dst, axis); | |
| 145 | + dst.append(src.first()); | |
| 146 | + for (int i=0; i<src.size(); i++) { | |
| 147 | + Mat buffer; | |
| 148 | + flip(src[i], buffer, axis); | |
| 149 | + dst.append(Template(src[i].file,buffer)); | |
| 150 | + | |
| 151 | + dst.last().file.setPoints(QtUtils::flipPoints(dst.last().file.points(),src[i].m().rows,src[i].m().cols)); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + void project(const Template &src, Template &dst) const { | |
| 156 | + TemplateList temp; | |
| 157 | + project(TemplateList() << src, temp); | |
| 158 | + if (!temp.isEmpty()) dst = temp.first(); | |
| 146 | 159 | } |
| 147 | 160 | }; |
| 148 | 161 | |
| 149 | 162 | BR_REGISTER(Transform, FlipTransform) |
| 150 | 163 | |
| 164 | +/*! | |
| 165 | + * \ingroup transforms | |
| 166 | + * \brief Randomly rotates an image in a specified range. | |
| 167 | + * \author Scott Klum \cite sklum | |
| 168 | + */ | |
| 169 | +class RandRotateTransform : public UntrainableTransform | |
| 170 | +{ | |
| 171 | + Q_OBJECT | |
| 172 | + | |
| 173 | + Q_PROPERTY(QList<int> range READ get_range WRITE set_range RESET reset_range STORED false) | |
| 174 | + BR_PROPERTY(QList<int>, range, QList<int>() << -15 << 15) | |
| 175 | + | |
| 176 | + void project(const Template &src, Template &dst) const { | |
| 177 | + int span = range.first() - range.last(); | |
| 178 | + int angle = (rand() % span) + range.first(); | |
| 179 | + Mat rotMatrix = getRotationMatrix2D(Point2f(src.m().rows/2,src.m().cols/2),angle,1.0); | |
| 180 | + warpAffine(src,dst,rotMatrix,Size(src.m().cols,src.m().rows)); | |
| 181 | + | |
| 182 | + QList<QPointF> points = src.file.points(); | |
| 183 | + QList<QPointF> rotatedPoints; | |
| 184 | + for (int i=0; i<points.size(); i++) { | |
| 185 | + rotatedPoints.append(QPointF(points.at(i).x()*rotMatrix.at<double>(0,0)+ | |
| 186 | + points.at(i).y()*rotMatrix.at<double>(0,1)+ | |
| 187 | + rotMatrix.at<double>(0,2), | |
| 188 | + points.at(i).x()*rotMatrix.at<double>(1,0)+ | |
| 189 | + points.at(i).y()*rotMatrix.at<double>(1,1)+ | |
| 190 | + rotMatrix.at<double>(1,2))); | |
| 191 | + } | |
| 192 | + | |
| 193 | + dst.file.setPoints(rotatedPoints); | |
| 194 | + } | |
| 195 | +}; | |
| 196 | + | |
| 197 | +BR_REGISTER(Transform, RandRotateTransform) | |
| 198 | + | |
| 151 | 199 | } // namespace br |
| 152 | 200 | |
| 153 | 201 | #include "register.moc" | ... | ... |