Commit 08aa0682ba3c1759abebc3632df405f405979db2
1 parent
0b581c79
Add a class for treating videos as galleries
Add a gallery class for videos, treating each frame as a separate template in a templatelist. Currently only uses the .avi file extension, other formats can be read via something like "Open!other_operations," and I'm not aware of a pressing reason to support output to other video containers Signed-off-by: caotto <ottochar@gmail.com>
Showing
1 changed file
with
61 additions
and
1 deletions
sdk/plugins/gallery.cpp
| ... | ... | @@ -27,6 +27,7 @@ |
| 27 | 27 | #include "core/bee.h" |
| 28 | 28 | #include "core/opencvutils.h" |
| 29 | 29 | #include "core/qtutils.h" |
| 30 | +#include <opencv2/highgui/highgui.hpp> | |
| 30 | 31 | |
| 31 | 32 | namespace br |
| 32 | 33 | { |
| ... | ... | @@ -158,10 +159,69 @@ class DefaultGallery : public Gallery |
| 158 | 159 | OpenCVUtils::saveImage(t, file.name); |
| 159 | 160 | } |
| 160 | 161 | }; |
| 161 | - | |
| 162 | 162 | BR_REGISTER(Gallery, DefaultGallery) |
| 163 | 163 | |
| 164 | 164 | /*! |
| 165 | + * \ingroup galleries | |
| 166 | + * \brief Treat a video as a gallery, making a single template from each frame | |
| 167 | + * \author Charles Otto \cite caotto | |
| 168 | + */ | |
| 169 | +class aviGallery : public Gallery | |
| 170 | +{ | |
| 171 | + Q_OBJECT | |
| 172 | + | |
| 173 | + TemplateList output_set; | |
| 174 | + QScopedPointer<cv::VideoWriter> videoOut; | |
| 175 | + | |
| 176 | + ~aviGallery() | |
| 177 | + { | |
| 178 | + if (videoOut && videoOut->isOpened()) videoOut->release(); | |
| 179 | + } | |
| 180 | + | |
| 181 | + TemplateList readBlock(bool * done) | |
| 182 | + { | |
| 183 | + std::string fname = file.name.toStdString(); | |
| 184 | + *done = true; | |
| 185 | + | |
| 186 | + TemplateList output; | |
| 187 | + if (!file.exists()) | |
| 188 | + return output; | |
| 189 | + | |
| 190 | + cv::VideoCapture videoReader(file.name.toStdString()); | |
| 191 | + | |
| 192 | + bool open = videoReader.isOpened(); | |
| 193 | + | |
| 194 | + while (open) { | |
| 195 | + cv::Mat frame; | |
| 196 | + | |
| 197 | + open = videoReader.read(frame); | |
| 198 | + if (!open) break; | |
| 199 | + output.append(Template()); | |
| 200 | + output.back() = frame.clone(); | |
| 201 | + } | |
| 202 | + | |
| 203 | + return TemplateList(); | |
| 204 | + } | |
| 205 | + | |
| 206 | + void write(const Template & t) | |
| 207 | + { | |
| 208 | + if (videoOut.isNull() || !videoOut->isOpened()) { | |
| 209 | + videoOut.reset(new cv::VideoWriter(qPrintable(file.name), CV_FOURCC('x','2','6','4'), 30, t.m().size())); | |
| 210 | + } | |
| 211 | + | |
| 212 | + if (!videoOut->isOpened()) { | |
| 213 | + qWarning("Failed to open %s for writing\n", qPrintable(file.name)); | |
| 214 | + return; | |
| 215 | + } | |
| 216 | + | |
| 217 | + foreach(const cv::Mat & m, t) { | |
| 218 | + videoOut->write(m); | |
| 219 | + } | |
| 220 | + } | |
| 221 | +}; | |
| 222 | +BR_REGISTER(Gallery, aviGallery) | |
| 223 | + | |
| 224 | +/*! | |
| 165 | 225 | * \ingroup initializers |
| 166 | 226 | * \brief Initialization support for memGallery. |
| 167 | 227 | * \author Josh Klontz \cite jklontz | ... | ... |