Commit fa9cbd42f748af59f9985f8afd8ede607fc71f5d
1 parent
1aceddc3
Add 2 transforms, 1 projects remaining time in a job, the other outputs to a gallery
Showing
1 changed file
with
104 additions
and
0 deletions
openbr/plugins/misc.cpp
| @@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
| 14 | * limitations under the License. * | 14 | * limitations under the License. * |
| 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | ||
| 17 | +#include <QElapsedTimer> | ||
| 17 | #include <QRegularExpression> | 18 | #include <QRegularExpression> |
| 18 | #include <opencv2/highgui/highgui.hpp> | 19 | #include <opencv2/highgui/highgui.hpp> |
| 19 | #include "openbr_internal.h" | 20 | #include "openbr_internal.h" |
| @@ -517,6 +518,109 @@ class EventTransform : public UntrainableMetaTransform | @@ -517,6 +518,109 @@ class EventTransform : public UntrainableMetaTransform | ||
| 517 | }; | 518 | }; |
| 518 | BR_REGISTER(Transform, EventTransform) | 519 | BR_REGISTER(Transform, EventTransform) |
| 519 | 520 | ||
| 521 | + | ||
| 522 | +//ProgressCounter+Output | ||
| 523 | + | ||
| 524 | +class GalleryOutputTransform : public TimeVaryingTransform | ||
| 525 | +{ | ||
| 526 | + Q_OBJECT | ||
| 527 | + | ||
| 528 | + Q_PROPERTY(QString outputString READ get_outputString WRITE set_outputString RESET reset_outputString STORED false) | ||
| 529 | + BR_PROPERTY(QString, outputString, "") | ||
| 530 | + | ||
| 531 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | ||
| 532 | + { | ||
| 533 | + if (src.empty()) | ||
| 534 | + return; | ||
| 535 | + dst = src; | ||
| 536 | + writer->writeBlock(dst); | ||
| 537 | + } | ||
| 538 | + | ||
| 539 | + void train(const TemplateList& data) | ||
| 540 | + { | ||
| 541 | + (void) data; | ||
| 542 | + } | ||
| 543 | + ; | ||
| 544 | + void init() | ||
| 545 | + { | ||
| 546 | + writer = QSharedPointer<Gallery>(Gallery::make(outputString)); | ||
| 547 | + } | ||
| 548 | + | ||
| 549 | + QSharedPointer<Gallery> writer; | ||
| 550 | +public: | ||
| 551 | + GalleryOutputTransform() : TimeVaryingTransform(false,false) {} | ||
| 552 | +}; | ||
| 553 | + | ||
| 554 | +BR_REGISTER(Transform, GalleryOutputTransform) | ||
| 555 | + | ||
| 556 | +class ProgressCounterTransform : public TimeVaryingTransform | ||
| 557 | +{ | ||
| 558 | + Q_OBJECT | ||
| 559 | + | ||
| 560 | + Q_PROPERTY(int totalTemplates READ get_totalTemplates WRITE set_totalTemplates RESET reset_totalTemplates STORED false) | ||
| 561 | + BR_PROPERTY(int, totalTemplates, 1) | ||
| 562 | + | ||
| 563 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | ||
| 564 | + { | ||
| 565 | + dst = src; | ||
| 566 | + qint64 elapsed = timer.elapsed(); | ||
| 567 | + calls++; | ||
| 568 | + set_calls++; | ||
| 569 | + // updated every 10 seconds | ||
| 570 | + if (elapsed > 5 * 1000) { | ||
| 571 | + float f_elapsed = elapsed / 1000.0f; | ||
| 572 | + // remaining calls (according to our input variable) | ||
| 573 | + int remaining = totalTemplates - calls; | ||
| 574 | + // calls / second | ||
| 575 | + float speed = set_calls / f_elapsed; | ||
| 576 | + | ||
| 577 | + float p = 100 * float(calls) / totalTemplates; | ||
| 578 | + | ||
| 579 | + // seconds remaining | ||
| 580 | + int s = float(remaining) / speed; | ||
| 581 | + | ||
| 582 | + int h = s / (60*60); | ||
| 583 | + int m = (s - h*60*60) / 60; | ||
| 584 | + s = (s - h*60*60 - m*60); | ||
| 585 | + | ||
| 586 | + // hours:minutes:seconds | ||
| 587 | + fprintf(stderr, "%05.2f%% REMAINING=%02d:%02d:%02d COUNT=%g \r", p, h, m, s, float(calls)); | ||
| 588 | + | ||
| 589 | + timer.start(); | ||
| 590 | + set_calls = 0; | ||
| 591 | + } | ||
| 592 | + | ||
| 593 | + | ||
| 594 | + return; | ||
| 595 | + } | ||
| 596 | + | ||
| 597 | + void train(const TemplateList& data) | ||
| 598 | + { | ||
| 599 | + (void) data; | ||
| 600 | + } | ||
| 601 | + | ||
| 602 | + void finalize(TemplateList & data) | ||
| 603 | + { | ||
| 604 | + (void) data; | ||
| 605 | + } | ||
| 606 | + void init() | ||
| 607 | + { | ||
| 608 | + calls = 0; | ||
| 609 | + set_calls = 0; | ||
| 610 | + timer.start(); | ||
| 611 | + } | ||
| 612 | + | ||
| 613 | +public: | ||
| 614 | + ProgressCounterTransform() : TimeVaryingTransform(false,false) {} | ||
| 615 | + bool initialized; | ||
| 616 | + QElapsedTimer timer; | ||
| 617 | + qint64 calls; | ||
| 618 | + qint64 set_calls; | ||
| 619 | + | ||
| 620 | +}; | ||
| 621 | + | ||
| 622 | +BR_REGISTER(Transform, ProgressCounterTransform) | ||
| 623 | + | ||
| 520 | } | 624 | } |
| 521 | 625 | ||
| 522 | #include "misc.moc" | 626 | #include "misc.moc" |