Commit e6376e0e624017edaf549b4358ef3dec7b12783c

Authored by Scott Klum
1 parent d159dc08

Moved some transforms to more recognizable plugins

openbr/plugins/draw.cpp
@@ -213,6 +213,41 @@ class DrawGridTransform : public UntrainableTransform @@ -213,6 +213,41 @@ class DrawGridTransform : public UntrainableTransform
213 213
214 BR_REGISTER(Transform, DrawGridTransform) 214 BR_REGISTER(Transform, DrawGridTransform)
215 215
  216 +/*!
  217 + * \ingroup transforms
  218 + * \brief Computes the mean of a set of templates.
  219 + * \note Suitable for visualization only as it sets every projected template to the mean template.
  220 + * \author Scott Klum \cite sklum
  221 + */
  222 +class MeanTransform : public Transform
  223 +{
  224 + Q_OBJECT
  225 +
  226 + Mat mean;
  227 +
  228 + void train(const TemplateList &data)
  229 + {
  230 + mean = Mat::zeros(data[0].m().rows,data[0].m().cols,CV_32F);
  231 +
  232 + for (int i = 0; i < data.size(); i++) {
  233 + Mat converted;
  234 + data[i].m().convertTo(converted, CV_32F);
  235 + mean += converted;
  236 + }
  237 +
  238 + mean /= data.size();
  239 + }
  240 +
  241 + void project(const Template &src, Template &dst) const
  242 + {
  243 + dst = src;
  244 + dst.m() = mean;
  245 + }
  246 +
  247 +};
  248 +
  249 +BR_REGISTER(Transform, MeanTransform)
  250 +
216 // TODO: re-implement EditTransform using Qt 251 // TODO: re-implement EditTransform using Qt
217 #if 0 252 #if 0
218 /*! 253 /*!
openbr/plugins/gui.cpp
@@ -67,6 +67,10 @@ public: @@ -67,6 +67,10 @@ public:
67 { 67 {
68 wait.wakeAll(); 68 wait.wakeAll();
69 } 69 }
  70 + else if (event->type() == QEvent::MouseButtonPress)
  71 + {
  72 + qDebug() << "hey there";
  73 + }
70 return QObject::eventFilter(obj, event); 74 return QObject::eventFilter(obj, event);
71 } 75 }
72 76
openbr/plugins/landmarks.cpp
@@ -149,13 +149,9 @@ class DelaunayTransform : public UntrainableTransform @@ -149,13 +149,9 @@ class DelaunayTransform : public UntrainableTransform
149 Q_OBJECT 149 Q_OBJECT
150 150
151 Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false) 151 Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false)
152 - Q_PROPERTY(QString widthCrop READ get_widthCrop WRITE set_widthCrop RESET reset_widthCrop STORED false)  
153 - Q_PROPERTY(QString heightCrop READ get_heightCrop WRITE set_heightCrop RESET reset_heightCrop STORED false)  
154 Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false) 152 Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false)
155 Q_PROPERTY(bool draw READ get_draw WRITE set_draw RESET reset_draw STORED false) 153 Q_PROPERTY(bool draw READ get_draw WRITE set_draw RESET reset_draw STORED false)
156 BR_PROPERTY(float, scaleFactor, 1) 154 BR_PROPERTY(float, scaleFactor, 1)
157 - BR_PROPERTY(QString, widthCrop, QString())  
158 - BR_PROPERTY(QString, heightCrop, QString())  
159 BR_PROPERTY(bool, warp, true) 155 BR_PROPERTY(bool, warp, true)
160 BR_PROPERTY(bool, draw, false) 156 BR_PROPERTY(bool, draw, false)
161 157
@@ -289,13 +285,7 @@ class DelaunayTransform : public UntrainableTransform @@ -289,13 +285,7 @@ class DelaunayTransform : public UntrainableTransform
289 } 285 }
290 286
291 Rect boundingBox = boundingRect(mappedPoints.toVector().toStdVector()); 287 Rect boundingBox = boundingRect(mappedPoints.toVector().toStdVector());
292 -  
293 - boundingBox.x += boundingBox.width * QtUtils::toPoint(widthCrop).x();  
294 - boundingBox.y += boundingBox.height * QtUtils::toPoint(heightCrop).x();  
295 - boundingBox.width *= 1-QtUtils::toPoint(widthCrop).y();  
296 - boundingBox.height *= 1-QtUtils::toPoint(heightCrop).y();  
297 -  
298 - dst.m() = Mat(dst.m(), boundingBox); 288 + dst.file.appendRect(OpenCVUtils::fromRect(boundingBox));
299 } 289 }
300 } 290 }
301 291
@@ -303,41 +293,6 @@ class DelaunayTransform : public UntrainableTransform @@ -303,41 +293,6 @@ class DelaunayTransform : public UntrainableTransform
303 293
304 BR_REGISTER(Transform, DelaunayTransform) 294 BR_REGISTER(Transform, DelaunayTransform)
305 295
306 -/*!  
307 - * \ingroup transforms  
308 - * \brief Computes the mean of a set of templates.  
309 - * \note Suitable for visualization only as it sets every projected template to the mean template.  
310 - * \author Scott Klum \cite sklum  
311 - */  
312 -class MeanTransform : public Transform  
313 -{  
314 - Q_OBJECT  
315 -  
316 - Mat mean;  
317 -  
318 - void train(const TemplateList &data)  
319 - {  
320 - mean = Mat::zeros(data[0].m().rows,data[0].m().cols,CV_32F);  
321 -  
322 - for (int i = 0; i < data.size(); i++) {  
323 - Mat converted;  
324 - data[i].m().convertTo(converted, CV_32F);  
325 - mean += converted;  
326 - }  
327 -  
328 - mean /= data.size();  
329 - }  
330 -  
331 - void project(const Template &src, Template &dst) const  
332 - {  
333 - dst = src;  
334 - dst.m() = mean;  
335 - }  
336 -  
337 -};  
338 -  
339 -BR_REGISTER(Transform, MeanTransform)  
340 -  
341 } // namespace br 296 } // namespace br
342 297
343 #include "landmarks.moc" 298 #include "landmarks.moc"
openbr/plugins/misc.cpp
@@ -516,52 +516,6 @@ class RestoreMatTransform : public UntrainableMetaTransform @@ -516,52 +516,6 @@ class RestoreMatTransform : public UntrainableMetaTransform
516 }; 516 };
517 BR_REGISTER(Transform, RestoreMatTransform) 517 BR_REGISTER(Transform, RestoreMatTransform)
518 518
519 -/*!  
520 - * \ingroup transforms  
521 - * \brief Expand the width and height of a template's rects by input width and height factors.  
522 - * \author Charles Otto \cite caotto  
523 - */  
524 -class ExpandRectTransform : public UntrainableTransform  
525 -{  
526 - Q_OBJECT  
527 - Q_PROPERTY(float widthExpand READ get_widthExpand WRITE set_widthExpand RESET reset_widthExpand STORED false)  
528 - Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false)  
529 - BR_PROPERTY(float, widthExpand, .5)  
530 - BR_PROPERTY(float, heightExpand, .5)  
531 - void project(const Template &src, Template &dst) const  
532 - {  
533 - dst = src;  
534 - QList<QRectF> rects = dst.file.rects();  
535 - for (int i=0;i < rects.size(); i++) {  
536 - QRectF rect = rects[i];  
537 -  
538 - qreal width = rect.width();  
539 - qreal height = rect.height();  
540 - float half_w_expansion = widthExpand / 2;  
541 - float half_h_expansion = heightExpand / 2;  
542 -  
543 - qreal half_width = width * widthExpand;  
544 - qreal quarter_width = width * half_w_expansion;  
545 - qreal half_height = height * heightExpand;  
546 - qreal quarter_height = height * half_h_expansion;  
547 -  
548 - rect.setX(std::max(qreal(0),(rect.x() - quarter_width)));  
549 - rect.setY(std::max(qreal(0),(rect.y() - quarter_height)));  
550 -  
551 - qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1);  
552 - qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1);  
553 -  
554 - rect.setWidth(x2 - rect.x());  
555 - rect.setHeight(y2 - rect.y());  
556 -  
557 - rects[i] = rect;  
558 - }  
559 - dst.file.setRects(rects);  
560 - }  
561 -};  
562 -  
563 -BR_REGISTER(Transform, ExpandRectTransform)  
564 -  
565 519
566 class EventTransform : public UntrainableMetaTransform 520 class EventTransform : public UntrainableMetaTransform
567 { 521 {
openbr/plugins/regions.cpp
@@ -191,6 +191,87 @@ BR_REGISTER(Transform, DupTransform) @@ -191,6 +191,87 @@ BR_REGISTER(Transform, DupTransform)
191 191
192 /*! 192 /*!
193 * \ingroup transforms 193 * \ingroup transforms
  194 + * \brief Expand the width and height of a template's rects by input width and height factors.
  195 + * \author Charles Otto \cite caotto
  196 + */
  197 +class ExpandRectTransform : public UntrainableTransform
  198 +{
  199 + Q_OBJECT
  200 + Q_PROPERTY(float widthExpand READ get_widthExpand WRITE set_widthExpand RESET reset_widthExpand STORED false)
  201 + Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false)
  202 + BR_PROPERTY(float, widthExpand, .5)
  203 + BR_PROPERTY(float, heightExpand, .5)
  204 + void project(const Template &src, Template &dst) const
  205 + {
  206 + dst = src;
  207 + QList<QRectF> rects = dst.file.rects();
  208 + for (int i=0;i < rects.size(); i++) {
  209 + QRectF rect = rects[i];
  210 +
  211 + qreal width = rect.width();
  212 + qreal height = rect.height();
  213 + float half_w_expansion = widthExpand / 2;
  214 + float half_h_expansion = heightExpand / 2;
  215 +
  216 + qreal half_width = width * widthExpand;
  217 + qreal quarter_width = width * half_w_expansion;
  218 + qreal half_height = height * heightExpand;
  219 + qreal quarter_height = height * half_h_expansion;
  220 +
  221 + rect.setX(std::max(qreal(0),(rect.x() - quarter_width)));
  222 + rect.setY(std::max(qreal(0),(rect.y() - quarter_height)));
  223 +
  224 + qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1);
  225 + qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1);
  226 +
  227 + rect.setWidth(x2 - rect.x());
  228 + rect.setHeight(y2 - rect.y());
  229 +
  230 + rects[i] = rect;
  231 + }
  232 + dst.file.setRects(rects);
  233 + }
  234 +};
  235 +
  236 +BR_REGISTER(Transform, ExpandRectTransform)
  237 +
  238 +/*!
  239 + * \ingroup transforms
  240 + * \brief Crops the width and height of a template's rects by input width and height factors.
  241 + * \author Scott Klum \cite sklum
  242 + */
  243 +class CropRectTransform : public UntrainableTransform
  244 +{
  245 + Q_OBJECT
  246 +
  247 + Q_PROPERTY(QString widthCrop READ get_widthCrop WRITE set_widthCrop RESET reset_widthCrop STORED false)
  248 + Q_PROPERTY(QString heightCrop READ get_heightCrop WRITE set_heightCrop RESET reset_heightCrop STORED false)
  249 + BR_PROPERTY(QString, widthCrop, QString())
  250 + BR_PROPERTY(QString, heightCrop, QString())
  251 +
  252 + void project(const Template &src, Template &dst) const
  253 + {
  254 + dst = src;
  255 + QList<QRectF> rects = dst.file.rects();
  256 + for (int i=0;i < rects.size(); i++) {
  257 + QRectF rect = rects[i];
  258 +
  259 + // Do a bit of error checking
  260 + rect.x += rect.width * QtUtils::toPoint(widthCrop).x();
  261 + rect.y += rect.height * QtUtils::toPoint(heightCrop).x();
  262 + rect.width *= 1-QtUtils::toPoint(widthCrop).y();
  263 + rect.height *= 1-QtUtils::toPoint(heightCrop).y();
  264 +
  265 + dst.m() = Mat(dst.m(), rect);
  266 + }
  267 + dst.file.setRects(rects);
  268 + }
  269 +};
  270 +
  271 +BR_REGISTER(Transform, CropRectTransform)
  272 +
  273 +/*!
  274 + * \ingroup transforms
194 * \brief Create matrix from landmarks. 275 * \brief Create matrix from landmarks.
195 * \author Scott Klum \cite sklum 276 * \author Scott Klum \cite sklum
196 * \todo Padding should be a percent of total image size 277 * \todo Padding should be a percent of total image size