Commit cc538ddf authored by marina.kolpakova's avatar marina.kolpakova

changes related with code review

parent f7ac7399
...@@ -24,7 +24,7 @@ set_target_properties(${the_target} PROPERTIES ...@@ -24,7 +24,7 @@ set_target_properties(${the_target} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib INSTALL_NAME_DIR lib
OUTPUT_NAME ${the_target}) OUTPUT_NAME "opencv_trainsoftcascade")
if(ENABLE_SOLUTION_FOLDERS) if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "applications") set_target_properties(${the_target} PROPERTIES FOLDER "applications")
......
...@@ -114,6 +114,8 @@ void sft::read(const cv::FileNode& node, Config& x, const Config& default_value) ...@@ -114,6 +114,8 @@ void sft::read(const cv::FileNode& node, Config& x, const Config& default_value)
x.read(node); x.read(node);
} }
namespace {
struct Out struct Out
{ {
Out(std::ostream& _out): out(_out) {} Out(std::ostream& _out): out(_out) {}
...@@ -124,6 +126,7 @@ struct Out ...@@ -124,6 +126,7 @@ struct Out
private: private:
Out& operator=(Out const& other); Out& operator=(Out const& other);
}; };
}
std::ostream& sft::operator<<(std::ostream& out, const Config& m) std::ostream& sft::operator<<(std::ostream& out, const Config& m)
{ {
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/softcascade/softcascade.hpp> #include <opencv2/softcascade/softcascade.hpp>
namespace cv {using namespace scascade;} namespace cv {using namespace softcascade;}
namespace sft namespace sft
{ {
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
namespace sft namespace sft
{ {
using cv::Dataset; using cv::softcascade::Dataset;
class ScaledDataset : public Dataset class ScaledDataset : public Dataset
{ {
......
...@@ -76,7 +76,7 @@ int main(int argc, char** argv) ...@@ -76,7 +76,7 @@ int main(int argc, char** argv)
string configPath = parser.get<string>("config"); string configPath = parser.get<string>("config");
if (configPath.empty()) if (configPath.empty())
{ {
std::cout << "Configuration file is missing or empty. Could not start training." << std::endl << std::flush; std::cout << "Configuration file is missing or empty. Could not start training." << std::endl;
return 0; return 0;
} }
...@@ -84,7 +84,7 @@ int main(int argc, char** argv) ...@@ -84,7 +84,7 @@ int main(int argc, char** argv)
cv::FileStorage fs(configPath, cv::FileStorage::READ); cv::FileStorage fs(configPath, cv::FileStorage::READ);
if(!fs.isOpened()) if(!fs.isOpened())
{ {
std::cout << "Configuration file " << configPath << " can't be opened." << std::endl << std::flush; std::cout << "Configuration file " << configPath << " can't be opened." << std::endl;
return 1; return 1;
} }
...@@ -97,7 +97,7 @@ int main(int argc, char** argv) ...@@ -97,7 +97,7 @@ int main(int argc, char** argv)
cv::FileStorage fso(cfg.outXmlPath, cv::FileStorage::WRITE); cv::FileStorage fso(cfg.outXmlPath, cv::FileStorage::WRITE);
if(!fso.isOpened()) if(!fso.isOpened())
{ {
std::cout << "Training stopped. Output classifier Xml file " << cfg.outXmlPath << " can't be opened." << std::endl << std::flush; std::cout << "Training stopped. Output classifier Xml file " << cfg.outXmlPath << " can't be opened." << std::endl;
return 1; return 1;
} }
...@@ -128,7 +128,7 @@ int main(int argc, char** argv) ...@@ -128,7 +128,7 @@ int main(int argc, char** argv)
cv::Rect boundingBox = cfg.bbox(it); cv::Rect boundingBox = cfg.bbox(it);
std::cout << "Object bounding box" << boundingBox << std::endl; std::cout << "Object bounding box" << boundingBox << std::endl;
typedef cv::SoftCascadeOctave Octave; typedef cv::Octave Octave;
cv::Ptr<Octave> boost = Octave::create(boundingBox, npositives, nnegatives, *it, shrinkage, nfeatures); cv::Ptr<Octave> boost = Octave::create(boundingBox, npositives, nnegatives, *it, shrinkage, nfeatures);
......
...@@ -97,7 +97,7 @@ catch (const cv::Exception &e) \ ...@@ -97,7 +97,7 @@ catch (const cv::Exception &e) \
} }
using namespace cv; using namespace cv;
typedef cv::scascade::ChannelFeatureBuilder scascade_ChannelFeatureBuilder; typedef cv::softcascade::ChannelFeatureBuilder softcascade_ChannelFeatureBuilder;
typedef vector<uchar> vector_uchar; typedef vector<uchar> vector_uchar;
typedef vector<int> vector_int; typedef vector<int> vector_int;
...@@ -126,7 +126,7 @@ typedef Ptr<DescriptorExtractor> Ptr_DescriptorExtractor; ...@@ -126,7 +126,7 @@ typedef Ptr<DescriptorExtractor> Ptr_DescriptorExtractor;
typedef Ptr<Feature2D> Ptr_Feature2D; typedef Ptr<Feature2D> Ptr_Feature2D;
typedef Ptr<DescriptorMatcher> Ptr_DescriptorMatcher; typedef Ptr<DescriptorMatcher> Ptr_DescriptorMatcher;
typedef Ptr<cv::scascade::ChannelFeatureBuilder> Ptr_ChannelFeatureBuilder; typedef Ptr<cv::softcascade::ChannelFeatureBuilder> Ptr_ChannelFeatureBuilder;
typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; typedef SimpleBlobDetector::Params SimpleBlobDetector_Params;
......
...@@ -25,20 +25,20 @@ The sample has been rejected if it fall rejection threshold. So stageless cascad ...@@ -25,20 +25,20 @@ The sample has been rejected if it fall rejection threshold. So stageless cascad
.. [BMTG12] Rodrigo Benenson, Markus Mathias, Radu Timofte and Luc Van Gool. Pedestrian detection at 100 frames per second. IEEE CVPR, 2012. .. [BMTG12] Rodrigo Benenson, Markus Mathias, Radu Timofte and Luc Van Gool. Pedestrian detection at 100 frames per second. IEEE CVPR, 2012.
SoftCascadeDetector Detector
------------------- -------------------
.. ocv:class:: SoftCascadeDetector .. ocv:class:: Detector
Implementation of soft (stageless) cascaded detector. :: Implementation of soft (stageless) cascaded detector. ::
class CV_EXPORTS_W SoftCascadeDetector : public Algorithm class CV_EXPORTS_W Detector : public Algorithm
{ {
public: public:
enum { NO_REJECT = 1, DOLLAR = 2, /*PASCAL = 4,*/ DEFAULT = NO_REJECT}; enum { NO_REJECT = 1, DOLLAR = 2, /*PASCAL = 4,*/ DEFAULT = NO_REJECT};
CV_WRAP SoftCascadeDetector(double minScale = 0.4, double maxScale = 5., int scales = 55, int rejCriteria = 1); CV_WRAP Detector(double minScale = 0.4, double maxScale = 5., int scales = 55, int rejCriteria = 1);
CV_WRAP virtual ~SoftCascadeDetector(); CV_WRAP virtual ~Detector();
cv::AlgorithmInfo* info() const; cv::AlgorithmInfo* info() const;
CV_WRAP virtual bool load(const FileNode& fileNode); CV_WRAP virtual bool load(const FileNode& fileNode);
CV_WRAP virtual void read(const FileNode& fileNode); CV_WRAP virtual void read(const FileNode& fileNode);
...@@ -49,13 +49,13 @@ Implementation of soft (stageless) cascaded detector. :: ...@@ -49,13 +49,13 @@ Implementation of soft (stageless) cascaded detector. ::
SoftCascadeDetector::SoftCascadeDetector Detector::Detector
---------------------------------------- ----------------------------------------
An empty cascade will be created. An empty cascade will be created.
.. ocv:function:: SoftCascadeDetector::SoftCascadeDetector(float minScale = 0.4f, float maxScale = 5.f, int scales = 55, int rejCriteria = 1) .. ocv:function:: Detector::Detector(float minScale = 0.4f, float maxScale = 5.f, int scales = 55, int rejCriteria = 1)
.. ocv:pyfunction:: cv2.SoftCascadeDetector.SoftCascadeDetector(minScale[, maxScale[, scales[, rejCriteria]]]) -> cascade .. ocv:pyfunction:: cv2.Detector.Detector(minScale[, maxScale[, scales[, rejCriteria]]]) -> cascade
:param minScale: a minimum scale relative to the original size of the image on which cascade will be applied. :param minScale: a minimum scale relative to the original size of the image on which cascade will be applied.
...@@ -67,35 +67,35 @@ An empty cascade will be created. ...@@ -67,35 +67,35 @@ An empty cascade will be created.
SoftCascadeDetector::~SoftCascadeDetector Detector::~Detector
----------------------------------------- -----------------------------------------
Destructor for SoftCascadeDetector. Destructor for Detector.
.. ocv:function:: SoftCascadeDetector::~SoftCascadeDetector() .. ocv:function:: Detector::~Detector()
SoftCascadeDetector::load Detector::load
-------------------------- --------------------------
Load cascade from FileNode. Load cascade from FileNode.
.. ocv:function:: bool SoftCascadeDetector::load(const FileNode& fileNode) .. ocv:function:: bool Detector::load(const FileNode& fileNode)
.. ocv:pyfunction:: cv2.SoftCascadeDetector.load(fileNode) .. ocv:pyfunction:: cv2.Detector.load(fileNode)
:param fileNode: File node from which the soft cascade are read. :param fileNode: File node from which the soft cascade are read.
SoftCascadeDetector::detect Detector::detect
--------------------------- ---------------------------
Apply cascade to an input frame and return the vector of Detection objects. Apply cascade to an input frame and return the vector of Detection objects.
.. ocv:function:: void SoftCascadeDetector::detect(InputArray image, InputArray rois, std::vector<Detection>& objects) const .. ocv:function:: void Detector::detect(InputArray image, InputArray rois, std::vector<Detection>& objects) const
.. ocv:function:: void SoftCascadeDetector::detect(InputArray image, InputArray rois, OutputArray rects, OutputArray confs) const .. ocv:function:: void Detector::detect(InputArray image, InputArray rois, OutputArray rects, OutputArray confs) const
.. ocv:pyfunction:: cv2.SoftCascadeDetector.detect(image, rois) -> (rects, confs) .. ocv:pyfunction:: cv2.Detector.detect(image, rois) -> (rects, confs)
:param image: a frame on which detector will be applied. :param image: a frame on which detector will be applied.
......
...@@ -7,13 +7,13 @@ Soft Cascade Detector Training ...@@ -7,13 +7,13 @@ Soft Cascade Detector Training
-------------------------------------------- --------------------------------------------
SoftCascadeOctave Octave
----------------- -----------------
.. ocv:class:: SoftCascadeOctave .. ocv:class:: Octave
Public interface for soft cascade training algorithm. :: Public interface for soft cascade training algorithm. ::
class CV_EXPORTS SoftCascadeOctave : public Algorithm class CV_EXPORTS Octave : public Algorithm
{ {
public: public:
...@@ -25,8 +25,8 @@ Public interface for soft cascade training algorithm. :: ...@@ -25,8 +25,8 @@ Public interface for soft cascade training algorithm. ::
// Originally proposed by L. Bourdev and J. Brandt // Originally proposed by L. Bourdev and J. Brandt
HEURISTIC = 4 }; HEURISTIC = 4 };
virtual ~SoftCascadeOctave(); virtual ~Octave();
static cv::Ptr<SoftCascadeOctave> create(cv::Rect boundingBox, int npositives, int nnegatives, int logScale, int shrinkage); static cv::Ptr<Octave> create(cv::Rect boundingBox, int npositives, int nnegatives, int logScale, int shrinkage);
virtual bool train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth) = 0; virtual bool train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth) = 0;
virtual void setRejectThresholds(OutputArray thresholds) = 0; virtual void setRejectThresholds(OutputArray thresholds) = 0;
...@@ -37,17 +37,17 @@ Public interface for soft cascade training algorithm. :: ...@@ -37,17 +37,17 @@ Public interface for soft cascade training algorithm. ::
SoftCascadeOctave::~SoftCascadeOctave Octave::~Octave
--------------------------------------- ---------------------------------------
Destructor for SoftCascadeOctave. Destructor for Octave.
.. ocv:function:: SoftCascadeOctave::~SoftCascadeOctave() .. ocv:function:: Octave::~Octave()
SoftCascadeOctave::train Octave::train
------------------------ ------------------------
.. ocv:function:: bool SoftCascadeOctave::train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth) .. ocv:function:: bool Octave::train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth)
:param dataset an object that allows communicate for training set. :param dataset an object that allows communicate for training set.
...@@ -59,19 +59,19 @@ SoftCascadeOctave::train ...@@ -59,19 +59,19 @@ SoftCascadeOctave::train
SoftCascadeOctave::setRejectThresholds Octave::setRejectThresholds
-------------------------------------- --------------------------------------
.. ocv:function:: void SoftCascadeOctave::setRejectThresholds(OutputArray thresholds) .. ocv:function:: void Octave::setRejectThresholds(OutputArray thresholds)
:param thresholds an output array of resulted rejection vector. Have same size as number of trained stages. :param thresholds an output array of resulted rejection vector. Have same size as number of trained stages.
SoftCascadeOctave::write Octave::write
------------------------ ------------------------
.. ocv:function:: void SoftCascadeOctave::train(cv::FileStorage &fs, const FeaturePool* pool, InputArray thresholds) const .. ocv:function:: void Octave::train(cv::FileStorage &fs, const FeaturePool* pool, InputArray thresholds) const
.. ocv:function:: void SoftCascadeOctave::train( CvFileStorage* fs, string name) const .. ocv:function:: void Octave::train( CvFileStorage* fs, string name) const
:param fs an output file storage to store trained detector. :param fs an output file storage to store trained detector.
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
namespace cv { namespace scascade { namespace cv { namespace softcascade {
// Representation of detectors result. // Representation of detectors result.
struct CV_EXPORTS Detection struct CV_EXPORTS Detection
...@@ -64,8 +64,6 @@ struct CV_EXPORTS Detection ...@@ -64,8 +64,6 @@ struct CV_EXPORTS Detection
int kind; int kind;
}; };
class CV_EXPORTS Dataset class CV_EXPORTS Dataset
{ {
public: public:
...@@ -136,7 +134,7 @@ public: ...@@ -136,7 +134,7 @@ public:
// ========================================================================== // // ========================================================================== //
// Implementation of soft (stageless) cascaded detector. // Implementation of soft (stageless) cascaded detector.
// ========================================================================== // // ========================================================================== //
class CV_EXPORTS_W SoftCascadeDetector : public cv::Algorithm class CV_EXPORTS_W Detector : public cv::Algorithm
{ {
public: public:
...@@ -147,9 +145,9 @@ public: ...@@ -147,9 +145,9 @@ public:
// Param minScale is a maximum scale relative to the original size of the image on which cascade will be applied. // Param minScale is a maximum scale relative to the original size of the image on which cascade will be applied.
// Param scales is a number of scales from minScale to maxScale. // Param scales is a number of scales from minScale to maxScale.
// Param rejCriteria is used for NMS. // Param rejCriteria is used for NMS.
CV_WRAP SoftCascadeDetector(double minScale = 0.4, double maxScale = 5., int scales = 55, int rejCriteria = 1); CV_WRAP Detector(double minScale = 0.4, double maxScale = 5., int scales = 55, int rejCriteria = 1);
CV_WRAP virtual ~SoftCascadeDetector(); CV_WRAP virtual ~Detector();
cv::AlgorithmInfo* info() const; cv::AlgorithmInfo* info() const;
...@@ -186,7 +184,7 @@ private: ...@@ -186,7 +184,7 @@ private:
// ========================================================================== // // ========================================================================== //
// Public Interface for singe soft (stageless) cascade octave training. // Public Interface for singe soft (stageless) cascade octave training.
// ========================================================================== // // ========================================================================== //
class CV_EXPORTS SoftCascadeOctave : public cv::Algorithm class CV_EXPORTS Octave : public cv::Algorithm
{ {
public: public:
enum enum
...@@ -199,8 +197,8 @@ public: ...@@ -199,8 +197,8 @@ public:
HEURISTIC = 4 HEURISTIC = 4
}; };
virtual ~SoftCascadeOctave(); virtual ~Octave();
static cv::Ptr<SoftCascadeOctave> create(cv::Rect boundingBox, int npositives, int nnegatives, static cv::Ptr<Octave> create(cv::Rect boundingBox, int npositives, int nnegatives,
int logScale, int shrinkage, int poolSize); int logScale, int shrinkage, int poolSize);
virtual bool train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth) = 0; virtual bool train(const Dataset* dataset, const FeaturePool* pool, int weaks, int treeDepth) = 0;
...@@ -211,6 +209,6 @@ public: ...@@ -211,6 +209,6 @@ public:
CV_EXPORTS bool initModule_softcascade(void); CV_EXPORTS bool initModule_softcascade(void);
} } }} // namespace cv { namespace softcascade {
#endif #endif
\ No newline at end of file
...@@ -24,7 +24,7 @@ def convert2detections(rects, confs, crop_factor = 0.125): ...@@ -24,7 +24,7 @@ def convert2detections(rects, confs, crop_factor = 0.125):
""" Create new instance of soft cascade.""" """ Create new instance of soft cascade."""
def cascade(min_scale, max_scale, nscales, f): def cascade(min_scale, max_scale, nscales, f):
# where we use nms cv::SoftCascadeDetector::DOLLAR == 2 # where we use nms cv::SoftCascadeDetector::DOLLAR == 2
c = cv2.scascade_SoftCascadeDetector(min_scale, max_scale, nscales, 2) c = cv2.softcascade_Detector(min_scale, max_scale, nscales, 2)
xml = cv2.FileStorage(f, 0) xml = cv2.FileStorage(f, 0)
dom = xml.getFirstTopLevelNode() dom = xml.getFirstTopLevelNode()
assert c.load(dom) assert c.load(dom)
......
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
using cv::Rect; using cv::Rect;
using std::tr1::get; using std::tr1::get;
using namespace cv::softcascade;
typedef std::tr1::tuple<std::string, std::string> fixture; typedef std::tr1::tuple<std::string, std::string> fixture;
typedef perf::TestBaseWithParam<fixture> detect; typedef perf::TestBaseWithParam<fixture> detect;
namespace { namespace {
void extractRacts(std::vector<cv::scascade::Detection> objectBoxes, std::vector<Rect>& rects) void extractRacts(std::vector<Detection> objectBoxes, std::vector<Rect>& rects)
{ {
rects.clear(); rects.clear();
for (int i = 0; i < (int)objectBoxes.size(); ++i) for (int i = 0; i < (int)objectBoxes.size(); ++i)
...@@ -26,14 +29,12 @@ PERF_TEST_P(detect, SoftCascadeDetector, ...@@ -26,14 +29,12 @@ PERF_TEST_P(detect, SoftCascadeDetector,
cv::Mat colored = cv::imread(getDataPath(get<1>(GetParam()))); cv::Mat colored = cv::imread(getDataPath(get<1>(GetParam())));
ASSERT_FALSE(colored.empty()); ASSERT_FALSE(colored.empty());
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(getDataPath(get<0>(GetParam())), cv::FileStorage::READ); cv::FileStorage fs(getDataPath(get<0>(GetParam())), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
std::vector<cv::scascade::Detection> objectBoxes; std::vector<Detection> objectBoxes;
cascade.detect(colored, cv::noArray(), objectBoxes);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(colored, cv::noArray(), objectBoxes); cascade.detect(colored, cv::noArray(), objectBoxes);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
// //
// * Redistribution's in binary form must reproduce the above copyright notice, // * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation // this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. // and / or other materials provided with the distribution.
// //
// * The name of the copyright holders may not be used to endorse or promote products // * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission. // derived from this software without specific prior written permission.
...@@ -44,41 +44,53 @@ ...@@ -44,41 +44,53 @@
#define __SFT_RANDOM_HPP__ #define __SFT_RANDOM_HPP__
#if defined(_MSC_VER) && _MSC_VER >= 1600 #if defined(_MSC_VER) && _MSC_VER >= 1600
# include <random> # include <random>
namespace sft {
namespace cv { namespace softcascade { namespace internal
{
struct Random struct Random
{ {
typedef std::mt19937 engine; typedef std::mt19937 engine;
typedef std::uniform_int<int> uniform; typedef std::uniform_int<int> uniform;
}; };
}
#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__) }}}
#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__)
# if defined (__cplusplus) && __cplusplus > 201100L # if defined (__cplusplus) && __cplusplus > 201100L
# include <random> # include <random>
namespace sft {
namespace cv { namespace softcascade { namespace internal
{
struct Random struct Random
{ {
typedef std::mt19937 engine; typedef std::mt19937 engine;
typedef std::uniform_int<int> uniform; typedef std::uniform_int<int> uniform;
}; };
} }}}
# else # else
# include <tr1/random> # include <tr1/random>
namespace cv { namespace softcascade { namespace internal
{
namespace sft {
struct Random struct Random
{ {
typedef std::tr1::mt19937 engine; typedef std::tr1::mt19937 engine;
typedef std::tr1::uniform_int<int> uniform; typedef std::tr1::uniform_int<int> uniform;
}; };
}
}}}
# endif # endif
#else #else
#include <opencv2/core/core.hpp> # include <opencv2/core/core.hpp>
namespace cv { namespace softcascade { namespace internal
{
namespace rnd { namespace rnd {
typedef cv::RNG engine; typedef cv::RNG engine;
...@@ -104,13 +116,13 @@ private: ...@@ -104,13 +116,13 @@ private:
} }
namespace sft {
struct Random struct Random
{ {
typedef rnd::engine engine; typedef rnd::engine engine;
typedef rnd::uniform_int<int> uniform; typedef rnd::uniform_int<int> uniform;
}; };
}
}}}
#endif #endif
......
...@@ -44,10 +44,13 @@ ...@@ -44,10 +44,13 @@
namespace { namespace {
using namespace cv::softcascade;
class ICFBuilder : public ChannelFeatureBuilder class ICFBuilder : public ChannelFeatureBuilder
{ {
virtual ~ICFBuilder() {} virtual ~ICFBuilder() {}
virtual cv::AlgorithmInfo* info() const; virtual cv::AlgorithmInfo* info() const;
virtual void operator()(cv::InputArray _frame, CV_OUT cv::OutputArray _integrals) const virtual void operator()(cv::InputArray _frame, CV_OUT cv::OutputArray _integrals) const
{ {
CV_Assert(_frame.type() == CV_8UC3); CV_Assert(_frame.type() == CV_8UC3);
...@@ -107,9 +110,12 @@ class ICFBuilder : public ChannelFeatureBuilder ...@@ -107,9 +110,12 @@ class ICFBuilder : public ChannelFeatureBuilder
} }
using cv::softcascade::ChannelFeatureBuilder;
using cv::softcascade::ChannelFeature;
CV_INIT_ALGORITHM(ICFBuilder, "ChannelFeatureBuilder.ICFBuilder", ); CV_INIT_ALGORITHM(ICFBuilder, "ChannelFeatureBuilder.ICFBuilder", );
cv::scascade::ChannelFeatureBuilder::~ChannelFeatureBuilder() {} ChannelFeatureBuilder::~ChannelFeatureBuilder() {}
cv::Ptr<ChannelFeatureBuilder> ChannelFeatureBuilder::create() cv::Ptr<ChannelFeatureBuilder> ChannelFeatureBuilder::create()
{ {
...@@ -117,7 +123,7 @@ cv::Ptr<ChannelFeatureBuilder> ChannelFeatureBuilder::create() ...@@ -117,7 +123,7 @@ cv::Ptr<ChannelFeatureBuilder> ChannelFeatureBuilder::create()
return builder; return builder;
} }
cv::scascade::ChannelFeature::ChannelFeature(int x, int y, int w, int h, int ch) ChannelFeature::ChannelFeature(int x, int y, int w, int h, int ch)
: bb(cv::Rect(x, y, w, h)), channel(ch) {} : bb(cv::Rect(x, y, w, h)), channel(ch) {}
bool ChannelFeature::operator ==(ChannelFeature b) bool ChannelFeature::operator ==(ChannelFeature b)
...@@ -131,7 +137,7 @@ bool ChannelFeature::operator !=(ChannelFeature b) ...@@ -131,7 +137,7 @@ bool ChannelFeature::operator !=(ChannelFeature b)
} }
float cv::scascade::ChannelFeature::operator() (const cv::Mat& integrals, const cv::Size& model) const float ChannelFeature::operator() (const cv::Mat& integrals, const cv::Size& model) const
{ {
int step = model.width + 1; int step = model.width + 1;
...@@ -148,21 +154,23 @@ float cv::scascade::ChannelFeature::operator() (const cv::Mat& integrals, const ...@@ -148,21 +154,23 @@ float cv::scascade::ChannelFeature::operator() (const cv::Mat& integrals, const
return (float)(a - b + c - d); return (float)(a - b + c - d);
} }
void cv::scascade::write(cv::FileStorage& fs, const string&, const ChannelFeature& f) void cv::softcascade::write(cv::FileStorage& fs, const string&, const ChannelFeature& f)
{ {
fs << "{" << "channel" << f.channel << "rect" << f.bb << "}"; fs << "{" << "channel" << f.channel << "rect" << f.bb << "}";
} }
std::ostream& cv::scascade::operator<<(std::ostream& out, const ChannelFeature& m) std::ostream& cv::softcascade::operator<<(std::ostream& out, const ChannelFeature& m)
{ {
out << m.channel << " " << m.bb; out << m.channel << " " << m.bb;
return out; return out;
} }
cv::scascade::ChannelFeature::~ChannelFeature(){} ChannelFeature::~ChannelFeature(){}
namespace { namespace {
using namespace cv::softcascade;
class ChannelFeaturePool : public FeaturePool class ChannelFeaturePool : public FeaturePool
{ {
public: public:
...@@ -200,6 +208,7 @@ void ChannelFeaturePool::write( cv::FileStorage& fs, int index) const ...@@ -200,6 +208,7 @@ void ChannelFeaturePool::write( cv::FileStorage& fs, int index) const
void ChannelFeaturePool::fill(int desired) void ChannelFeaturePool::fill(int desired)
{ {
using namespace cv::softcascade::internal;
int mw = model.width; int mw = model.width;
int mh = model.height; int mh = model.height;
...@@ -208,16 +217,16 @@ void ChannelFeaturePool::fill(int desired) ...@@ -208,16 +217,16 @@ void ChannelFeaturePool::fill(int desired)
int nfeatures = std::min(desired, maxPoolSize); int nfeatures = std::min(desired, maxPoolSize);
pool.reserve(nfeatures); pool.reserve(nfeatures);
sft::Random::engine eng(FEATURE_RECT_SEED); Random::engine eng(FEATURE_RECT_SEED);
sft::Random::engine eng_ch(DCHANNELS_SEED); Random::engine eng_ch(DCHANNELS_SEED);
sft::Random::uniform chRand(0, N_CHANNELS - 1); Random::uniform chRand(0, N_CHANNELS - 1);
sft::Random::uniform xRand(0, model.width - 2); Random::uniform xRand(0, model.width - 2);
sft::Random::uniform yRand(0, model.height - 2); Random::uniform yRand(0, model.height - 2);
sft::Random::uniform wRand(1, model.width - 1); Random::uniform wRand(1, model.width - 1);
sft::Random::uniform hRand(1, model.height - 1); Random::uniform hRand(1, model.height - 1);
while (pool.size() < size_t(nfeatures)) while (pool.size() < size_t(nfeatures))
{ {
...@@ -246,7 +255,7 @@ void ChannelFeaturePool::fill(int desired) ...@@ -246,7 +255,7 @@ void ChannelFeaturePool::fill(int desired)
} }
cv::Ptr<FeaturePool> cv::scascade::FeaturePool::create(const cv::Size& model, int nfeatures) cv::Ptr<FeaturePool> FeaturePool::create(const cv::Size& model, int nfeatures)
{ {
cv::Ptr<FeaturePool> pool(new ChannelFeaturePool(model, nfeatures)); cv::Ptr<FeaturePool> pool(new ChannelFeaturePool(model, nfeatures));
return pool; return pool;
......
...@@ -55,6 +55,4 @@ ...@@ -55,6 +55,4 @@
#include "opencv2/ml/ml.hpp" #include "opencv2/ml/ml.hpp"
#include "_random.hpp" #include "_random.hpp"
using namespace cv::scascade;
#endif #endif
...@@ -48,13 +48,17 @@ using cv::InputArray; ...@@ -48,13 +48,17 @@ using cv::InputArray;
using cv::OutputArray; using cv::OutputArray;
using cv::Mat; using cv::Mat;
cv::scascade::FeaturePool::~FeaturePool(){} using cv::softcascade::Octave;
cv::scascade::Dataset::~Dataset(){} using cv::softcascade::FeaturePool;
using cv::softcascade::Dataset;
using cv::softcascade::ChannelFeatureBuilder;
namespace { FeaturePool::~FeaturePool(){}
Dataset::~Dataset(){}
namespace {
class BoostedSoftCascadeOctave : public cv::Boost, public SoftCascadeOctave class BoostedSoftCascadeOctave : public cv::Boost, public Octave
{ {
public: public:
...@@ -214,14 +218,15 @@ void BoostedSoftCascadeOctave::processPositives(const Dataset* dataset) ...@@ -214,14 +218,15 @@ void BoostedSoftCascadeOctave::processPositives(const Dataset* dataset)
void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset) void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset)
{ {
using namespace cv::softcascade::internal;
// ToDo: set seed, use offsets // ToDo: set seed, use offsets
sft::Random::engine eng(DX_DY_SEED); Random::engine eng(DX_DY_SEED);
sft::Random::engine idxEng(INDEX_ENGINE_SEED); Random::engine idxEng(INDEX_ENGINE_SEED);
int h = boundingBox.height; int h = boundingBox.height;
int nimages = dataset->available(Dataset::NEGATIVE); int nimages = dataset->available(Dataset::NEGATIVE);
sft::Random::uniform iRand(0, nimages - 1); Random::uniform iRand(0, nimages - 1);
int total = 0; int total = 0;
Mat sum; Mat sum;
...@@ -236,8 +241,8 @@ void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset) ...@@ -236,8 +241,8 @@ void BoostedSoftCascadeOctave::generateNegatives(const Dataset* dataset)
int maxW = frame.cols - 2 * boundingBox.x - boundingBox.width; int maxW = frame.cols - 2 * boundingBox.x - boundingBox.width;
int maxH = frame.rows - 2 * boundingBox.y - boundingBox.height; int maxH = frame.rows - 2 * boundingBox.y - boundingBox.height;
sft::Random::uniform wRand(0, maxW -1); Random::uniform wRand(0, maxW -1);
sft::Random::uniform hRand(0, maxH -1); Random::uniform hRand(0, maxH -1);
int dx = wRand(eng); int dx = wRand(eng);
int dy = hRand(eng); int dy = hRand(eng);
...@@ -439,12 +444,12 @@ void BoostedSoftCascadeOctave::write( CvFileStorage* fs, std::string _name) cons ...@@ -439,12 +444,12 @@ void BoostedSoftCascadeOctave::write( CvFileStorage* fs, std::string _name) cons
CV_INIT_ALGORITHM(BoostedSoftCascadeOctave, "SoftCascadeOctave.BoostedSoftCascadeOctave", ); CV_INIT_ALGORITHM(BoostedSoftCascadeOctave, "SoftCascadeOctave.BoostedSoftCascadeOctave", );
cv::scascade::SoftCascadeOctave::~SoftCascadeOctave(){} Octave::~Octave(){}
cv::Ptr<SoftCascadeOctave> cv::scascade::SoftCascadeOctave::create(cv::Rect boundingBox, int npositives, int nnegatives, cv::Ptr<Octave> Octave::create(cv::Rect boundingBox, int npositives, int nnegatives,
int logScale, int shrinkage, int poolSize) int logScale, int shrinkage, int poolSize)
{ {
cv::Ptr<SoftCascadeOctave> octave( cv::Ptr<Octave> octave(
new BoostedSoftCascadeOctave(boundingBox, npositives, nnegatives, logScale, shrinkage, poolSize)); new BoostedSoftCascadeOctave(boundingBox, npositives, nnegatives, logScale, shrinkage, poolSize));
return octave; return octave;
} }
...@@ -42,11 +42,17 @@ ...@@ -42,11 +42,17 @@
#include "precomp.hpp" #include "precomp.hpp"
using cv::softcascade::Detection;
using cv::softcascade::Detector;
using cv::softcascade::ChannelFeatureBuilder;
using namespace cv;
namespace { namespace {
struct Octave struct SOctave
{ {
Octave(const int i, const cv::Size& origObjSize, const cv::FileNode& fn) SOctave(const int i, const cv::Size& origObjSize, const cv::FileNode& fn)
: index(i), weaks((int)fn[SC_OCT_WEAKS]), scale(pow(2,(float)fn[SC_OCT_SCALE])), : index(i), weaks((int)fn[SC_OCT_WEAKS]), scale(pow(2,(float)fn[SC_OCT_SCALE])),
size(cvRound(origObjSize.width * scale), cvRound(origObjSize.height * scale)) {} size(cvRound(origObjSize.width * scale), cvRound(origObjSize.height * scale)) {}
...@@ -115,16 +121,16 @@ struct Feature ...@@ -115,16 +121,16 @@ struct Feature
static const char *const SC_F_RECT; static const char *const SC_F_RECT;
}; };
const char *const Octave::SC_OCT_SCALE = "scale"; const char *const SOctave::SC_OCT_SCALE = "scale";
const char *const Octave::SC_OCT_WEAKS = "weaks"; const char *const SOctave::SC_OCT_WEAKS = "weaks";
const char *const Octave::SC_OCT_SHRINKAGE = "shrinkingFactor"; const char *const SOctave::SC_OCT_SHRINKAGE = "shrinkingFactor";
const char *const Weak::SC_WEAK_THRESHOLD = "treeThreshold"; const char *const Weak::SC_WEAK_THRESHOLD = "treeThreshold";
const char *const Feature::SC_F_CHANNEL = "channel"; const char *const Feature::SC_F_CHANNEL = "channel";
const char *const Feature::SC_F_RECT = "rect"; const char *const Feature::SC_F_RECT = "rect";
struct Level struct Level
{ {
const Octave* octave; const SOctave* octave;
float origScale; float origScale;
float relScale; float relScale;
...@@ -135,7 +141,7 @@ struct Level ...@@ -135,7 +141,7 @@ struct Level
float scaling[2]; // 0-th for channels <= 6, 1-st otherwise float scaling[2]; // 0-th for channels <= 6, 1-st otherwise
Level(const Octave& oct, const float scale, const int shrinkage, const int w, const int h) Level(const SOctave& oct, const float scale, const int shrinkage, const int w, const int h)
: octave(&oct), origScale(scale), relScale(scale / oct.scale), : octave(&oct), origScale(scale), relScale(scale / oct.scale),
workRect(cv::Size(cvRound(w / (float)shrinkage),cvRound(h / (float)shrinkage))), workRect(cv::Size(cvRound(w / (float)shrinkage),cvRound(h / (float)shrinkage))),
objSize(cv::Size(cvRound(oct.size.width * relScale), cvRound(oct.size.height * relScale))) objSize(cv::Size(cvRound(oct.size.width * relScale), cvRound(oct.size.height * relScale)))
...@@ -205,7 +211,8 @@ struct ChannelStorage ...@@ -205,7 +211,8 @@ struct ChannelStorage
} }
struct SoftCascadeDetector::Fields
struct Detector::Fields
{ {
float minScale; float minScale;
float maxScale; float maxScale;
...@@ -216,7 +223,7 @@ struct SoftCascadeDetector::Fields ...@@ -216,7 +223,7 @@ struct SoftCascadeDetector::Fields
int shrinkage; int shrinkage;
std::vector<Octave> octaves; std::vector<SOctave> octaves;
std::vector<Weak> weaks; std::vector<Weak> weaks;
std::vector<Node> nodes; std::vector<Node> nodes;
std::vector<float> leaves; std::vector<float> leaves;
...@@ -226,14 +233,14 @@ struct SoftCascadeDetector::Fields ...@@ -226,14 +233,14 @@ struct SoftCascadeDetector::Fields
cv::Size frameSize; cv::Size frameSize;
typedef std::vector<Octave>::iterator octIt_t; typedef std::vector<SOctave>::iterator octIt_t;
typedef std::vector<Detection> dvector; typedef std::vector<Detection> dvector;
void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage, dvector& detections) const void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage, dvector& detections) const
{ {
float detectionScore = 0.f; float detectionScore = 0.f;
const Octave& octave = *(level.octave); const SOctave& octave = *(level.octave);
int stBegin = octave.index * octave.weaks, stEnd = stBegin + octave.weaks; int stBegin = octave.index * octave.weaks, stEnd = stBegin + octave.weaks;
...@@ -279,7 +286,7 @@ struct SoftCascadeDetector::Fields ...@@ -279,7 +286,7 @@ struct SoftCascadeDetector::Fields
octIt_t res = octaves.begin(); octIt_t res = octaves.begin();
for (octIt_t oct = octaves.begin(); oct < octaves.end(); ++oct) for (octIt_t oct = octaves.begin(); oct < octaves.end(); ++oct)
{ {
const Octave& octave =*oct; const SOctave& octave =*oct;
float logOctave = log(octave.scale); float logOctave = log(octave.scale);
float logAbsScale = fabs(logFactor - logOctave); float logAbsScale = fabs(logFactor - logOctave);
...@@ -373,7 +380,7 @@ struct SoftCascadeDetector::Fields ...@@ -373,7 +380,7 @@ struct SoftCascadeDetector::Fields
for (int octIndex = 0; it != it_end; ++it, ++octIndex) for (int octIndex = 0; it != it_end; ++it, ++octIndex)
{ {
FileNode fns = *it; FileNode fns = *it;
Octave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns); SOctave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns);
CV_Assert(octave.weaks > 0); CV_Assert(octave.weaks > 0);
octaves.push_back(octave); octaves.push_back(octave);
...@@ -409,17 +416,17 @@ struct SoftCascadeDetector::Fields ...@@ -409,17 +416,17 @@ struct SoftCascadeDetector::Fields
} }
}; };
SoftCascadeDetector::SoftCascadeDetector(const double mins, const double maxs, const int nsc, const int rej) Detector::Detector(const double mins, const double maxs, const int nsc, const int rej)
: fields(0), minScale(mins), maxScale(maxs), scales(nsc), rejCriteria(rej) {} : fields(0), minScale(mins), maxScale(maxs), scales(nsc), rejCriteria(rej) {}
SoftCascadeDetector::~SoftCascadeDetector() { delete fields;} Detector::~Detector() { delete fields;}
void SoftCascadeDetector::read(const FileNode& fn) void Detector::read(const cv::FileNode& fn)
{ {
Algorithm::read(fn); Algorithm::read(fn);
} }
bool SoftCascadeDetector::load(const FileNode& fn) bool Detector::load(const cv::FileNode& fn)
{ {
if (fields) delete fields; if (fields) delete fields;
...@@ -429,6 +436,7 @@ bool SoftCascadeDetector::load(const FileNode& fn) ...@@ -429,6 +436,7 @@ bool SoftCascadeDetector::load(const FileNode& fn)
namespace { namespace {
using cv::softcascade::Detection;
typedef std::vector<Detection> dvector; typedef std::vector<Detection> dvector;
...@@ -472,13 +480,13 @@ void DollarNMS(dvector& objects) ...@@ -472,13 +480,13 @@ void DollarNMS(dvector& objects)
static void suppress(int type, std::vector<Detection>& objects) static void suppress(int type, std::vector<Detection>& objects)
{ {
CV_Assert(type == SoftCascadeDetector::DOLLAR); CV_Assert(type == Detector::DOLLAR);
DollarNMS(objects); DollarNMS(objects);
} }
} }
void SoftCascadeDetector::detectNoRoi(const cv::Mat& image, std::vector<Detection>& objects) const void Detector::detectNoRoi(const cv::Mat& image, std::vector<Detection>& objects) const
{ {
Fields& fld = *fields; Fields& fld = *fields;
// create integrals // create integrals
...@@ -502,10 +510,10 @@ void SoftCascadeDetector::detectNoRoi(const cv::Mat& image, std::vector<Detectio ...@@ -502,10 +510,10 @@ void SoftCascadeDetector::detectNoRoi(const cv::Mat& image, std::vector<Detectio
} }
} }
// if (rejCriteria != NO_REJECT) suppress(rejCriteria, objects); if (rejCriteria != NO_REJECT) suppress(rejCriteria, objects);
} }
void SoftCascadeDetector::detect(cv::InputArray _image, cv::InputArray _rois, std::vector<Detection>& objects) const void Detector::detect(cv::InputArray _image, cv::InputArray _rois, std::vector<Detection>& objects) const
{ {
// only color images are suppered // only color images are suppered
cv::Mat image = _image.getMat(); cv::Mat image = _image.getMat();
...@@ -557,7 +565,7 @@ void SoftCascadeDetector::detect(cv::InputArray _image, cv::InputArray _rois, st ...@@ -557,7 +565,7 @@ void SoftCascadeDetector::detect(cv::InputArray _image, cv::InputArray _rois, st
if (rejCriteria != NO_REJECT) suppress(rejCriteria, objects); if (rejCriteria != NO_REJECT) suppress(rejCriteria, objects);
} }
void SoftCascadeDetector::detect(InputArray _image, InputArray _rois, OutputArray _rects, OutputArray _confs) const void Detector::detect(InputArray _image, InputArray _rois, OutputArray _rects, OutputArray _confs) const
{ {
std::vector<Detection> objects; std::vector<Detection> objects;
detect( _image, _rois, objects); detect( _image, _rois, objects);
......
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
#include "precomp.hpp" #include "precomp.hpp"
namespace cv { namespace scascade namespace cv { namespace softcascade
{ {
CV_INIT_ALGORITHM(SoftCascadeDetector, "SoftCascade.SoftCascadeDetector", CV_INIT_ALGORITHM(Detector, "SoftCascade.Detector",
obj.info()->addParam(obj, "minScale", obj.minScale); obj.info()->addParam(obj, "minScale", obj.minScale);
obj.info()->addParam(obj, "maxScale", obj.maxScale); obj.info()->addParam(obj, "maxScale", obj.maxScale);
obj.info()->addParam(obj, "scales", obj.scales); obj.info()->addParam(obj, "scales", obj.scales);
...@@ -54,7 +54,7 @@ CV_INIT_ALGORITHM(SoftCascadeDetector, "SoftCascade.SoftCascadeDetector", ...@@ -54,7 +54,7 @@ CV_INIT_ALGORITHM(SoftCascadeDetector, "SoftCascade.SoftCascadeDetector",
bool initModule_softcascade(void) bool initModule_softcascade(void)
{ {
Ptr<Algorithm> sc1 = createSoftCascadeDetector(); Ptr<Algorithm> sc1 = createDetector();
return (sc1->info() != 0); return (sc1->info() != 0);
} }
......
...@@ -42,15 +42,17 @@ ...@@ -42,15 +42,17 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
using namespace cv::softcascade;
TEST(ChannelFeatureBuilderTest, info) TEST(ChannelFeatureBuilderTest, info)
{ {
cv::Ptr<cv::scascade::ChannelFeatureBuilder> builder = cv::scascade::ChannelFeatureBuilder::create(); cv::Ptr<ChannelFeatureBuilder> builder = ChannelFeatureBuilder::create();
ASSERT_TRUE(builder->info() != 0); ASSERT_TRUE(builder->info() != 0);
} }
TEST(ChannelFeatureBuilderTest, compute) TEST(ChannelFeatureBuilderTest, compute)
{ {
cv::Ptr<cv::scascade::ChannelFeatureBuilder> builder = cv::scascade::ChannelFeatureBuilder::create(); cv::Ptr<ChannelFeatureBuilder> builder = ChannelFeatureBuilder::create();
cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/images/image_00000000_0.png"); cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/images/image_00000000_0.png");
cv::Mat ints; cv::Mat ints;
......
...@@ -44,12 +44,13 @@ ...@@ -44,12 +44,13 @@
#include <fstream> #include <fstream>
#include "test_precomp.hpp" #include "test_precomp.hpp"
typedef cv::scascade::Detection Detection;
using namespace cv::softcascade;
TEST(SoftCascadeDetector, readCascade) TEST(SoftCascadeDetector, readCascade)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
...@@ -58,7 +59,7 @@ TEST(SoftCascadeDetector, readCascade) ...@@ -58,7 +59,7 @@ TEST(SoftCascadeDetector, readCascade)
TEST(SoftCascadeDetector, detect) TEST(SoftCascadeDetector, detect)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path()+ "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path()+ "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
...@@ -74,7 +75,7 @@ TEST(SoftCascadeDetector, detect) ...@@ -74,7 +75,7 @@ TEST(SoftCascadeDetector, detect)
TEST(SoftCascadeDetector, detectSeparate) TEST(SoftCascadeDetector, detectSeparate)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
...@@ -90,7 +91,7 @@ TEST(SoftCascadeDetector, detectSeparate) ...@@ -90,7 +91,7 @@ TEST(SoftCascadeDetector, detectSeparate)
TEST(SoftCascadeDetector, detectRoi) TEST(SoftCascadeDetector, detectRoi)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
...@@ -108,7 +109,7 @@ TEST(SoftCascadeDetector, detectRoi) ...@@ -108,7 +109,7 @@ TEST(SoftCascadeDetector, detectRoi)
TEST(SoftCascadeDetector, detectNoRoi) TEST(SoftCascadeDetector, detectNoRoi)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
...@@ -126,7 +127,7 @@ TEST(SoftCascadeDetector, detectNoRoi) ...@@ -126,7 +127,7 @@ TEST(SoftCascadeDetector, detectNoRoi)
TEST(SoftCascadeDetector, detectEmptyRoi) TEST(SoftCascadeDetector, detectEmptyRoi)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml"; std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/cascades/inria_caltech-17.01.2013.xml";
cv::scascade::SoftCascadeDetector cascade; Detector cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
......
...@@ -57,8 +57,10 @@ using namespace std; ...@@ -57,8 +57,10 @@ using namespace std;
namespace { namespace {
using namespace cv::softcascade;
typedef vector<string> svector; typedef vector<string> svector;
class ScaledDataset : public cv::scascade::Dataset class ScaledDataset : public Dataset
{ {
public: public:
ScaledDataset(const string& path, const int octave); ScaledDataset(const string& path, const int octave);
...@@ -210,7 +212,7 @@ TEST(DISABLED_SoftCascade, training) ...@@ -210,7 +212,7 @@ TEST(DISABLED_SoftCascade, training)
float octave = powf(2.f, (float)(*it)); float octave = powf(2.f, (float)(*it));
cv::Size model = cv::Size( cvRound(64 * octave) / shrinkage, cvRound(128 * octave) / shrinkage ); cv::Size model = cv::Size( cvRound(64 * octave) / shrinkage, cvRound(128 * octave) / shrinkage );
cv::Ptr<cv::scascade::FeaturePool> pool = cv::scascade::FeaturePool::create(model, nfeatures); cv::Ptr<FeaturePool> pool = FeaturePool::create(model, nfeatures);
nfeatures = pool->size(); nfeatures = pool->size();
int npositives = 20; int npositives = 20;
int nnegatives = 40; int nnegatives = 40;
...@@ -218,7 +220,6 @@ TEST(DISABLED_SoftCascade, training) ...@@ -218,7 +220,6 @@ TEST(DISABLED_SoftCascade, training)
cv::Rect boundingBox = cv::Rect( cvRound(20 * octave), cvRound(20 * octave), cv::Rect boundingBox = cv::Rect( cvRound(20 * octave), cvRound(20 * octave),
cvRound(64 * octave), cvRound(128 * octave)); cvRound(64 * octave), cvRound(128 * octave));
typedef cv::scascade::SoftCascadeOctave Octave;
cv::Ptr<Octave> boost = Octave::create(boundingBox, npositives, nnegatives, *it, shrinkage, nfeatures); cv::Ptr<Octave> boost = Octave::create(boundingBox, npositives, nnegatives, *it, shrinkage, nfeatures);
std::string path = cvtest::TS::ptr()->get_data_path() + "softcascade/sample_training_set"; std::string path = cvtest::TS::ptr()->get_data_path() + "softcascade/sample_training_set";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment