Commit 3a165aa921379e864a2229b38d84b81c2293200f

Authored by Josh Klontz
2 parents 2d868e20 f3357e59

Merge branch 'mosift'

openbr/plugins/algorithms.cpp
@@ -49,6 +49,10 @@ class AlgorithmsInitializer : public Initializer @@ -49,6 +49,10 @@ class AlgorithmsInitializer : public Initializer
49 Globals->abbreviations.insert("DisplayVideo", "Stream([FPSLimit(30)+Show(false,[FrameNumber])+Discard])"); 49 Globals->abbreviations.insert("DisplayVideo", "Stream([FPSLimit(30)+Show(false,[FrameNumber])+Discard])");
50 Globals->abbreviations.insert("PerFrameDetection", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+RestoreMat(original)+Draw(inPlace=true),Show(false,[FrameNumber])+Discard])"); 50 Globals->abbreviations.insert("PerFrameDetection", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+RestoreMat(original)+Draw(inPlace=true),Show(false,[FrameNumber])+Discard])");
51 Globals->abbreviations.insert("AgeGenderDemo", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+Expand+<FaceClassificationRegistration>+<FaceClassificationExtraction>+(<AgeRegressor>+Rename(Subject,Age)+Discard)/(<GenderClassifier>+Rename(Subject,Gender)+Discard)+RestoreMat(original)+Draw(inPlace=true)+DrawPropertiesPoint([Age,Gender],Affine_0,inPlace=true)+SaveMat(original)+Discard+Contract,RestoreMat(original)+FPSCalc+Show(false,[AvgFPS,Age,Gender])+Discard])"); 51 Globals->abbreviations.insert("AgeGenderDemo", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+Expand+<FaceClassificationRegistration>+<FaceClassificationExtraction>+(<AgeRegressor>+Rename(Subject,Age)+Discard)/(<GenderClassifier>+Rename(Subject,Gender)+Discard)+RestoreMat(original)+Draw(inPlace=true)+DrawPropertiesPoint([Age,Gender],Affine_0,inPlace=true)+SaveMat(original)+Discard+Contract,RestoreMat(original)+FPSCalc+Show(false,[AvgFPS,Age,Gender])+Discard])");
  52 + Globals->abbreviations.insert("BoVW", "Flatten+CatRows+KMeans(500)+Hist(500)");
  53 + Globals->abbreviations.insert("HOF", "Stream([KeyPointDetector(SIFT),AggregateFrames(2)+OpticalFlow,ROI,HoGDescriptor])+BoVW");
  54 + Globals->abbreviations.insert("HoG", "Stream([KeyPointDetector(SIFT),ROI,HoGDescriptor])+BoVW");
  55 + Globals->abbreviations.insert("HoGHOF", "Stream([KeyPointDetector(SIFT),AggregateFrames(2),(OpticalFlow+ROI+HoGDescriptor)/(First+ROI+HoGDescriptor),Cat])+BoVW");
52 56
53 // Generic Image Processing 57 // Generic Image Processing
54 Globals->abbreviations.insert("SIFT", "Open+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); 58 Globals->abbreviations.insert("SIFT", "Open+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)");
openbr/plugins/hist.cpp
@@ -52,8 +52,12 @@ class HistTransform : public UntrainableTransform @@ -52,8 +52,12 @@ class HistTransform : public UntrainableTransform
52 int histSize[] = {dims}; 52 int histSize[] = {dims};
53 float range[] = {min, max}; 53 float range[] = {min, max};
54 const float* ranges[] = {range}; 54 const float* ranges[] = {range};
55 - Mat hist;  
56 - calcHist(&mv[i], 1, channels, Mat(), hist, 1, histSize, ranges); 55 + Mat hist, chan = mv[i];
  56 + // calcHist requires F or U, might as well convert just in case
  57 + if (mv[i].depth() != CV_8U || mv[i].depth() == CV_32F)
  58 + mv[i].convertTo(chan, CV_32FC1);
  59 +// qDebug("clust r %i c %i ch %i", chan.rows, chan.cols, chan.channels());
  60 + calcHist(&chan, 1, channels, Mat(), hist, 1, histSize, ranges);
57 memcpy(m.ptr(i), hist.ptr(), dims * sizeof(float)); 61 memcpy(m.ptr(i), hist.ptr(), dims * sizeof(float));
58 } 62 }
59 63
openbr/plugins/keypoint.cpp
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16 16
17 #include <opencv2/features2d/features2d.hpp> 17 #include <opencv2/features2d/features2d.hpp>
  18 +#include <opencv2/objdetect/objdetect.hpp>
18 #include <opencv2/nonfree/nonfree.hpp> 19 #include <opencv2/nonfree/nonfree.hpp>
19 #include "openbr_internal.h" 20 #include "openbr_internal.h"
20 #include "openbr/core/opencvutils.h" 21 #include "openbr/core/opencvutils.h"
@@ -178,6 +179,33 @@ BR_REGISTER(Transform, SIFTDescriptorTransform) @@ -178,6 +179,33 @@ BR_REGISTER(Transform, SIFTDescriptorTransform)
178 179
179 /*! 180 /*!
180 * \ingroup transforms 181 * \ingroup transforms
  182 + * \brief OpenCV HOGDescriptor wrapper
  183 + * \author Austin Blanton \cite imaus10
  184 + */
  185 +class HoGDescriptorTransform : public UntrainableTransform
  186 +{
  187 + Q_OBJECT
  188 +
  189 + HOGDescriptor hog;
  190 +
  191 + void project(const Template &src, Template &dst) const
  192 + {
  193 + std::vector<float> descriptorVals;
  194 + std::vector<Point> locations;
  195 + Size winStride = Size(0,0);
  196 + Size padding = Size(0,0);
  197 + foreach (const Mat &rect, src) {
  198 + hog.compute(rect, descriptorVals, winStride, padding, locations);
  199 + Mat HoGFeats(descriptorVals, true);
  200 + dst += HoGFeats;
  201 + }
  202 + }
  203 +};
  204 +
  205 +BR_REGISTER(Transform, HoGDescriptorTransform)
  206 +
  207 +/*!
  208 + * \ingroup transforms
181 * \brief Add landmarks to the template in a grid layout 209 * \brief Add landmarks to the template in a grid layout
182 * \author Josh Klontz \cite jklontz 210 * \author Josh Klontz \cite jklontz
183 */ 211 */
openbr/plugins/misc.cpp
@@ -538,6 +538,32 @@ class EventTransform : public UntrainableMetaTransform @@ -538,6 +538,32 @@ class EventTransform : public UntrainableMetaTransform
538 }; 538 };
539 BR_REGISTER(Transform, EventTransform) 539 BR_REGISTER(Transform, EventTransform)
540 540
  541 +/*!
  542 + * \ingroup transforms
  543 + * \brief Flattens a list of Templates into a single Template
  544 + * \author Austin Blanton \cite imaus10
  545 + */
  546 +class FlattenTransform : public UntrainableMetaTransform
  547 +{
  548 + Q_OBJECT
  549 +
  550 + void project(const TemplateList &src, TemplateList &dst) const
  551 + {
  552 + Template flat;
  553 + foreach (const Template &tmpl, src)
  554 + flat.append(tmpl);
  555 + dst.append(flat);
  556 + }
  557 +
  558 + void project(const Template &src, Template &dst) const
  559 + {
  560 + (void) src;
  561 + (void) dst;
  562 + qFatal("You shouldn't do that!");
  563 + }
  564 +};
  565 +BR_REGISTER(Transform, FlattenTransform)
  566 +
541 } 567 }
542 568
543 #include "misc.moc" 569 #include "misc.moc"
openbr/plugins/opticalflow.cpp 0 → 100644
  1 +#include <opencv2/video/tracking.hpp>
  2 +#include "openbr_internal.h"
  3 +
  4 +using namespace cv;
  5 +
  6 +namespace br
  7 +{
  8 +
  9 +/*!
  10 + * \ingroup transforms
  11 + * \brief Gets a one-channel dense optical flow from two images
  12 + * \author Austin Blanton \cite imaus10
  13 + */
  14 +class OpticalFlowTransform : public UntrainableTransform
  15 +{
  16 + Q_OBJECT
  17 + Q_PROPERTY(double pyr_scale READ get_pyr_scale WRITE set_pyr_scale RESET reset_pyr_scale STORED false)
  18 + Q_PROPERTY(int levels READ get_levels WRITE set_levels RESET reset_levels STORED false)
  19 + Q_PROPERTY(int winsize READ get_winsize WRITE set_winsize RESET reset_winsize STORED false)
  20 + Q_PROPERTY(int iterations READ get_iterations WRITE set_iterations RESET reset_iterations STORED false)
  21 + Q_PROPERTY(int poly_n READ get_poly_n WRITE set_poly_n RESET reset_poly_n STORED false)
  22 + Q_PROPERTY(double poly_sigma READ get_poly_sigma WRITE set_poly_sigma RESET reset_poly_sigma STORED false)
  23 + Q_PROPERTY(int flags READ get_flags WRITE set_flags RESET reset_flags STORED false)
  24 + // these defaults are optimized for KTH
  25 + BR_PROPERTY(double, pyr_scale, 0.1)
  26 + BR_PROPERTY(int, levels, 1)
  27 + BR_PROPERTY(int, winsize, 5)
  28 + BR_PROPERTY(int, iterations, 10)
  29 + BR_PROPERTY(int, poly_n, 7)
  30 + BR_PROPERTY(double, poly_sigma, 1.1)
  31 + BR_PROPERTY(int, flags, 0)
  32 +
  33 + void project(const Template &src, Template &dst) const
  34 + {
  35 + // get the two images put there by AggregateFrames
  36 + Mat prevImg = src[0];
  37 + Mat nextImg = src[1];
  38 + Mat flow;
  39 + calcOpticalFlowFarneback(prevImg, nextImg, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags);
  40 +
  41 + // the result is two channels
  42 + std::vector<Mat> channels(2);
  43 + split(flow, channels);
  44 + Mat flowOneCh;
  45 + magnitude(channels[0], channels[1], flowOneCh);
  46 +
  47 + dst += flowOneCh;
  48 + }
  49 +};
  50 +
  51 +BR_REGISTER(Transform, OpticalFlowTransform)
  52 +
  53 +} // namespace br
  54 +
  55 +#include "opticalflow.moc"