move ICF -> ChannelFeature
This commit is contained in:
parent
a01f596474
commit
b4aa33b6d3
@ -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;
|
||||
|
@ -50,48 +50,6 @@
|
||||
#include <opencv2/softcascade/softcascade.hpp>
|
||||
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<int>(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<ICF> pool;
|
||||
std::vector<cv::ChannelFeature> pool;
|
||||
|
||||
static const unsigned int seed = 0;
|
||||
|
||||
|
@ -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.
|
||||
|
117
modules/softcascade/src/_random.hpp
Normal file
117
modules/softcascade/src/_random.hpp
Normal file
@ -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 <random>
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::mt19937 engine;
|
||||
typedef std::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
|
||||
#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__)
|
||||
|
||||
# if defined (__cplusplus) && __cplusplus > 201100L
|
||||
# include <random>
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::mt19937 engine;
|
||||
typedef std::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
# else
|
||||
# include <tr1/random>
|
||||
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::tr1::mt19937 engine;
|
||||
typedef std::tr1::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
# endif
|
||||
|
||||
#else
|
||||
#include <opencv2/core/core.hpp>
|
||||
namespace rnd {
|
||||
|
||||
typedef cv::RNG engine;
|
||||
|
||||
template<typename T>
|
||||
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<int> uniform;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -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> cv::ChannelFeatureBuilder::create()
|
||||
{
|
||||
cv::Ptr<cv::ChannelFeatureBuilder> builder(new ICF());
|
||||
cv::Ptr<cv::ChannelFeatureBuilder> builder(new ICFBuilder());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
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<int>(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(){}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "precomp.hpp"
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include "_random.hpp"
|
||||
|
||||
#define WITH_DEBUG_OUT
|
||||
|
||||
@ -53,75 +54,6 @@
|
||||
# define dprintf(format, ...)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1600
|
||||
|
||||
# include <random>
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::mt19937 engine;
|
||||
typedef std::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
|
||||
#elif (__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 1 && !defined(__ANDROID__)
|
||||
|
||||
# if defined (__cplusplus) && __cplusplus > 201100L
|
||||
# include <random>
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::mt19937 engine;
|
||||
typedef std::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
# else
|
||||
# include <tr1/random>
|
||||
|
||||
namespace sft {
|
||||
struct Random
|
||||
{
|
||||
typedef std::tr1::mt19937 engine;
|
||||
typedef std::tr1::uniform_int<int> uniform;
|
||||
};
|
||||
}
|
||||
# endif
|
||||
|
||||
#else
|
||||
#include <opencv2/core/core.hpp>
|
||||
namespace rnd {
|
||||
|
||||
typedef cv::RNG engine;
|
||||
|
||||
template<typename T>
|
||||
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<int> uniform;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
using cv::Dataset;
|
||||
using cv::FeaturePool;
|
||||
|
Loading…
x
Reference in New Issue
Block a user