From c1dcf40ea5aeba77a49f203b3f2855ce9904e94a Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Tue, 29 Oct 2013 22:36:45 -0400 Subject: [PATCH] Speed ups and minor tweaks to sliding window --- openbr/plugins/lbp.cpp | 3 ++- openbr/plugins/slidingwindow.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/openbr/plugins/lbp.cpp b/openbr/plugins/lbp.cpp index a455021..09fcd80 100644 --- a/openbr/plugins/lbp.cpp +++ b/openbr/plugins/lbp.cpp @@ -15,6 +15,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include +#include #include #include "openbr_internal.h" @@ -30,6 +31,7 @@ namespace br * Pattern Analysis and Machine Intelligence, IEEE Transactions, vol.28, no.12, pp.2037-2041, Dec. 2006 * \author Josh Klontz \cite jklontz */ +static int SCNT = 1; class LBPTransform : public UntrainableTransform { Q_OBJECT @@ -98,7 +100,6 @@ class LBPTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { Mat m; src.m().convertTo(m, CV_32F); assert(m.isContinuous() && (m.channels() == 1)); - Mat n(m.rows, m.cols, CV_8UC1); n = null; // Initialize to NULL LBP pattern diff --git a/openbr/plugins/slidingwindow.cpp b/openbr/plugins/slidingwindow.cpp index 65b174f..68e9af1 100644 --- a/openbr/plugins/slidingwindow.cpp +++ b/openbr/plugins/slidingwindow.cpp @@ -75,6 +75,7 @@ private: dst.file.clearRects(); float scale = src.file.get("scale", 1); Template windowTemplate(src.file, src); + QList confidences = dst.file.getList("Confidences", QList()); for (double y = 0; y + windowHeight < src.m().rows; y += stepSize) { for (double x = 0; x + windowWidth < src.m().cols; x += stepSize) { Mat windowMat(src, Rect(x, y, windowWidth, windowHeight)); @@ -86,14 +87,13 @@ private: // the result will be in the Label if (conf > threshold) { dst.file.appendRect(QRectF((float) x * scale, (float) y * scale, (float) windowWidth * scale, (float) windowHeight * scale)); - QList confidences = dst.file.getList("Confidences", QList()); confidences.append(conf); - dst.file.setList("Confidences", confidences); if (takeFirst) return; } } } + dst.file.setList("Confidences", confidences); } }; @@ -114,6 +114,7 @@ class BuildScalesTransform : public Transform Q_PROPERTY(int negToPosRatio READ get_negToPosRatio WRITE set_negToPosRatio RESET reset_negToPosRatio STORED false) Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false) Q_PROPERTY(double maxOverlap READ get_maxOverlap WRITE set_maxOverlap RESET reset_maxOverlap STORED false) + Q_PROPERTY(float minScale READ get_minScale WRITE set_minScale RESET reset_minScale STORED false) Q_PROPERTY(bool negSamples READ get_negSamples WRITE set_negSamples RESET reset_negSamples STORED false) BR_PROPERTY(br::Transform *, transform, NULL) BR_PROPERTY(double, scaleFactor, 0.75) @@ -122,6 +123,7 @@ class BuildScalesTransform : public Transform BR_PROPERTY(int, negToPosRatio, 1) BR_PROPERTY(int, minSize, 8) BR_PROPERTY(double, maxOverlap, 0) + BR_PROPERTY(float, minScale, 1.0) BR_PROPERTY(bool, negSamples, true) public: @@ -131,14 +133,13 @@ private: void train(const TemplateList &_data) { - TemplateList data = _data; // have to make a copy b/c data is const + TemplateList data(_data); // have to make a copy b/c data is const aspectRatio = getAspectRatio(data); data.first().file.set("aspectRatio", aspectRatio); windowHeight = (int) qRound((float) windowWidth / aspectRatio); if (transform->trainable) { TemplateList full; - foreach (const Template &tmpl, data) { QList posRects = OpenCVUtils::toRects(tmpl.file.rects()); QList negRects; @@ -222,7 +223,7 @@ private: startScale = qRound((float) rows / (float) windowHeight); else startScale = qRound((float) cols / (float) windowWidth); - for (float scale = startScale; scale >= 1.0; scale -= (1.0 - scaleFactor)) { + for (float scale = startScale; scale >= minScale; scale -= (1.0 - scaleFactor)) { Template scaleImg(src.file, Mat()); scaleImg.file.set("scale", scale); resize(src, scaleImg, Size(qRound(cols / scale), qRound(rows / scale))); -- libgit2 0.21.4