Commit bf1af0c9c909550bc077aca3a93801dfb8ed4eff
1 parent
cb89d81b
Add vbbGallery (if cvmatio is being used)
Showing
1 changed file
with
81 additions
and
0 deletions
openbr/plugins/gallery.cpp
| @@ -32,6 +32,11 @@ | @@ -32,6 +32,11 @@ | ||
| 32 | #include "openbr/core/opencvutils.h" | 32 | #include "openbr/core/opencvutils.h" |
| 33 | #include "openbr/core/qtutils.h" | 33 | #include "openbr/core/qtutils.h" |
| 34 | 34 | ||
| 35 | +#ifdef CVMATIO | ||
| 36 | +#include "MatlabIO.hpp" | ||
| 37 | +#include "MatlabIOContainer.hpp" | ||
| 38 | +#endif | ||
| 39 | + | ||
| 35 | namespace br | 40 | namespace br |
| 36 | { | 41 | { |
| 37 | 42 | ||
| @@ -969,6 +974,82 @@ class landmarksGallery : public Gallery | @@ -969,6 +974,82 @@ class landmarksGallery : public Gallery | ||
| 969 | 974 | ||
| 970 | BR_REGISTER(Gallery, landmarksGallery) | 975 | BR_REGISTER(Gallery, landmarksGallery) |
| 971 | 976 | ||
| 977 | +#ifdef CVMATIO | ||
| 978 | + | ||
| 979 | +using namespace std; | ||
| 980 | +using namespace cv; | ||
| 981 | + | ||
| 982 | +class vbbGallery : public Gallery | ||
| 983 | +{ | ||
| 984 | + Q_OBJECT | ||
| 985 | + | ||
| 986 | + void init() | ||
| 987 | + { | ||
| 988 | + MatlabIO matio; | ||
| 989 | + QString filename = file.name; | ||
| 990 | + bool ok = matio.open(filename.toStdString(), "r"); | ||
| 991 | + if (!ok) qFatal("Couldn't open the vbb file"); | ||
| 992 | + | ||
| 993 | + vector<MatlabIOContainer> variables; | ||
| 994 | + variables = matio.read(); | ||
| 995 | + matio.close(); | ||
| 996 | + | ||
| 997 | + double vers = variables[1].data<Mat>().at<double>(0,0); | ||
| 998 | + if (vers != 1.4) qFatal("This is an old vbb version, we don't mess with that."); | ||
| 999 | + | ||
| 1000 | + A = variables[0].data<vector<vector<MatlabIOContainer> > >().at(0); | ||
| 1001 | + objLists = A.at(1).data<vector<MatlabIOContainer> >(); | ||
| 1002 | + | ||
| 1003 | + // start at the first frame (duh!) | ||
| 1004 | + currFrame = 0; | ||
| 1005 | + } | ||
| 1006 | + | ||
| 1007 | + TemplateList readBlock(bool *done) | ||
| 1008 | + { | ||
| 1009 | + *done = false; | ||
| 1010 | + TemplateList rects; | ||
| 1011 | + // if it's a Mat, there aren't any bounding boxes in that frame | ||
| 1012 | + // (i think that's the cvmatio default for an empty spot in a matlab array) | ||
| 1013 | + if (objLists[currFrame].typeEquals<Mat>()) { | ||
| 1014 | + Template t(file); | ||
| 1015 | + t.file.set("FrameNumber", currFrame); | ||
| 1016 | + rects.append(Template(file)); | ||
| 1017 | + } else { | ||
| 1018 | + vector<vector<MatlabIOContainer> > bbs = objLists[currFrame].data<vector<vector<MatlabIOContainer> > >(); | ||
| 1019 | + for (unsigned int i=0; i<bbs.size(); i++) { | ||
| 1020 | + vector<MatlabIOContainer> bb = bbs[i]; | ||
| 1021 | + Mat pos = bb[1].data<Mat>(); | ||
| 1022 | + Template t = Template(file); | ||
| 1023 | + double left = pos.at<float>(0,0); | ||
| 1024 | + double top = pos.at<float>(0,1); | ||
| 1025 | + double width = pos.at<float>(0,2); | ||
| 1026 | + double height = pos.at<float>(0,3); | ||
| 1027 | + t.file.appendRect(QRectF(left, top, width, height)); | ||
| 1028 | + t.file.set("FrameNumber", currFrame); | ||
| 1029 | + rects.append(t); | ||
| 1030 | + } | ||
| 1031 | + } | ||
| 1032 | + if (++currFrame == (int)objLists.size()) *done = true; | ||
| 1033 | + return rects; | ||
| 1034 | + } | ||
| 1035 | + | ||
| 1036 | + void write(const Template &t) | ||
| 1037 | + { | ||
| 1038 | + (void)t; qFatal("Not implemented"); | ||
| 1039 | + } | ||
| 1040 | + | ||
| 1041 | +private: | ||
| 1042 | + // this holds a bunch of stuff, maybe we'll use it all later | ||
| 1043 | + vector<MatlabIOContainer> A; | ||
| 1044 | + // this, a field in A, holds bounding boxes for each frame | ||
| 1045 | + vector<MatlabIOContainer> objLists; | ||
| 1046 | + int currFrame; | ||
| 1047 | +}; | ||
| 1048 | + | ||
| 1049 | +BR_REGISTER(Gallery, vbbGallery) | ||
| 1050 | + | ||
| 1051 | +#endif | ||
| 1052 | + | ||
| 972 | } // namespace br | 1053 | } // namespace br |
| 973 | 1054 | ||
| 974 | #include "gallery.moc" | 1055 | #include "gallery.moc" |