From 08aa0682ba3c1759abebc3632df405f405979db2 Mon Sep 17 00:00:00 2001 From: caotto Date: Thu, 14 Feb 2013 15:43:06 -0500 Subject: [PATCH] Add a class for treating videos as galleries --- sdk/plugins/gallery.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/sdk/plugins/gallery.cpp b/sdk/plugins/gallery.cpp index d46d388..fe3729c 100644 --- a/sdk/plugins/gallery.cpp +++ b/sdk/plugins/gallery.cpp @@ -27,6 +27,7 @@ #include "core/bee.h" #include "core/opencvutils.h" #include "core/qtutils.h" +#include namespace br { @@ -158,10 +159,69 @@ class DefaultGallery : public Gallery OpenCVUtils::saveImage(t, file.name); } }; - BR_REGISTER(Gallery, DefaultGallery) /*! + * \ingroup galleries + * \brief Treat a video as a gallery, making a single template from each frame + * \author Charles Otto \cite caotto + */ +class aviGallery : public Gallery +{ + Q_OBJECT + + TemplateList output_set; + QScopedPointer videoOut; + + ~aviGallery() + { + if (videoOut && videoOut->isOpened()) videoOut->release(); + } + + TemplateList readBlock(bool * done) + { + std::string fname = file.name.toStdString(); + *done = true; + + TemplateList output; + if (!file.exists()) + return output; + + cv::VideoCapture videoReader(file.name.toStdString()); + + bool open = videoReader.isOpened(); + + while (open) { + cv::Mat frame; + + open = videoReader.read(frame); + if (!open) break; + output.append(Template()); + output.back() = frame.clone(); + } + + return TemplateList(); + } + + void write(const Template & t) + { + if (videoOut.isNull() || !videoOut->isOpened()) { + videoOut.reset(new cv::VideoWriter(qPrintable(file.name), CV_FOURCC('x','2','6','4'), 30, t.m().size())); + } + + if (!videoOut->isOpened()) { + qWarning("Failed to open %s for writing\n", qPrintable(file.name)); + return; + } + + foreach(const cv::Mat & m, t) { + videoOut->write(m); + } + } +}; +BR_REGISTER(Gallery, aviGallery) + +/*! * \ingroup initializers * \brief Initialization support for memGallery. * \author Josh Klontz \cite jklontz -- libgit2 0.21.4