Commit d177a4591d77e90c11cf763dac8d70e69c818f0b

Authored by Charles Otto
1 parent c919513d

Add a transform that can be used to incrementally save frames to disk through the gallery interface

Showing 1 changed file with 66 additions and 0 deletions
openbr/plugins/misc.cpp
@@ -470,6 +470,72 @@ class RestoreMatTransform : public UntrainableMetaTransform @@ -470,6 +470,72 @@ class RestoreMatTransform : public UntrainableMetaTransform
470 BR_REGISTER(Transform, RestoreMatTransform) 470 BR_REGISTER(Transform, RestoreMatTransform)
471 471
472 472
  473 +/*!
  474 + * \ingroup transforms
  475 + * \brief Incrementally output templates received to a gallery, based on the current filename
  476 + * When a template is received in projectUpdate for the first time since a finalize, open a new gallery based on the
  477 + * template's filename, and the galleryFormat property.
  478 + * Templates received in projectUpdate will be output to the gallery with a filename combining their original filename and
  479 + * their FrameNumber property, with the file extension specified by the fileFormat property.
  480 + * \author Charles Otto \cite caotto
  481 + */
  482 +class IncrementalOutputTransform : public TimeVaryingTransform
  483 +{
  484 + Q_OBJECT
  485 +
  486 + Q_PROPERTY(QString galleryFormat READ get_galleryFormat WRITE set_galleryFormat RESET reset_galleryFormat STORED false)
  487 + Q_PROPERTY(QString fileFormat READ get_fileFormat WRITE set_fileFormat RESET reset_fileFormat STORED false)
  488 + BR_PROPERTY(QString, galleryFormat, "")
  489 + BR_PROPERTY(QString, fileFormat, ".png")
  490 +
  491 + bool galleryUp;
  492 +
  493 + void projectUpdate(const TemplateList &src, TemplateList &dst)
  494 + {
  495 + if (src.empty())
  496 + return;
  497 +
  498 + if (!galleryUp) {
  499 + QFileInfo finfo(src[0].file.name);
  500 + QString galleryName = finfo.baseName() + galleryFormat;
  501 +
  502 + writer = QSharedPointer<Gallery> (Factory<Gallery>::make(galleryName));
  503 + galleryUp = true;
  504 + }
  505 +
  506 + dst = src;
  507 + foreach(const Template & t, src) {
  508 + if (t.empty())
  509 + continue;
  510 +
  511 + // Build the output filename for this template
  512 + QFileInfo finfo(t.file.name);
  513 + QString outputName = finfo.baseName() +"_" + t.file.get<QString>("FrameNumber") + fileFormat;
  514 +
  515 + Template out = t;
  516 + out.file.name = outputName;
  517 + writer->write(out);
  518 + }
  519 + }
  520 +
  521 + void train(const TemplateList& data)
  522 + {
  523 + (void) data;
  524 + }
  525 +
  526 + // Drop the current gallery.
  527 + void finalize(TemplateList & data)
  528 + {
  529 + galleryUp = false;
  530 + }
  531 +
  532 + QSharedPointer<Gallery> writer;
  533 +public:
  534 + IncrementalOutputTransform() : TimeVaryingTransform(false,false) {galleryUp = false;}
  535 +};
  536 +
  537 +BR_REGISTER(Transform, IncrementalOutputTransform)
  538 +
473 class EventTransform : public UntrainableMetaTransform 539 class EventTransform : public UntrainableMetaTransform
474 { 540 {
475 Q_OBJECT 541 Q_OBJECT