diff --git a/apps/sft/fpool.cpp b/apps/sft/fpool.cpp index 8eff33ff6d..f29e94dfa2 100644 --- a/apps/sft/fpool.cpp +++ b/apps/sft/fpool.cpp @@ -72,11 +72,6 @@ void sft::ICFFeaturePool::write( cv::FileStorage& fs, int index) const fs << pool[index]; } -void sft::write(cv::FileStorage& fs, const string&, const ICF& f) -{ - fs << "{" << "channel" << f.channel << "rect" << f.bb << "}"; -} - sft::ICFFeaturePool::~ICFFeaturePool(){} #if defined _WIN32 && (_WIN32 || _WIN64) @@ -137,7 +132,7 @@ void sft::ICFFeaturePool::fill(int desired) int ch = chRand(eng_ch); - sft::ICF f(x, y, w, h, ch); + cv::ChannelFeature f(x, y, w, h, ch); if (std::find(pool.begin(), pool.end(),f) == pool.end()) { @@ -147,12 +142,6 @@ void sft::ICFFeaturePool::fill(int desired) } } -std::ostream& sft::operator<<(std::ostream& out, const sft::ICF& m) -{ - out << m.channel << " " << m.bb; - return out; -} - // ============ Dataset ============ // namespace { using namespace sft; diff --git a/apps/sft/include/sft/fpool.hpp b/apps/sft/include/sft/fpool.hpp index d531a760d0..9a7c192b7f 100644 --- a/apps/sft/include/sft/fpool.hpp +++ b/apps/sft/include/sft/fpool.hpp @@ -50,48 +50,6 @@ #include namespace sft { -struct ICF -{ - ICF(int x, int y, int w, int h, int ch) : bb(cv::Rect(x, y, w, h)), channel(ch) {} - - bool operator ==(ICF b) - { - return bb == b.bb && channel == b.channel; - } - - bool operator !=(ICF b) - { - return bb != b.bb || channel != b.channel; - } - - - float operator() (const cv::Mat& integrals, const cv::Size& model) const - { - int step = model.width + 1; - - const int* ptr = integrals.ptr(0) + (model.height * channel + bb.y) * step + bb.x; - - int a = ptr[0]; - int b = ptr[bb.width]; - - ptr += bb.height * step; - - int c = ptr[bb.width]; - int d = ptr[0]; - - return (float)(a - b + c - d); - } - -private: - cv::Rect bb; - int channel; - - friend void write(cv::FileStorage& fs, const std::string&, const ICF& f); - friend std::ostream& operator<<(std::ostream& out, const ICF& f); -}; - -void write(cv::FileStorage& fs, const std::string&, const ICF& f); -std::ostream& operator<<(std::ostream& out, const ICF& m); using cv::FeaturePool; using cv::Dataset; @@ -115,7 +73,7 @@ private: cv::Size model; int nfeatures; - std::vector pool; + std::vector pool; static const unsigned int seed = 0; diff --git a/modules/softcascade/include/opencv2/softcascade/softcascade.hpp b/modules/softcascade/include/opencv2/softcascade/softcascade.hpp index ad5586858a..2a4339c2b9 100644 --- a/modules/softcascade/include/opencv2/softcascade/softcascade.hpp +++ b/modules/softcascade/include/opencv2/softcascade/softcascade.hpp @@ -87,6 +87,31 @@ public: virtual ~Dataset(); }; +// ========================================================================== // +// First order channel feature. +// ========================================================================== // + +class CV_EXPORTS ChannelFeature +{ +public: + ChannelFeature(int x, int y, int w, int h, int ch); + ~ChannelFeature(); + + bool operator ==(ChannelFeature b); + bool operator !=(ChannelFeature b); + + float operator() (const cv::Mat& integrals, const cv::Size& model) const; + + friend void write(cv::FileStorage& fs, const std::string&, const ChannelFeature& f); + friend std::ostream& operator<<(std::ostream& out, const ChannelFeature& f); + +private: + cv::Rect bb; + int channel; +}; + +void write(cv::FileStorage& fs, const std::string&, const ChannelFeature& f); +std::ostream& operator<<(std::ostream& out, const ChannelFeature& m); // ========================================================================== // // Public Interface for Integral Channel Feature. diff --git a/modules/softcascade/src/_random.hpp b/modules/softcascade/src/_random.hpp new file mode 100644 index 0000000000..3a3be8bbc7 --- /dev/null +++ b/modules/softcascade/src/_random.hpp @@ -0,0 +1,117 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __SFT_RANDOM_HPP__ +#define __SFT_RANDOM_HPP__ + +#if defined(_MSC_VER) && _MSC_VER >= 1600 + +# include +namespace sft { +struct Random +{ + typedef std::mt19937 engine; + typedef std::uniform_int uniform; +}; +} + +#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__) + +# if defined (__cplusplus) && __cplusplus > 201100L +# include +namespace sft { +struct Random +{ + typedef std::mt19937 engine; + typedef std::uniform_int uniform; +}; +} +# else +# include + +namespace sft { +struct Random +{ + typedef std::tr1::mt19937 engine; + typedef std::tr1::uniform_int uniform; +}; +} +# endif + +#else +#include +namespace rnd { + +typedef cv::RNG engine; + +template +struct uniform_int +{ + uniform_int(const int _min, const int _max) : min(_min), max(_max) {} + T operator() (engine& eng, const int bound) const + { + return (T)eng.uniform(min, bound); + } + + T operator() (engine& eng) const + { + return (T)eng.uniform(min, max); + } + +private: + int min; + int max; +}; + +} + +namespace sft { +struct Random +{ + typedef rnd::engine engine; + typedef rnd::uniform_int uniform; +}; +} + +#endif + +#endif \ No newline at end of file diff --git a/modules/softcascade/src/integral_channel_builder.cpp b/modules/softcascade/src/integral_channel_builder.cpp index 3d07df4f91..ce437db4a9 100644 --- a/modules/softcascade/src/integral_channel_builder.cpp +++ b/modules/softcascade/src/integral_channel_builder.cpp @@ -44,9 +44,9 @@ namespace { -class ICF : public cv::ChannelFeatureBuilder +class ICFBuilder : public cv::ChannelFeatureBuilder { - virtual ~ICF() {} + virtual ~ICFBuilder() {} virtual cv::AlgorithmInfo* info() const; virtual void operator()(cv::InputArray _frame, CV_OUT cv::OutputArray _integrals) const { @@ -107,12 +107,56 @@ class ICF : public cv::ChannelFeatureBuilder } -CV_INIT_ALGORITHM(ICF, "ChannelFeatureBuilder.ICF", ); +CV_INIT_ALGORITHM(ICFBuilder, "ChannelFeatureBuilder.ICFBuilder", ); cv::ChannelFeatureBuilder::~ChannelFeatureBuilder() {} cv::Ptr cv::ChannelFeatureBuilder::create() { - cv::Ptr builder(new ICF()); + cv::Ptr builder(new ICFBuilder()); return builder; -} \ No newline at end of file +} + +cv::ChannelFeature::ChannelFeature(int x, int y, int w, int h, int ch) +: bb(cv::Rect(x, y, w, h)), channel(ch) {} + +bool cv::ChannelFeature::operator ==(cv::ChannelFeature b) +{ + return bb == b.bb && channel == b.channel; +} + +bool cv::ChannelFeature::operator !=(cv::ChannelFeature b) +{ + return bb != b.bb || channel != b.channel; +} + + +float cv::ChannelFeature::operator() (const cv::Mat& integrals, const cv::Size& model) const +{ + int step = model.width + 1; + + const int* ptr = integrals.ptr(0) + (model.height * channel + bb.y) * step + bb.x; + + int a = ptr[0]; + int b = ptr[bb.width]; + + ptr += bb.height * step; + + int c = ptr[bb.width]; + int d = ptr[0]; + + return (float)(a - b + c - d); +} + +void cv::write(cv::FileStorage& fs, const string&, const cv::ChannelFeature& f) +{ + fs << "{" << "channel" << f.channel << "rect" << f.bb << "}"; +} + +std::ostream& cv::operator<<(std::ostream& out, const cv::ChannelFeature& m) +{ + out << m.channel << " " << m.bb; + return out; +} + +cv::ChannelFeature::~ChannelFeature(){} diff --git a/modules/softcascade/src/soft_cascade_octave.cpp b/modules/softcascade/src/soft_cascade_octave.cpp index 3e5ba7e3fb..305cdf5daa 100644 --- a/modules/softcascade/src/soft_cascade_octave.cpp +++ b/modules/softcascade/src/soft_cascade_octave.cpp @@ -43,6 +43,7 @@ #include "precomp.hpp" #include #include +#include "_random.hpp" #define WITH_DEBUG_OUT @@ -53,75 +54,6 @@ # define dprintf(format, ...) #endif -#if defined(_MSC_VER) && _MSC_VER >= 1600 - -# include -namespace sft { -struct Random -{ - typedef std::mt19937 engine; - typedef std::uniform_int uniform; -}; -} - -#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__) - -# if defined (__cplusplus) && __cplusplus > 201100L -# include -namespace sft { -struct Random -{ - typedef std::mt19937 engine; - typedef std::uniform_int uniform; -}; -} -# else -# include - -namespace sft { -struct Random -{ - typedef std::tr1::mt19937 engine; - typedef std::tr1::uniform_int uniform; -}; -} -# endif - -#else -#include -namespace rnd { - -typedef cv::RNG engine; - -template -struct uniform_int -{ - uniform_int(const int _min, const int _max) : min(_min), max(_max) {} - T operator() (engine& eng, const int bound) const - { - return (T)eng.uniform(min, bound); - } - - T operator() (engine& eng) const - { - return (T)eng.uniform(min, max); - } - -private: - int min; - int max; -}; - -} - -namespace sft { -struct Random -{ - typedef rnd::engine engine; - typedef rnd::uniform_int uniform; -}; -} -#endif using cv::Dataset; using cv::FeaturePool;