Commit 6ab3d0c5687b3b702c644ea061ddcbe744261fe9

Authored by Scott Klum
1 parent 1c003ddc

Separated point reordering functionality, reverted openbr_plugin change such tha…

…t Fork is not affected
openbr/openbr_plugin.cpp
... ... @@ -81,10 +81,8 @@ QString File::hash() const
81 81  
82 82 void File::append(const QVariantMap &metadata)
83 83 {
84   - foreach (const QString &key, metadata.keys()) {
85   - if (key != "Points" && key != "Rects")
86   - set(key, metadata[key]);
87   - }
  84 + foreach (const QString &key, metadata.keys())
  85 + set(key, metadata[key]);
88 86 }
89 87  
90 88 void File::append(const File &other)
... ... @@ -98,8 +96,6 @@ void File::append(const File &other)
98 96 }
99 97 }
100 98 append(other.m_metadata);
101   - appendPoints(other.points());
102   - appendRects(other.rects());
103 99 }
104 100  
105 101 QList<File> File::split() const
... ...
openbr/plugins/algorithms.cpp
... ... @@ -79,10 +79,10 @@ class AlgorithmsInitializer : public Initializer
79 79 Globals->abbreviations.insert("RegisterAffine", "Open+Affine(256,256,0.37,0.45)");
80 80 Globals->abbreviations.insert("ContrastEnhanced", "Open+Affine(256,256,0.37,0.45)+Cvt(Gray)+Blur(1.1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)");
81 81 Globals->abbreviations.insert("ColoredLBP", "Open+Affine(128,128,0.37,0.45)+Cvt(Gray)+Blur(1.1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)+LBP(1,2)+ColoredU2");
82   - Globals->abbreviations.insert("FlipMUCT","Flip(from=[ 0, 1, 2, 3, 4, 5, 6, 7, 17,18,19,20,21,31,32,36,37,38,39,40,41,48,49,50,55,56,60,61,65], \
83   - to=[16,15,14,13,12,11,10, 9, 26,25,24,23,22,35,34,45,44,43,42,47,46,54,53,52,59,58,64,63,67])");
84   - Globals->abbreviations.insert("FlipMUCTNoJaw","Flip(from=[0,1,2,3,4,14,15,19,20,21,22,23,24,31,32,33,38,39,43,44,48], \
85   - to=[9,8,7,6,5,18,17,28,27,26,25,30,29,37,36,35,42,41,47,46,50])");
  82 + Globals->abbreviations.insert("FlipMUCT","Flip+ReorderPoints([ 0, 1, 2, 3, 4, 5, 6, 7, 17,18,19,20,21,31,32,36,37,38,39,40,41,48,49,50,55,56,60,61,65], \
  83 + to=[16,15,14,13,12,11,10, 9, 26,25,24,23,22,35,34,45,44,43,42,47,46,54,53,52,59,58,64,63,67],true)");
  84 + Globals->abbreviations.insert("FlipMUCTNoJaw","Flip+ReorderPoints([0,1,2,3,4,14,15,19,20,21,22,23,24,31,32,33,38,39,43,44,48], \
  85 + [9,8,7,6,5,18,17,28,27,26,25,30,29,37,36,35,42,41,47,46,50],true)");
86 86  
87 87 // Transforms
88 88 Globals->abbreviations.insert("FaceDetection", "Open+Cvt(Gray)+Cascade(FrontalFace)");
... ...
openbr/plugins/regions.cpp
... ... @@ -246,8 +246,16 @@ class DupTransform : public UntrainableMetaTransform
246 246  
247 247 void project(const Template &src, Template &dst) const
248 248 {
  249 + QList<QPointF> points = src.file.points();
  250 + QList<QRectF> rects = src.file.rects();
  251 +
249 252 for (int i=0; i<n; i++)
250 253 dst.merge(src);
  254 +
  255 + for (int i=1; i<n; i++) {
  256 + dst.file.appendPoints(points);
  257 + dst.file.appendRects(rects);
  258 + }
251 259 }
252 260 };
253 261  
... ...
openbr/plugins/register.cpp
... ... @@ -124,17 +124,12 @@ BR_REGISTER(Transform, AffineTransform)
124 124 * \ingroup transforms
125 125 * \brief Flips the image about an axis.
126 126 * \author Josh Klontz \cite jklontz
127   - * \note In the case that you would like to flip both the image and the template's points but keep the indices for
128   - * the points consistent between flipped an unflipped images, the to and from variables specify which indices
129   - * to swap (i.e. points[from[0]] becomes points[to[0]] and vice versa).
130 127 */
131 128 class FlipTransform : public UntrainableMetaTransform
132 129 {
133 130 Q_OBJECT
134 131 Q_ENUMS(Axis)
135 132 Q_PROPERTY(Axis axis READ get_axis WRITE set_axis RESET reset_axis STORED false)
136   - Q_PROPERTY(QList<int> from READ get_from WRITE set_from RESET reset_from STORED false)
137   - Q_PROPERTY(QList<int> to READ get_to WRITE set_to RESET reset_to STORED false)
138 133  
139 134 public:
140 135 /*!< */
... ... @@ -144,34 +139,29 @@ public:
144 139  
145 140 private:
146 141 BR_PROPERTY(Axis, axis, Y)
147   - BR_PROPERTY(QList<int>, from, QList<int>())
148   - BR_PROPERTY(QList<int>, to, QList<int>())
149 142  
150 143 void project(const TemplateList &src, TemplateList &dst) const
151 144 {
152   - dst.append(src.first());
153 145 for (int i=0; i<src.size(); i++) {
  146 + dst.append(src[i]);
  147 +
154 148 Mat buffer;
155 149 flip(src[i], buffer, axis);
156 150 dst.append(Template(src[i].file,buffer));
157 151  
158   - if (from.size() == to.size()) {
159   - QList<QPointF> flippedPoints;
160   - foreach(const QPointF &point, dst.last().file.points()) {
161   - if (axis == Y) {
162   - flippedPoints.append(QPointF(src[i].m().cols-point.x(),point.y()));
163   - } else if (axis == X) {
164   - flippedPoints.append(QPointF(point.x(),src[i].m().rows-point.y()));
165   - } else {
166   - flippedPoints.append(QPointF(src[i].m().cols-point.x(),src[i].m().rows-point.y()));
167   - }
  152 + QList<QPointF> flippedPoints;
  153 + foreach(const QPointF &point, src.last().file.points()) {
  154 + if (axis == Y) {
  155 + flippedPoints.append(QPointF(src[i].m().cols-point.x(),point.y()));
  156 + } else if (axis == X) {
  157 + flippedPoints.append(QPointF(point.x(),src[i].m().rows-point.y()));
  158 + } else {
  159 + flippedPoints.append(QPointF(src[i].m().cols-point.x(),src[i].m().rows-point.y()));
168 160 }
  161 + }
169 162  
170   - for (int j=0; j<from.size(); j++)
171   - std::swap(flippedPoints[from[j]],flippedPoints[to[j]]);
172   -
173   - dst.last().file.setPoints(flippedPoints);
174   - } else qFatal("Inconsistent sizes for to and from index lists.");
  163 + dst.last().file.setPoints(flippedPoints);
  164 + dst.last().file.set("Flipped",true);
175 165 }
176 166 }
177 167  
... ...
openbr/plugins/template.cpp
... ... @@ -207,6 +207,41 @@ public:
207 207  
208 208 BR_REGISTER(Transform, FilterDupeMetadataTransform)
209 209  
  210 +/*!
  211 + * \ingroup transforms
  212 + * \brief Reorder the points such that points[from[i]] becomes points[to[i]] and
  213 + * vice versa
  214 + * \author Scott Klum \cite sklum
  215 + */
  216 +class ReorderPointsTransform : public UntrainableMetadataTransform
  217 +{
  218 + Q_OBJECT
  219 +
  220 + Q_PROPERTY(QList<int> from READ get_from WRITE set_from RESET reset_from STORED false)
  221 + Q_PROPERTY(QList<int> to READ get_to WRITE set_to RESET reset_to STORED false)
  222 + Q_PROPERTY(bool flippedOnly READ get_flippedOnly WRITE set_flippedOnly RESET reset_flippedOnly STORED false)
  223 + BR_PROPERTY(QList<int>, from, QList<int>())
  224 + BR_PROPERTY(QList<int>, to, QList<int>())
  225 + BR_PROPERTY(bool, flippedOnly, false)
  226 +
  227 + void projectMetadata(const File &src, File &dst) const
  228 + {
  229 + if (flippedOnly && !src.contains("Flipped")) {
  230 + dst = src;
  231 + return;
  232 + }
  233 +
  234 + if (from.size() == to.size()) {
  235 + QList<QPointF> points = src.points();
  236 + for (int i=0; i<from.size(); i++)
  237 + std::swap(points[from[i]],points[to[i]]);
  238 + dst.setPoints(points);
  239 + } else qFatal("Inconsistent sizes for to and from index lists.");
  240 + }
  241 +};
  242 +
  243 +BR_REGISTER(Transform, ReorderPointsTransform)
  244 +
210 245 } // namespace br
211 246  
212 247 #include "template.moc"
... ...