From bf1af0c9c909550bc077aca3a93801dfb8ed4eff Mon Sep 17 00:00:00 2001 From: Austin Blanton Date: Wed, 5 Feb 2014 18:26:15 -0500 Subject: [PATCH] Add vbbGallery (if cvmatio is being used) --- openbr/plugins/gallery.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+), 0 deletions(-) diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index bb1b4f2..7ff8e96 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -32,6 +32,11 @@ #include "openbr/core/opencvutils.h" #include "openbr/core/qtutils.h" +#ifdef CVMATIO +#include "MatlabIO.hpp" +#include "MatlabIOContainer.hpp" +#endif + namespace br { @@ -969,6 +974,82 @@ class landmarksGallery : public Gallery BR_REGISTER(Gallery, landmarksGallery) +#ifdef CVMATIO + +using namespace std; +using namespace cv; + +class vbbGallery : public Gallery +{ + Q_OBJECT + + void init() + { + MatlabIO matio; + QString filename = file.name; + bool ok = matio.open(filename.toStdString(), "r"); + if (!ok) qFatal("Couldn't open the vbb file"); + + vector variables; + variables = matio.read(); + matio.close(); + + double vers = variables[1].data().at(0,0); + if (vers != 1.4) qFatal("This is an old vbb version, we don't mess with that."); + + A = variables[0].data > >().at(0); + objLists = A.at(1).data >(); + + // start at the first frame (duh!) + currFrame = 0; + } + + TemplateList readBlock(bool *done) + { + *done = false; + TemplateList rects; + // if it's a Mat, there aren't any bounding boxes in that frame + // (i think that's the cvmatio default for an empty spot in a matlab array) + if (objLists[currFrame].typeEquals()) { + Template t(file); + t.file.set("FrameNumber", currFrame); + rects.append(Template(file)); + } else { + vector > bbs = objLists[currFrame].data > >(); + for (unsigned int i=0; i bb = bbs[i]; + Mat pos = bb[1].data(); + Template t = Template(file); + double left = pos.at(0,0); + double top = pos.at(0,1); + double width = pos.at(0,2); + double height = pos.at(0,3); + t.file.appendRect(QRectF(left, top, width, height)); + t.file.set("FrameNumber", currFrame); + rects.append(t); + } + } + if (++currFrame == (int)objLists.size()) *done = true; + return rects; + } + + void write(const Template &t) + { + (void)t; qFatal("Not implemented"); + } + +private: + // this holds a bunch of stuff, maybe we'll use it all later + vector A; + // this, a field in A, holds bounding boxes for each frame + vector objLists; + int currFrame; +}; + +BR_REGISTER(Gallery, vbbGallery) + +#endif + } // namespace br #include "gallery.moc" -- libgit2 0.21.4