Commit 5030971401a8dfe92f6d0ae32c0a668e480c11e0
1 parent
b18c77d1
Transform to compute the mean image from templates and write as image
Showing
1 changed file
with
47 additions
and
1 deletions
openbr/plugins/draw.cpp
| @@ -554,12 +554,58 @@ class WriteImageTransform : public TimeVaryingTransform | @@ -554,12 +554,58 @@ class WriteImageTransform : public TimeVaryingTransform | ||
| 554 | { | 554 | { |
| 555 | dst = src; | 555 | dst = src; |
| 556 | OpenCVUtils::saveImage(dst.m(), QString("%1/%2_%3.%4").arg(outputDirectory).arg(imageName).arg(cnt++, 5, QChar('0')).arg(imgExtension)); | 556 | OpenCVUtils::saveImage(dst.m(), QString("%1/%2_%3.%4").arg(outputDirectory).arg(imageName).arg(cnt++, 5, QChar('0')).arg(imgExtension)); |
| 557 | -qDebug() << "AT " << cnt; | ||
| 558 | } | 557 | } |
| 559 | 558 | ||
| 560 | }; | 559 | }; |
| 561 | BR_REGISTER(Transform, WriteImageTransform) | 560 | BR_REGISTER(Transform, WriteImageTransform) |
| 562 | 561 | ||
| 562 | + | ||
| 563 | +/** | ||
| 564 | + * @brief The MeanImageTransform class computes the average template/image | ||
| 565 | + * and save the result as an encoded image. | ||
| 566 | + */ | ||
| 567 | +class MeanImageTransform : public TimeVaryingTransform | ||
| 568 | +{ | ||
| 569 | + Q_OBJECT | ||
| 570 | + | ||
| 571 | + Q_PROPERTY(QString imgname READ get_imgname WRITE set_imgname RESET reset_imgname STORED false) | ||
| 572 | + Q_PROPERTY(QString ext READ get_ext WRITE set_ext RESET reset_ext STORED false) | ||
| 573 | + | ||
| 574 | + BR_PROPERTY(QString, imgname, "average") | ||
| 575 | + BR_PROPERTY(QString, ext, "jpg") | ||
| 576 | + | ||
| 577 | + Mat average; | ||
| 578 | + int cnt; | ||
| 579 | + | ||
| 580 | + void init() | ||
| 581 | + { | ||
| 582 | + cnt = 0; | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + void projectUpdate(const Template &src, Template &dst) | ||
| 586 | + { | ||
| 587 | + dst = src; | ||
| 588 | + if (cnt == 0) | ||
| 589 | + average = Mat::zeros(dst.m().size(),dst.m().type()); | ||
| 590 | + average += dst; | ||
| 591 | + cnt++; | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + virtual void finalize(TemplateList & output) | ||
| 595 | + { | ||
| 596 | + average /= cnt; | ||
| 597 | + imwrite(QString("%1.%2").arg(imgname).arg(ext).toStdString(), average); | ||
| 598 | + output = TemplateList(); | ||
| 599 | + } | ||
| 600 | + | ||
| 601 | + | ||
| 602 | +public: | ||
| 603 | + MeanImageTransform() : TimeVaryingTransform(true, false) {} | ||
| 604 | +}; | ||
| 605 | + | ||
| 606 | +BR_REGISTER(Transform, MeanImageTransform) | ||
| 607 | + | ||
| 608 | + | ||
| 563 | // TODO: re-implement EditTransform using Qt | 609 | // TODO: re-implement EditTransform using Qt |
| 564 | #if 0 | 610 | #if 0 |
| 565 | /*! | 611 | /*! |