diff --git a/openbr/plugins/algorithms.cpp b/openbr/plugins/algorithms.cpp index fa91da6..809a112 100644 --- a/openbr/plugins/algorithms.cpp +++ b/openbr/plugins/algorithms.cpp @@ -49,6 +49,10 @@ class AlgorithmsInitializer : public Initializer Globals->abbreviations.insert("DisplayVideo", "Stream([FPSLimit(30)+Show(false,[FrameNumber])+Discard])"); Globals->abbreviations.insert("PerFrameDetection", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+RestoreMat(original)+Draw(inPlace=true),Show(false,[FrameNumber])+Discard])"); Globals->abbreviations.insert("AgeGenderDemo", "Stream([SaveMat(original)+Cvt(Gray)+Cascade(FrontalFace)+Expand+++(+Rename(Subject,Age)+Discard)/(+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])"); + Globals->abbreviations.insert("BoVW", "Flatten+CatRows+KMeans(500)+Hist(500)"); + Globals->abbreviations.insert("HOF", "Stream([KeyPointDetector(SIFT),AggregateFrames(2)+OpticalFlow,ROI,HoGDescriptor])+BoVW"); + Globals->abbreviations.insert("HoG", "Stream([KeyPointDetector(SIFT),ROI,HoGDescriptor])+BoVW"); + Globals->abbreviations.insert("HoGHOF", "Stream([KeyPointDetector(SIFT),AggregateFrames(2),(OpticalFlow+ROI+HoGDescriptor)/(First+ROI+HoGDescriptor),Cat])+BoVW"); // Generic Image Processing Globals->abbreviations.insert("SIFT", "Open+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); diff --git a/openbr/plugins/hist.cpp b/openbr/plugins/hist.cpp index b3efd8b..d13fdee 100644 --- a/openbr/plugins/hist.cpp +++ b/openbr/plugins/hist.cpp @@ -52,8 +52,12 @@ class HistTransform : public UntrainableTransform int histSize[] = {dims}; float range[] = {min, max}; const float* ranges[] = {range}; - Mat hist; - calcHist(&mv[i], 1, channels, Mat(), hist, 1, histSize, ranges); + Mat hist, chan = mv[i]; + // calcHist requires F or U, might as well convert just in case + if (mv[i].depth() != CV_8U || mv[i].depth() == CV_32F) + mv[i].convertTo(chan, CV_32FC1); +// qDebug("clust r %i c %i ch %i", chan.rows, chan.cols, chan.channels()); + calcHist(&chan, 1, channels, Mat(), hist, 1, histSize, ranges); memcpy(m.ptr(i), hist.ptr(), dims * sizeof(float)); } diff --git a/openbr/plugins/keypoint.cpp b/openbr/plugins/keypoint.cpp index 9e936cb..18f234c 100644 --- a/openbr/plugins/keypoint.cpp +++ b/openbr/plugins/keypoint.cpp @@ -15,6 +15,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include +#include #include #include "openbr_internal.h" #include "openbr/core/opencvutils.h" @@ -178,6 +179,33 @@ BR_REGISTER(Transform, SIFTDescriptorTransform) /*! * \ingroup transforms + * \brief OpenCV HOGDescriptor wrapper + * \author Austin Blanton \cite imaus10 + */ +class HoGDescriptorTransform : public UntrainableTransform +{ + Q_OBJECT + + HOGDescriptor hog; + + void project(const Template &src, Template &dst) const + { + std::vector descriptorVals; + std::vector locations; + Size winStride = Size(0,0); + Size padding = Size(0,0); + foreach (const Mat &rect, src) { + hog.compute(rect, descriptorVals, winStride, padding, locations); + Mat HoGFeats(descriptorVals, true); + dst += HoGFeats; + } + } +}; + +BR_REGISTER(Transform, HoGDescriptorTransform) + +/*! + * \ingroup transforms * \brief Add landmarks to the template in a grid layout * \author Josh Klontz \cite jklontz */ diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index 567fa0d..d79208b 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -538,6 +538,32 @@ class EventTransform : public UntrainableMetaTransform }; BR_REGISTER(Transform, EventTransform) +/*! + * \ingroup transforms + * \brief Flattens a list of Templates into a single Template + * \author Austin Blanton \cite imaus10 + */ +class FlattenTransform : public UntrainableMetaTransform +{ + Q_OBJECT + + void project(const TemplateList &src, TemplateList &dst) const + { + Template flat; + foreach (const Template &tmpl, src) + flat.append(tmpl); + dst.append(flat); + } + + void project(const Template &src, Template &dst) const + { + (void) src; + (void) dst; + qFatal("You shouldn't do that!"); + } +}; +BR_REGISTER(Transform, FlattenTransform) + } #include "misc.moc" diff --git a/openbr/plugins/opticalflow.cpp b/openbr/plugins/opticalflow.cpp new file mode 100644 index 0000000..f5fde4b --- /dev/null +++ b/openbr/plugins/opticalflow.cpp @@ -0,0 +1,55 @@ +#include +#include "openbr_internal.h" + +using namespace cv; + +namespace br +{ + +/*! + * \ingroup transforms + * \brief Gets a one-channel dense optical flow from two images + * \author Austin Blanton \cite imaus10 + */ +class OpticalFlowTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(double pyr_scale READ get_pyr_scale WRITE set_pyr_scale RESET reset_pyr_scale STORED false) + Q_PROPERTY(int levels READ get_levels WRITE set_levels RESET reset_levels STORED false) + Q_PROPERTY(int winsize READ get_winsize WRITE set_winsize RESET reset_winsize STORED false) + Q_PROPERTY(int iterations READ get_iterations WRITE set_iterations RESET reset_iterations STORED false) + Q_PROPERTY(int poly_n READ get_poly_n WRITE set_poly_n RESET reset_poly_n STORED false) + Q_PROPERTY(double poly_sigma READ get_poly_sigma WRITE set_poly_sigma RESET reset_poly_sigma STORED false) + Q_PROPERTY(int flags READ get_flags WRITE set_flags RESET reset_flags STORED false) + // these defaults are optimized for KTH + BR_PROPERTY(double, pyr_scale, 0.1) + BR_PROPERTY(int, levels, 1) + BR_PROPERTY(int, winsize, 5) + BR_PROPERTY(int, iterations, 10) + BR_PROPERTY(int, poly_n, 7) + BR_PROPERTY(double, poly_sigma, 1.1) + BR_PROPERTY(int, flags, 0) + + void project(const Template &src, Template &dst) const + { + // get the two images put there by AggregateFrames + Mat prevImg = src[0]; + Mat nextImg = src[1]; + Mat flow; + calcOpticalFlowFarneback(prevImg, nextImg, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags); + + // the result is two channels + std::vector channels(2); + split(flow, channels); + Mat flowOneCh; + magnitude(channels[0], channels[1], flowOneCh); + + dst += flowOneCh; + } +}; + +BR_REGISTER(Transform, OpticalFlowTransform) + +} // namespace br + +#include "opticalflow.moc"