Normalize line endings and whitespace
This commit is contained in:
committed by
Andrey Kamaev
parent
69020da607
commit
04384a71e4
@@ -57,7 +57,7 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
BackgroundSubtractor::~BackgroundSubtractor() {}
|
||||
void BackgroundSubtractor::operator()(InputArray, OutputArray, double)
|
||||
{
|
||||
@@ -73,12 +73,12 @@ static const double defaultBackgroundRatio = 0.7;
|
||||
static const double defaultVarThreshold = 2.5*2.5;
|
||||
static const double defaultNoiseSigma = 30*0.5;
|
||||
static const double defaultInitialWeight = 0.05;
|
||||
|
||||
|
||||
BackgroundSubtractorMOG::BackgroundSubtractorMOG()
|
||||
{
|
||||
frameSize = Size(0,0);
|
||||
frameType = 0;
|
||||
|
||||
|
||||
nframes = 0;
|
||||
nmixtures = defaultNMixtures;
|
||||
history = defaultHistory;
|
||||
@@ -86,14 +86,14 @@ BackgroundSubtractorMOG::BackgroundSubtractorMOG()
|
||||
backgroundRatio = defaultBackgroundRatio;
|
||||
noiseSigma = defaultNoiseSigma;
|
||||
}
|
||||
|
||||
|
||||
BackgroundSubtractorMOG::BackgroundSubtractorMOG(int _history, int _nmixtures,
|
||||
double _backgroundRatio,
|
||||
double _noiseSigma)
|
||||
{
|
||||
frameSize = Size(0,0);
|
||||
frameType = 0;
|
||||
|
||||
|
||||
nframes = 0;
|
||||
nmixtures = min(_nmixtures > 0 ? _nmixtures : defaultNMixtures, 8);
|
||||
history = _history > 0 ? _history : defaultHistory;
|
||||
@@ -101,7 +101,7 @@ BackgroundSubtractorMOG::BackgroundSubtractorMOG(int _history, int _nmixtures,
|
||||
backgroundRatio = min(_backgroundRatio > 0 ? _backgroundRatio : 0.95, 1.);
|
||||
noiseSigma = _noiseSigma <= 0 ? defaultNoiseSigma : _noiseSigma;
|
||||
}
|
||||
|
||||
|
||||
BackgroundSubtractorMOG::~BackgroundSubtractorMOG()
|
||||
{
|
||||
}
|
||||
@@ -112,10 +112,10 @@ void BackgroundSubtractorMOG::initialize(Size _frameSize, int _frameType)
|
||||
frameSize = _frameSize;
|
||||
frameType = _frameType;
|
||||
nframes = 0;
|
||||
|
||||
|
||||
int nchannels = CV_MAT_CN(frameType);
|
||||
CV_Assert( CV_MAT_DEPTH(frameType) == CV_8U );
|
||||
|
||||
|
||||
// for each gaussian mixture of each pixel bg model we store ...
|
||||
// the mixture sort key (w/sum_of_variances), the mixture weight (w),
|
||||
// the mean (nchannels values) and
|
||||
@@ -124,7 +124,7 @@ void BackgroundSubtractorMOG::initialize(Size _frameSize, int _frameType)
|
||||
bgmodel = Scalar::all(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename VT> struct MixData
|
||||
{
|
||||
float sortKey;
|
||||
@@ -133,7 +133,7 @@ template<typename VT> struct MixData
|
||||
VT var;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
Mat& bgmodel, int nmixtures, double backgroundRatio,
|
||||
double varThreshold, double noiseSigma )
|
||||
@@ -142,17 +142,17 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
float alpha = (float)learningRate, T = (float)backgroundRatio, vT = (float)varThreshold;
|
||||
int K = nmixtures;
|
||||
MixData<float>* mptr = (MixData<float>*)bgmodel.data;
|
||||
|
||||
|
||||
const float w0 = (float)defaultInitialWeight;
|
||||
const float sk0 = (float)(w0/(defaultNoiseSigma*2));
|
||||
const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4);
|
||||
const float minVar = (float)(noiseSigma*noiseSigma);
|
||||
|
||||
|
||||
for( y = 0; y < rows; y++ )
|
||||
{
|
||||
const uchar* src = image.ptr<uchar>(y);
|
||||
uchar* dst = fgmask.ptr<uchar>(y);
|
||||
|
||||
|
||||
if( alpha > 0 )
|
||||
{
|
||||
for( x = 0; x < cols; x++, mptr += K )
|
||||
@@ -160,7 +160,7 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
float wsum = 0;
|
||||
float pix = src[x];
|
||||
int kHit = -1, kForeground = -1;
|
||||
|
||||
|
||||
for( k = 0; k < K; k++ )
|
||||
{
|
||||
float w = mptr[k].weight;
|
||||
@@ -180,19 +180,19 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
var = max(var + alpha*(d2 - var), minVar);
|
||||
mptr[k].var = var;
|
||||
mptr[k].sortKey = w/sqrt(var);
|
||||
|
||||
|
||||
for( k1 = k-1; k1 >= 0; k1-- )
|
||||
{
|
||||
if( mptr[k1].sortKey >= mptr[k1+1].sortKey )
|
||||
break;
|
||||
std::swap( mptr[k1], mptr[k1+1] );
|
||||
}
|
||||
|
||||
|
||||
kHit = k1+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( kHit < 0 ) // no appropriate gaussian mixture found at all, remove the weakest mixture and create a new one
|
||||
{
|
||||
kHit = k = min(k, K-1);
|
||||
@@ -205,7 +205,7 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
else
|
||||
for( ; k < K; k++ )
|
||||
wsum += mptr[k].weight;
|
||||
|
||||
|
||||
float wscale = 1.f/wsum;
|
||||
wsum = 0;
|
||||
for( k = 0; k < K; k++ )
|
||||
@@ -215,7 +215,7 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
if( wsum > T && kForeground < 0 )
|
||||
kForeground = k+1;
|
||||
}
|
||||
|
||||
|
||||
dst[x] = (uchar)(-(kHit >= kForeground));
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
{
|
||||
float pix = src[x];
|
||||
int kHit = -1, kForeground = -1;
|
||||
|
||||
|
||||
for( k = 0; k < K; k++ )
|
||||
{
|
||||
if( mptr[k].weight < FLT_EPSILON )
|
||||
@@ -240,7 +240,7 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( kHit >= 0 )
|
||||
{
|
||||
float wsum = 0;
|
||||
@@ -254,14 +254,14 @@ static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dst[x] = (uchar)(kHit < 0 || kHit >= kForeground ? 255 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
Mat& bgmodel, int nmixtures, double backgroundRatio,
|
||||
double varThreshold, double noiseSigma )
|
||||
@@ -269,18 +269,18 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
int x, y, k, k1, rows = image.rows, cols = image.cols;
|
||||
float alpha = (float)learningRate, T = (float)backgroundRatio, vT = (float)varThreshold;
|
||||
int K = nmixtures;
|
||||
|
||||
|
||||
const float w0 = (float)defaultInitialWeight;
|
||||
const float sk0 = (float)(w0/(defaultNoiseSigma*2*sqrt(3.)));
|
||||
const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4);
|
||||
const float minVar = (float)(noiseSigma*noiseSigma);
|
||||
MixData<Vec3f>* mptr = (MixData<Vec3f>*)bgmodel.data;
|
||||
|
||||
|
||||
for( y = 0; y < rows; y++ )
|
||||
{
|
||||
const uchar* src = image.ptr<uchar>(y);
|
||||
uchar* dst = fgmask.ptr<uchar>(y);
|
||||
|
||||
|
||||
if( alpha > 0 )
|
||||
{
|
||||
for( x = 0; x < cols; x++, mptr += K )
|
||||
@@ -288,7 +288,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
float wsum = 0;
|
||||
Vec3f pix(src[x*3], src[x*3+1], src[x*3+2]);
|
||||
int kHit = -1, kForeground = -1;
|
||||
|
||||
|
||||
for( k = 0; k < K; k++ )
|
||||
{
|
||||
float w = mptr[k].weight;
|
||||
@@ -310,19 +310,19 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
max(var[2] + alpha*(diff[2]*diff[2] - var[2]), minVar));
|
||||
mptr[k].var = var;
|
||||
mptr[k].sortKey = w/sqrt(var[0] + var[1] + var[2]);
|
||||
|
||||
|
||||
for( k1 = k-1; k1 >= 0; k1-- )
|
||||
{
|
||||
if( mptr[k1].sortKey >= mptr[k1+1].sortKey )
|
||||
break;
|
||||
std::swap( mptr[k1], mptr[k1+1] );
|
||||
}
|
||||
|
||||
|
||||
kHit = k1+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( kHit < 0 ) // no appropriate gaussian mixture found at all, remove the weakest mixture and create a new one
|
||||
{
|
||||
kHit = k = min(k, K-1);
|
||||
@@ -335,7 +335,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
else
|
||||
for( ; k < K; k++ )
|
||||
wsum += mptr[k].weight;
|
||||
|
||||
|
||||
float wscale = 1.f/wsum;
|
||||
wsum = 0;
|
||||
for( k = 0; k < K; k++ )
|
||||
@@ -345,7 +345,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
if( wsum > T && kForeground < 0 )
|
||||
kForeground = k+1;
|
||||
}
|
||||
|
||||
|
||||
dst[x] = (uchar)(-(kHit >= kForeground));
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
{
|
||||
Vec3f pix(src[x*3], src[x*3+1], src[x*3+2]);
|
||||
int kHit = -1, kForeground = -1;
|
||||
|
||||
|
||||
for( k = 0; k < K; k++ )
|
||||
{
|
||||
if( mptr[k].weight < FLT_EPSILON )
|
||||
@@ -370,7 +370,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( kHit >= 0 )
|
||||
{
|
||||
float wsum = 0;
|
||||
@@ -384,7 +384,7 @@ static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dst[x] = (uchar)(kHit < 0 || kHit >= kForeground ? 255 : 0);
|
||||
}
|
||||
}
|
||||
@@ -395,18 +395,18 @@ void BackgroundSubtractorMOG::operator()(InputArray _image, OutputArray _fgmask,
|
||||
{
|
||||
Mat image = _image.getMat();
|
||||
bool needToInitialize = nframes == 0 || learningRate >= 1 || image.size() != frameSize || image.type() != frameType;
|
||||
|
||||
|
||||
if( needToInitialize )
|
||||
initialize(image.size(), image.type());
|
||||
|
||||
|
||||
CV_Assert( image.depth() == CV_8U );
|
||||
_fgmask.create( image.size(), CV_8U );
|
||||
Mat fgmask = _fgmask.getMat();
|
||||
|
||||
|
||||
++nframes;
|
||||
learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./min( nframes, history );
|
||||
CV_Assert(learningRate >= 0);
|
||||
|
||||
|
||||
if( image.type() == CV_8UC1 )
|
||||
process8uC1( image, fgmask, learningRate, bgmodel, nmixtures, backgroundRatio, varThreshold, noiseSigma );
|
||||
else if( image.type() == CV_8UC3 )
|
||||
@@ -414,7 +414,7 @@ void BackgroundSubtractorMOG::operator()(InputArray _image, OutputArray _fgmask,
|
||||
else
|
||||
CV_Error( CV_StsUnsupportedFormat, "Only 1- and 3-channel 8-bit images are supported in BackgroundSubtractorMOG" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -41,30 +41,30 @@
|
||||
/*//Implementation of the Gaussian mixture model background subtraction from:
|
||||
//
|
||||
//"Improved adaptive Gausian mixture model for background subtraction"
|
||||
//Z.Zivkovic
|
||||
//Z.Zivkovic
|
||||
//International Conference Pattern Recognition, UK, August, 2004
|
||||
//http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf
|
||||
//The code is very fast and performs also shadow detection.
|
||||
//The code is very fast and performs also shadow detection.
|
||||
//Number of Gausssian components is adapted per pixel.
|
||||
//
|
||||
// and
|
||||
//
|
||||
//"Efficient Adaptive Density Estimapion per Image Pixel for the Task of Background Subtraction"
|
||||
//Z.Zivkovic, F. van der Heijden
|
||||
//Z.Zivkovic, F. van der Heijden
|
||||
//Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
|
||||
//
|
||||
//The algorithm similar to the standard Stauffer&Grimson algorithm with
|
||||
//additional selection of the number of the Gaussian components based on:
|
||||
//
|
||||
//"Recursive unsupervised learning of finite mixture models "
|
||||
//Z.Zivkovic, F.van der Heijden
|
||||
//Z.Zivkovic, F.van der Heijden
|
||||
//IEEE Trans. on Pattern Analysis and Machine Intelligence, vol.26, no.5, pages 651-656, 2004
|
||||
//http://www.zoranz.net/Publications/zivkovic2004PAMI.pdf
|
||||
//
|
||||
//
|
||||
//Example usage with as cpp class
|
||||
// BackgroundSubtractorMOG2 bg_model;
|
||||
//For each new image the model is updates using:
|
||||
//For each new image the model is updates using:
|
||||
// bg_model(img, fgmask);
|
||||
//
|
||||
//Example usage as part of the CvBGStatModel:
|
||||
@@ -87,16 +87,16 @@ namespace cv
|
||||
|
||||
/*
|
||||
Interface of Gaussian mixture algorithm from:
|
||||
|
||||
|
||||
"Improved adaptive Gausian mixture model for background subtraction"
|
||||
Z.Zivkovic
|
||||
International Conference Pattern Recognition, UK, August, 2004
|
||||
http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf
|
||||
|
||||
|
||||
Advantages:
|
||||
-fast - number of Gausssian components is constantly adapted per pixel.
|
||||
-performs also shadow detection (see bgfg_segm_test.cpp example)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// default parameters of gaussian background detection algorithm
|
||||
@@ -109,23 +109,23 @@ static const float defaultVarInit2 = 15.0f; // initial variance for new componen
|
||||
static const float defaultVarMax2 = 5*defaultVarInit2;
|
||||
static const float defaultVarMin2 = 4.0f;
|
||||
|
||||
// additional parameters
|
||||
// additional parameters
|
||||
static const float defaultfCT2 = 0.05f; // complexity reduction prior constant 0 - no reduction of number of components
|
||||
static const unsigned char defaultnShadowDetection2 = (unsigned char)127; // value to use in the segmentation mask for shadows, set 0 not to do shadow detection
|
||||
static const float defaultfTau = 0.5f; // Tau - shadow threshold, see the paper for explanation
|
||||
|
||||
|
||||
struct GaussBGStatModel2Params
|
||||
{
|
||||
//image info
|
||||
int nWidth;
|
||||
int nHeight;
|
||||
int nND;//number of data dimensions (image channels)
|
||||
|
||||
bool bPostFiltering;//defult 1 - do postfiltering - will make shadow detection results also give value 255
|
||||
|
||||
bool bPostFiltering;//defult 1 - do postfiltering - will make shadow detection results also give value 255
|
||||
double minArea; // for postfiltering
|
||||
|
||||
|
||||
bool bInit;//default 1, faster updates at start
|
||||
|
||||
|
||||
/////////////////////////
|
||||
//very important parameters - things you will change
|
||||
////////////////////////
|
||||
@@ -138,7 +138,7 @@ struct GaussBGStatModel2Params
|
||||
//by the background model or not. Related to Cthr from the paper.
|
||||
//This does not influence the update of the background. A typical value could be 4 sigma
|
||||
//and that is Tb=4*4=16;
|
||||
|
||||
|
||||
/////////////////////////
|
||||
//less important parameters - things you might change but be carefull
|
||||
////////////////////////
|
||||
@@ -164,10 +164,10 @@ struct GaussBGStatModel2Params
|
||||
//this is related to the number of samples needed to accept that a component
|
||||
//actually exists. We use CT=0.05 of all the samples. By setting CT=0 you get
|
||||
//the standard Stauffer&Grimson algorithm (maybe not exact but very similar)
|
||||
|
||||
|
||||
//even less important parameters
|
||||
int nM;//max number of modes - const - 4 is usually enough
|
||||
|
||||
|
||||
//shadow detection parameters
|
||||
bool bShadowDetection;//default 1 - do shadow detection
|
||||
unsigned char nShadowDetection;//do shadow detection - insert this value as the detection result
|
||||
@@ -216,7 +216,7 @@ detectShadowGMM(const float* data, int nchannels, int nmodes,
|
||||
{
|
||||
float a = numerator / denominator;
|
||||
float dist2a = 0.0f;
|
||||
|
||||
|
||||
for( int c = 0; c < nchannels; c++ )
|
||||
{
|
||||
float dD= a*mean[c] - data[c];
|
||||
@@ -237,14 +237,14 @@ detectShadowGMM(const float* data, int nchannels, int nmodes,
|
||||
//update GMM - the base update function performed per pixel
|
||||
//
|
||||
//"Efficient Adaptive Density Estimapion per Image Pixel for the Task of Background Subtraction"
|
||||
//Z.Zivkovic, F. van der Heijden
|
||||
//Z.Zivkovic, F. van der Heijden
|
||||
//Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.
|
||||
//
|
||||
//The algorithm similar to the standard Stauffer&Grimson algorithm with
|
||||
//additional selection of the number of the Gaussian components based on:
|
||||
//
|
||||
//"Recursive unsupervised learning of finite mixture models "
|
||||
//Z.Zivkovic, F.van der Heijden
|
||||
//Z.Zivkovic, F.van der Heijden
|
||||
//IEEE Trans. on Pattern Analysis and Machine Intelligence, vol.26, no.5, pages 651-656, 2004
|
||||
//http://www.zoranz.net/Publications/zivkovic2004PAMI.pdf
|
||||
|
||||
@@ -276,10 +276,10 @@ struct MOG2Invoker
|
||||
tau = _tau;
|
||||
detectShadows = _detectShadows;
|
||||
shadowVal = _shadowVal;
|
||||
|
||||
|
||||
cvtfunc = src->depth() != CV_32F ? getConvertFunc(src->depth(), CV_32F) : 0;
|
||||
}
|
||||
|
||||
|
||||
void operator()(const BlockedRange& range) const
|
||||
{
|
||||
int y0 = range.begin(), y1 = range.end();
|
||||
@@ -287,7 +287,7 @@ struct MOG2Invoker
|
||||
AutoBuffer<float> buf(src->cols*nchannels);
|
||||
float alpha1 = 1.f - alphaT;
|
||||
float dData[CV_CN_MAX];
|
||||
|
||||
|
||||
for( int y = y0; y < y1; y++ )
|
||||
{
|
||||
const float* data = buf;
|
||||
@@ -295,41 +295,41 @@ struct MOG2Invoker
|
||||
cvtfunc( src->ptr(y), src->step, 0, 0, (uchar*)data, 0, Size(ncols*nchannels, 1), 0);
|
||||
else
|
||||
data = src->ptr<float>(y);
|
||||
|
||||
|
||||
float* mean = mean0 + ncols*nmixtures*nchannels*y;
|
||||
GMM* gmm = gmm0 + ncols*nmixtures*y;
|
||||
uchar* modesUsed = modesUsed0 + ncols*y;
|
||||
uchar* mask = dst->ptr(y);
|
||||
|
||||
|
||||
for( int x = 0; x < ncols; x++, data += nchannels, gmm += nmixtures, mean += nmixtures*nchannels )
|
||||
{
|
||||
//calculate distances to the modes (+ sort)
|
||||
//here we need to go in descending order!!!
|
||||
//here we need to go in descending order!!!
|
||||
bool background = false;//return value -> true - the pixel classified as background
|
||||
|
||||
|
||||
//internal:
|
||||
bool fitsPDF = false;//if it remains zero a new GMM mode will be added
|
||||
bool fitsPDF = false;//if it remains zero a new GMM mode will be added
|
||||
int nmodes = modesUsed[x], nNewModes = nmodes;//current number of modes in GMM
|
||||
float totalWeight = 0.f;
|
||||
|
||||
|
||||
float* mean_m = mean;
|
||||
|
||||
|
||||
//////
|
||||
//go through all modes
|
||||
for( int mode = 0; mode < nmodes; mode++, mean_m += nchannels )
|
||||
{
|
||||
float weight = alpha1*gmm[mode].weight + prune;//need only weight if fit is found
|
||||
|
||||
|
||||
////
|
||||
//fit not found yet
|
||||
if( !fitsPDF )
|
||||
{
|
||||
//check if it belongs to some of the remaining modes
|
||||
float var = gmm[mode].variance;
|
||||
|
||||
|
||||
//calculate difference and distance
|
||||
float dist2;
|
||||
|
||||
|
||||
if( nchannels == 3 )
|
||||
{
|
||||
dData[0] = mean_m[0] - data[0];
|
||||
@@ -346,44 +346,44 @@ struct MOG2Invoker
|
||||
dist2 += dData[c]*dData[c];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//background? - Tb - usually larger than Tg
|
||||
if( totalWeight < TB && dist2 < Tb*var )
|
||||
background = true;
|
||||
|
||||
|
||||
//check fit
|
||||
if( dist2 < Tg*var )
|
||||
{
|
||||
/////
|
||||
//belongs to the mode
|
||||
fitsPDF = true;
|
||||
|
||||
//update distribution
|
||||
|
||||
|
||||
//update distribution
|
||||
|
||||
//update weight
|
||||
weight += alphaT;
|
||||
float k = alphaT/weight;
|
||||
|
||||
|
||||
//update mean
|
||||
for( int c = 0; c < nchannels; c++ )
|
||||
mean_m[c] -= k*dData[c];
|
||||
|
||||
|
||||
//update variance
|
||||
float varnew = var + k*(dist2-var);
|
||||
//limit the variance
|
||||
varnew = MAX(varnew, varMin);
|
||||
varnew = MIN(varnew, varMax);
|
||||
gmm[mode].variance = varnew;
|
||||
|
||||
|
||||
//sort
|
||||
//all other weights are at the same place and
|
||||
//only the matched (iModes) is higher -> just find the new place for it
|
||||
//all other weights are at the same place and
|
||||
//only the matched (iModes) is higher -> just find the new place for it
|
||||
for( int i = mode; i > 0; i-- )
|
||||
{
|
||||
//check one up
|
||||
if( weight < gmm[i-1].weight )
|
||||
break;
|
||||
|
||||
|
||||
//swap one up
|
||||
std::swap(gmm[i], gmm[i-1]);
|
||||
for( int c = 0; c < nchannels; c++ )
|
||||
@@ -393,52 +393,52 @@ struct MOG2Invoker
|
||||
/////
|
||||
}
|
||||
}//!bFitsPDF)
|
||||
|
||||
|
||||
//check prune
|
||||
if( weight < -prune )
|
||||
{
|
||||
weight = 0.0;
|
||||
nmodes--;
|
||||
}
|
||||
|
||||
|
||||
gmm[mode].weight = weight;//update weight by the calculated value
|
||||
totalWeight += weight;
|
||||
}
|
||||
//go through all modes
|
||||
//////
|
||||
|
||||
|
||||
//renormalize weights
|
||||
totalWeight = 1.f/totalWeight;
|
||||
for( int mode = 0; mode < nmodes; mode++ )
|
||||
{
|
||||
gmm[mode].weight *= totalWeight;
|
||||
}
|
||||
|
||||
|
||||
nmodes = nNewModes;
|
||||
|
||||
|
||||
//make new mode if needed and exit
|
||||
if( !fitsPDF )
|
||||
{
|
||||
// replace the weakest or add a new one
|
||||
int mode = nmodes == nmixtures ? nmixtures-1 : nmodes++;
|
||||
|
||||
|
||||
if (nmodes==1)
|
||||
gmm[mode].weight = 1.f;
|
||||
else
|
||||
{
|
||||
gmm[mode].weight = alphaT;
|
||||
|
||||
|
||||
// renormalize all other weights
|
||||
for( int i = 0; i < nmodes-1; i++ )
|
||||
gmm[i].weight *= alpha1;
|
||||
}
|
||||
|
||||
|
||||
// init
|
||||
for( int c = 0; c < nchannels; c++ )
|
||||
mean[mode*nchannels + c] = data[c];
|
||||
|
||||
|
||||
gmm[mode].variance = varInit;
|
||||
|
||||
|
||||
//sort
|
||||
//find the new place for it
|
||||
for( int i = nmodes - 1; i > 0; i-- )
|
||||
@@ -446,14 +446,14 @@ struct MOG2Invoker
|
||||
// check one up
|
||||
if( alphaT < gmm[i-1].weight )
|
||||
break;
|
||||
|
||||
|
||||
// swap one up
|
||||
std::swap(gmm[i], gmm[i-1]);
|
||||
for( int c = 0; c < nchannels; c++ )
|
||||
std::swap(mean[i*nchannels + c], mean[(i-1)*nchannels + c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//set the number of modes
|
||||
modesUsed[x] = uchar(nmodes);
|
||||
mask[x] = background ? 0 :
|
||||
@@ -462,20 +462,20 @@ struct MOG2Invoker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Mat* src;
|
||||
Mat* dst;
|
||||
GMM* gmm0;
|
||||
float* mean0;
|
||||
uchar* modesUsed0;
|
||||
|
||||
|
||||
int nmixtures;
|
||||
float alphaT, Tb, TB, Tg;
|
||||
float varInit, varMin, varMax, prune, tau;
|
||||
|
||||
|
||||
bool detectShadows;
|
||||
uchar shadowVal;
|
||||
|
||||
|
||||
BinaryFunc cvtfunc;
|
||||
};
|
||||
|
||||
@@ -483,13 +483,13 @@ BackgroundSubtractorMOG2::BackgroundSubtractorMOG2()
|
||||
{
|
||||
frameSize = Size(0,0);
|
||||
frameType = 0;
|
||||
|
||||
|
||||
nframes = 0;
|
||||
history = defaultHistory2;
|
||||
varThreshold = defaultVarThreshold2;
|
||||
bShadowDetection = 1;
|
||||
|
||||
nmixtures = defaultNMixtures2;
|
||||
nmixtures = defaultNMixtures2;
|
||||
backgroundRatio = defaultBackgroundRatio2;
|
||||
fVarInit = defaultVarInit2;
|
||||
fVarMax = defaultVarMax2;
|
||||
@@ -500,18 +500,18 @@ BackgroundSubtractorMOG2::BackgroundSubtractorMOG2()
|
||||
nShadowDetection = defaultnShadowDetection2;
|
||||
fTau = defaultfTau;
|
||||
}
|
||||
|
||||
|
||||
BackgroundSubtractorMOG2::BackgroundSubtractorMOG2(int _history, float _varThreshold, bool _bShadowDetection)
|
||||
{
|
||||
frameSize = Size(0,0);
|
||||
frameType = 0;
|
||||
|
||||
|
||||
nframes = 0;
|
||||
history = _history > 0 ? _history : defaultHistory2;
|
||||
varThreshold = (_varThreshold>0)? _varThreshold : defaultVarThreshold2;
|
||||
bShadowDetection = _bShadowDetection;
|
||||
|
||||
nmixtures = defaultNMixtures2;
|
||||
nmixtures = defaultNMixtures2;
|
||||
backgroundRatio = defaultBackgroundRatio2;
|
||||
fVarInit = defaultVarInit2;
|
||||
fVarMax = defaultVarMax2;
|
||||
@@ -522,7 +522,7 @@ BackgroundSubtractorMOG2::BackgroundSubtractorMOG2(int _history, float _varThre
|
||||
nShadowDetection = defaultnShadowDetection2;
|
||||
fTau = defaultfTau;
|
||||
}
|
||||
|
||||
|
||||
BackgroundSubtractorMOG2::~BackgroundSubtractorMOG2()
|
||||
{
|
||||
}
|
||||
@@ -533,10 +533,10 @@ void BackgroundSubtractorMOG2::initialize(Size _frameSize, int _frameType)
|
||||
frameSize = _frameSize;
|
||||
frameType = _frameType;
|
||||
nframes = 0;
|
||||
|
||||
|
||||
int nchannels = CV_MAT_CN(frameType);
|
||||
CV_Assert( nchannels <= CV_CN_MAX );
|
||||
|
||||
|
||||
// for each gaussian mixture of each pixel bg model we store ...
|
||||
// the mixture weight (w),
|
||||
// the mean (nchannels values) and
|
||||
@@ -551,17 +551,17 @@ void BackgroundSubtractorMOG2::operator()(InputArray _image, OutputArray _fgmask
|
||||
{
|
||||
Mat image = _image.getMat();
|
||||
bool needToInitialize = nframes == 0 || learningRate >= 1 || image.size() != frameSize || image.type() != frameType;
|
||||
|
||||
|
||||
if( needToInitialize )
|
||||
initialize(image.size(), image.type());
|
||||
|
||||
|
||||
_fgmask.create( image.size(), CV_8U );
|
||||
Mat fgmask = _fgmask.getMat();
|
||||
|
||||
|
||||
++nframes;
|
||||
learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./min( 2*nframes, history );
|
||||
CV_Assert(learningRate >= 0);
|
||||
|
||||
|
||||
parallel_for(BlockedRange(0, image.rows),
|
||||
MOG2Invoker(image, fgmask,
|
||||
(GMM*)bgmodel.data,
|
||||
|
||||
@@ -52,27 +52,27 @@ cvCreateKalman( int DP, int MP, int CP )
|
||||
|
||||
if( CP < 0 )
|
||||
CP = DP;
|
||||
|
||||
|
||||
/* allocating memory for the structure */
|
||||
kalman = (CvKalman *)cvAlloc( sizeof( CvKalman ));
|
||||
memset( kalman, 0, sizeof(*kalman));
|
||||
|
||||
|
||||
kalman->DP = DP;
|
||||
kalman->MP = MP;
|
||||
kalman->CP = CP;
|
||||
|
||||
kalman->state_pre = cvCreateMat( DP, 1, CV_32FC1 );
|
||||
cvZero( kalman->state_pre );
|
||||
|
||||
|
||||
kalman->state_post = cvCreateMat( DP, 1, CV_32FC1 );
|
||||
cvZero( kalman->state_post );
|
||||
|
||||
|
||||
kalman->transition_matrix = cvCreateMat( DP, DP, CV_32FC1 );
|
||||
cvSetIdentity( kalman->transition_matrix );
|
||||
|
||||
kalman->process_noise_cov = cvCreateMat( DP, DP, CV_32FC1 );
|
||||
cvSetIdentity( kalman->process_noise_cov );
|
||||
|
||||
|
||||
kalman->measurement_matrix = cvCreateMat( MP, DP, CV_32FC1 );
|
||||
cvZero( kalman->measurement_matrix );
|
||||
|
||||
@@ -80,7 +80,7 @@ cvCreateKalman( int DP, int MP, int CP )
|
||||
cvSetIdentity( kalman->measurement_noise_cov );
|
||||
|
||||
kalman->error_cov_pre = cvCreateMat( DP, DP, CV_32FC1 );
|
||||
|
||||
|
||||
kalman->error_cov_post = cvCreateMat( DP, DP, CV_32FC1 );
|
||||
cvZero( kalman->error_cov_post );
|
||||
|
||||
@@ -108,7 +108,7 @@ cvCreateKalman( int DP, int MP, int CP )
|
||||
kalman->KalmGainMatr = kalman->gain->data.fl;
|
||||
kalman->PriorErrorCovariance = kalman->error_cov_pre->data.fl;
|
||||
kalman->PosterErrorCovariance = kalman->error_cov_post->data.fl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return kalman;
|
||||
}
|
||||
@@ -121,11 +121,11 @@ cvReleaseKalman( CvKalman** _kalman )
|
||||
|
||||
if( !_kalman )
|
||||
CV_Error( CV_StsNullPtr, "" );
|
||||
|
||||
|
||||
kalman = *_kalman;
|
||||
if( !kalman )
|
||||
return;
|
||||
|
||||
|
||||
/* freeing the memory */
|
||||
cvReleaseMat( &kalman->state_pre );
|
||||
cvReleaseMat( &kalman->state_post );
|
||||
@@ -163,15 +163,15 @@ cvKalmanPredict( CvKalman* kalman, const CvMat* control )
|
||||
if( control && kalman->CP > 0 )
|
||||
/* x'(k) = x'(k) + B*u(k) */
|
||||
cvMatMulAdd( kalman->control_matrix, control, kalman->state_pre, kalman->state_pre );
|
||||
|
||||
|
||||
/* update error covariance matrices */
|
||||
/* temp1 = A*P(k) */
|
||||
cvMatMulAdd( kalman->transition_matrix, kalman->error_cov_post, 0, kalman->temp1 );
|
||||
|
||||
|
||||
/* P'(k) = temp1*At + Q */
|
||||
cvGEMM( kalman->temp1, kalman->transition_matrix, 1, kalman->process_noise_cov, 1,
|
||||
kalman->error_cov_pre, CV_GEMM_B_T );
|
||||
|
||||
|
||||
/* handle the case when there will be measurement before the next predict */
|
||||
cvCopy(kalman->state_pre, kalman->state_post);
|
||||
|
||||
@@ -196,7 +196,7 @@ cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement )
|
||||
|
||||
/* K(k) */
|
||||
cvTranspose( kalman->temp4, kalman->gain );
|
||||
|
||||
|
||||
/* temp5 = z(k) - H*x'(k) */
|
||||
cvGEMM( kalman->measurement_matrix, kalman->state_pre, -1, measurement, 1, kalman->temp5 );
|
||||
|
||||
@@ -263,7 +263,7 @@ const Mat& KalmanFilter::predict(const Mat& control)
|
||||
|
||||
// P'(k) = temp1*At + Q
|
||||
gemm(temp1, transitionMatrix, 1, processNoiseCov, 1, errorCovPre, GEMM_2_T);
|
||||
|
||||
|
||||
// handle the case when there will be measurement before the next predict.
|
||||
statePre.copyTo(statePost);
|
||||
|
||||
@@ -276,14 +276,14 @@ const Mat& KalmanFilter::correct(const Mat& measurement)
|
||||
temp2 = measurementMatrix * errorCovPre;
|
||||
|
||||
// temp3 = temp2*Ht + R
|
||||
gemm(temp2, measurementMatrix, 1, measurementNoiseCov, 1, temp3, GEMM_2_T);
|
||||
gemm(temp2, measurementMatrix, 1, measurementNoiseCov, 1, temp3, GEMM_2_T);
|
||||
|
||||
// temp4 = inv(temp3)*temp2 = Kt(k)
|
||||
solve(temp3, temp2, temp4, DECOMP_SVD);
|
||||
|
||||
// K(k)
|
||||
gain = temp4.t();
|
||||
|
||||
|
||||
// temp5 = z(k) - H*x'(k)
|
||||
temp5 = measurement - measurementMatrix*statePre;
|
||||
|
||||
@@ -295,7 +295,7 @@ const Mat& KalmanFilter::correct(const Mat& measurement)
|
||||
|
||||
return statePost;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -73,13 +73,13 @@ cvUpdateMotionHistory( const void* silhouette, void* mhimg,
|
||||
#if CV_SSE2
|
||||
volatile bool useSIMD = cv::checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
|
||||
for( y = 0; y < size.height; y++ )
|
||||
{
|
||||
const uchar* silhData = silh->data.ptr + silh->step*y;
|
||||
float* mhiData = (float*)(mhi->data.ptr + mhi->step*y);
|
||||
x = 0;
|
||||
|
||||
|
||||
#if CV_SSE2
|
||||
if( useSIMD )
|
||||
{
|
||||
@@ -91,22 +91,22 @@ cvUpdateMotionHistory( const void* silhouette, void* mhimg,
|
||||
__m128 s0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(s, z)), s1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(s, z));
|
||||
__m128 v0 = _mm_loadu_ps(mhiData + x), v1 = _mm_loadu_ps(mhiData + x + 4);
|
||||
__m128 fz = _mm_setzero_ps();
|
||||
|
||||
|
||||
v0 = _mm_and_ps(v0, _mm_cmpge_ps(v0, db4));
|
||||
v1 = _mm_and_ps(v1, _mm_cmpge_ps(v1, db4));
|
||||
|
||||
__m128 m0 = _mm_and_ps(_mm_xor_ps(v0, ts4), _mm_cmpneq_ps(s0, fz));
|
||||
__m128 m1 = _mm_and_ps(_mm_xor_ps(v1, ts4), _mm_cmpneq_ps(s1, fz));
|
||||
|
||||
|
||||
v0 = _mm_xor_ps(v0, m0);
|
||||
v1 = _mm_xor_ps(v1, m1);
|
||||
|
||||
|
||||
_mm_storeu_ps(mhiData + x, v0);
|
||||
_mm_storeu_ps(mhiData + x + 4, v1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for( ; x < size.width; x++ )
|
||||
{
|
||||
float val = mhiData[x];
|
||||
@@ -209,7 +209,7 @@ cvCalcMotionGradient( const CvArr* mhiimg, CvArr* maskimg,
|
||||
dY_max_row.data.ptr = dY_max->data.ptr + y*dY_max->step;
|
||||
mask_row.data.ptr = mask->data.ptr + y*mask->step;
|
||||
orient_row.data.ptr = orient->data.ptr + y*orient->step;
|
||||
|
||||
|
||||
for( x = 0; x < size.width; x++ )
|
||||
{
|
||||
float d0 = dY_max_row.data.fl[x] - dX_min_row.data.fl[x];
|
||||
@@ -370,7 +370,7 @@ cvSegmentMotion( const CvArr* mhiimg, CvArr* segmask, CvMemStorage* storage,
|
||||
cvZero( mask );
|
||||
components = cvCreateSeq( CV_SEQ_KIND_GENERIC, sizeof(CvSeq),
|
||||
sizeof(CvConnectedComp), storage );
|
||||
|
||||
|
||||
v.f = (float)timestamp; ts = v.i;
|
||||
v.f = FLT_MAX*0.1f; stub_val = v.i;
|
||||
comp_idx.f = 1;
|
||||
@@ -478,9 +478,9 @@ void cv::segmentMotion(InputArray _mhi, OutputArray _segmask,
|
||||
Seq<CvConnectedComp> comps = cvSegmentMotion(&c_mhi, &c_segmask, storage, timestamp, segThresh);
|
||||
Seq<CvConnectedComp>::const_iterator it(comps);
|
||||
size_t i, ncomps = comps.size();
|
||||
boundingRects.resize(ncomps);
|
||||
boundingRects.resize(ncomps);
|
||||
for( i = 0; i < ncomps; i++, ++it)
|
||||
boundingRects[i] = (*it).rect;
|
||||
}
|
||||
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
static void removeOcclusions(const Mat& flow,
|
||||
static void removeOcclusions(const Mat& flow,
|
||||
const Mat& flow_inv,
|
||||
float occ_thr,
|
||||
Mat& confidence) {
|
||||
@@ -84,12 +84,12 @@ static void wd(Mat& d, int top_shift, int bottom_shift, int left_shift, int righ
|
||||
exp(d, d);
|
||||
}
|
||||
|
||||
static void wc(const Mat& image, Mat& d, int r0, int c0,
|
||||
static void wc(const Mat& image, Mat& d, int r0, int c0,
|
||||
int top_shift, int bottom_shift, int left_shift, int right_shift, float sigma) {
|
||||
const Vec3b centeral_point = image.at<Vec3b>(r0, c0);
|
||||
int left_border = c0-left_shift, right_border = c0+right_shift;
|
||||
for (int dr = r0-top_shift, r = 0; dr <= r0+bottom_shift; ++dr, ++r) {
|
||||
const Vec3b *row = image.ptr<Vec3b>(dr);
|
||||
const Vec3b *row = image.ptr<Vec3b>(dr);
|
||||
float *d_row = d.ptr<float>(r);
|
||||
for (int dc = left_border, c = 0; dc <= right_border; ++dc, ++c) {
|
||||
d_row[c] = -dist(centeral_point, row[dc]);
|
||||
@@ -99,11 +99,11 @@ static void wc(const Mat& image, Mat& d, int r0, int c0,
|
||||
exp(d, d);
|
||||
}
|
||||
|
||||
static void crossBilateralFilter(const Mat& image,
|
||||
const Mat& edge_image,
|
||||
const Mat confidence,
|
||||
Mat& dst, int d,
|
||||
float sigma_color, float sigma_space,
|
||||
static void crossBilateralFilter(const Mat& image,
|
||||
const Mat& edge_image,
|
||||
const Mat confidence,
|
||||
Mat& dst, int d,
|
||||
float sigma_color, float sigma_space,
|
||||
bool flag=false) {
|
||||
const int rows = image.rows;
|
||||
const int cols = image.cols;
|
||||
@@ -115,7 +115,7 @@ static void crossBilateralFilter(const Mat& image,
|
||||
wd(weights_space, d, d, d, d, sigma_space);
|
||||
Mat weights(2*d+1, 2*d+1, CV_32F);
|
||||
Mat weighted_sum(2*d+1, 2*d+1, CV_32F);
|
||||
|
||||
|
||||
vector<Mat> image_extended_channels;
|
||||
split(image_extended, image_extended_channels);
|
||||
|
||||
@@ -134,15 +134,15 @@ static void crossBilateralFilter(const Mat& image,
|
||||
multiply(weights, image_extended_channels[ch](window_rows, window_cols), weighted_sum);
|
||||
float total_sum = (float)sum(weighted_sum)[0];
|
||||
|
||||
dst.at<Vec2f>(row, col)[ch] = (flag && fabs(weights_sum) < 1e-9)
|
||||
? image.at<float>(row, col)
|
||||
dst.at<Vec2f>(row, col)[ch] = (flag && fabs(weights_sum) < 1e-9)
|
||||
? image.at<float>(row, col)
|
||||
: total_sum / weights_sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void calcConfidence(const Mat& prev,
|
||||
static void calcConfidence(const Mat& prev,
|
||||
const Mat& next,
|
||||
const Mat& flow,
|
||||
Mat& confidence,
|
||||
@@ -150,7 +150,7 @@ static void calcConfidence(const Mat& prev,
|
||||
const int rows = prev.rows;
|
||||
const int cols = prev.cols;
|
||||
confidence = Mat::zeros(rows, cols, CV_32F);
|
||||
|
||||
|
||||
for (int r0 = 0; r0 < rows; ++r0) {
|
||||
for (int c0 = 0; c0 < cols; ++c0) {
|
||||
Vec2f flow_at_point = flow.at<Vec2f>(r0, c0);
|
||||
@@ -195,14 +195,14 @@ static void calcOpticalFlowSingleScaleSF(const Mat& prev_extended,
|
||||
const Mat& next_extended,
|
||||
const Mat& mask,
|
||||
Mat& flow,
|
||||
int averaging_radius,
|
||||
int averaging_radius,
|
||||
int max_flow,
|
||||
float sigma_dist,
|
||||
float sigma_color) {
|
||||
const int averaging_radius_2 = averaging_radius << 1;
|
||||
const int rows = prev_extended.rows - averaging_radius_2;
|
||||
const int cols = prev_extended.cols - averaging_radius_2;
|
||||
|
||||
|
||||
Mat weight_window(averaging_radius_2 + 1, averaging_radius_2 + 1, CV_32F);
|
||||
Mat space_weight_window(averaging_radius_2 + 1, averaging_radius_2 + 1, CV_32F);
|
||||
|
||||
@@ -248,12 +248,12 @@ static void calcOpticalFlowSingleScaleSF(const Mat& prev_extended,
|
||||
const Vec3b *next_extended_window_row = next_extended.ptr<Vec3b>(next_extended_top_window_row + r);
|
||||
const float* weight_window_row = weight_window.ptr<float>(r);
|
||||
for (int c = 0; c <= averaging_radius_2; ++c) {
|
||||
cost += weight_window_row[c] *
|
||||
dist(prev_extended_window_row[prev_extended_left_window_col + c],
|
||||
cost += weight_window_row[c] *
|
||||
dist(prev_extended_window_row[prev_extended_left_window_col + c],
|
||||
next_extended_window_row[next_extended_left_window_col + c]);
|
||||
}
|
||||
}
|
||||
// cost should be divided by sum(weight_window), but because
|
||||
// cost should be divided by sum(weight_window), but because
|
||||
// we interested only in min(cost) and sum(weight_window) is constant
|
||||
// for every point - we remove it
|
||||
|
||||
@@ -269,7 +269,7 @@ static void calcOpticalFlowSingleScaleSF(const Mat& prev_extended,
|
||||
}
|
||||
}
|
||||
|
||||
static Mat upscaleOpticalFlow(int new_rows,
|
||||
static Mat upscaleOpticalFlow(int new_rows,
|
||||
int new_cols,
|
||||
const Mat& image,
|
||||
const Mat& confidence,
|
||||
@@ -307,7 +307,7 @@ static Mat calcIrregularityMat(const Mat& flow, int radius) {
|
||||
return irregularity;
|
||||
}
|
||||
|
||||
static void selectPointsToRecalcFlow(const Mat& flow,
|
||||
static void selectPointsToRecalcFlow(const Mat& flow,
|
||||
int irregularity_metric_radius,
|
||||
float speed_up_thr,
|
||||
int curr_rows,
|
||||
@@ -327,7 +327,7 @@ static void selectPointsToRecalcFlow(const Mat& flow,
|
||||
for (int r = 0; r < is_flow_regular.rows; ++r) {
|
||||
for (int c = 0; c < is_flow_regular.cols; ++c) {
|
||||
if (!done.at<uchar>(r, c)) {
|
||||
if (is_flow_regular.at<uchar>(r, c) &&
|
||||
if (is_flow_regular.at<uchar>(r, c) &&
|
||||
2*r + 1 < curr_rows && 2*c + 1< curr_cols) {
|
||||
|
||||
bool all_flow_in_region_regular = true;
|
||||
@@ -352,7 +352,7 @@ static void selectPointsToRecalcFlow(const Mat& flow,
|
||||
int curr_left = std::min(2 * c, curr_cols - 1);
|
||||
int curr_right = std::min(2*(c + step) + 1, curr_cols - 1);
|
||||
|
||||
if (all_flow_in_region_regular &&
|
||||
if (all_flow_in_region_regular &&
|
||||
curr_top != curr_bottom &&
|
||||
curr_left != curr_right) {
|
||||
mask.at<uchar>(curr_top, curr_left) = MASK_TRUE_VALUE;
|
||||
@@ -361,7 +361,7 @@ static void selectPointsToRecalcFlow(const Mat& flow,
|
||||
mask.at<uchar>(curr_bottom, curr_right) = MASK_TRUE_VALUE;
|
||||
for (int rr = curr_top; rr <= curr_bottom; ++rr) {
|
||||
for (int cc = curr_left; cc <= curr_right; ++cc) {
|
||||
speed_up.at<uchar>(rr, cc) = (uchar)(speed_up_at_this_point + 1);
|
||||
speed_up.at<uchar>(rr, cc) = (uchar)(speed_up_at_this_point + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -396,15 +396,15 @@ static inline float extrapolateValueInRect(int height, int width,
|
||||
if (r == 0 && c == width) { return v12;}
|
||||
if (r == height && c == 0) { return v21;}
|
||||
if (r == height && c == width) { return v22;}
|
||||
|
||||
|
||||
float qr = float(r) / height;
|
||||
float pr = 1.0f - qr;
|
||||
float qc = float(c) / width;
|
||||
float pc = 1.0f - qc;
|
||||
|
||||
return v11*pr*pc + v12*pr*qc + v21*qr*pc + v22*qc*qr;
|
||||
return v11*pr*pc + v12*pr*qc + v21*qr*pc + v22*qc*qr;
|
||||
}
|
||||
|
||||
|
||||
static void extrapolateFlow(Mat& flow,
|
||||
const Mat& speed_up) {
|
||||
const int rows = flow.rows;
|
||||
@@ -430,15 +430,15 @@ static void extrapolateFlow(Mat& flow,
|
||||
Vec2f bottom_left = flow.at<Vec2f>(bottom, left);
|
||||
Vec2f bottom_right = flow.at<Vec2f>(bottom, right);
|
||||
|
||||
flow_at_point[0] = extrapolateValueInRect(height, width,
|
||||
flow_at_point[0] = extrapolateValueInRect(height, width,
|
||||
top_left[0], top_right[0],
|
||||
bottom_left[0], bottom_right[0],
|
||||
rr-top, cc-left);
|
||||
rr-top, cc-left);
|
||||
|
||||
flow_at_point[1] = extrapolateValueInRect(height, width,
|
||||
flow_at_point[1] = extrapolateValueInRect(height, width,
|
||||
top_left[1], top_right[1],
|
||||
bottom_left[1], bottom_right[1],
|
||||
rr-top, cc-left);
|
||||
rr-top, cc-left);
|
||||
flow.at<Vec2f>(rr, cc) = flow_at_point;
|
||||
}
|
||||
}
|
||||
@@ -464,16 +464,16 @@ static void buildPyramidWithResizeMethod(Mat& src,
|
||||
}
|
||||
}
|
||||
|
||||
CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
Mat& to,
|
||||
CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
Mat& to,
|
||||
Mat& resulted_flow,
|
||||
int layers,
|
||||
int averaging_radius,
|
||||
int averaging_radius,
|
||||
int max_flow,
|
||||
double sigma_dist,
|
||||
double sigma_color,
|
||||
int postprocess_window,
|
||||
double sigma_dist_fix,
|
||||
int postprocess_window,
|
||||
double sigma_dist_fix,
|
||||
double sigma_color_fix,
|
||||
double occ_thr,
|
||||
int upscale_averaging_radius,
|
||||
@@ -494,10 +494,10 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
curr_from = pyr_from_images[layers - 1];
|
||||
curr_to = pyr_to_images[layers - 1];
|
||||
|
||||
copyMakeBorder(curr_from, curr_from_extended,
|
||||
copyMakeBorder(curr_from, curr_from_extended,
|
||||
averaging_radius, averaging_radius, averaging_radius, averaging_radius,
|
||||
BORDER_DEFAULT);
|
||||
copyMakeBorder(curr_to, curr_to_extended,
|
||||
copyMakeBorder(curr_to, curr_to_extended,
|
||||
averaging_radius, averaging_radius, averaging_radius, averaging_radius,
|
||||
BORDER_DEFAULT);
|
||||
|
||||
@@ -515,26 +515,26 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
curr_to_extended,
|
||||
mask,
|
||||
flow,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
(float)sigma_color);
|
||||
|
||||
calcOpticalFlowSingleScaleSF(curr_to_extended,
|
||||
curr_from_extended,
|
||||
mask_inv,
|
||||
flow_inv,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
(float)sigma_color);
|
||||
|
||||
removeOcclusions(flow,
|
||||
removeOcclusions(flow,
|
||||
flow_inv,
|
||||
(float)occ_thr,
|
||||
confidence);
|
||||
|
||||
removeOcclusions(flow_inv,
|
||||
removeOcclusions(flow_inv,
|
||||
flow,
|
||||
(float)occ_thr,
|
||||
confidence_inv);
|
||||
@@ -548,7 +548,7 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
prev_from = pyr_from_images[curr_layer + 1];
|
||||
prev_to = pyr_to_images[curr_layer + 1];
|
||||
|
||||
copyMakeBorder(curr_from, curr_from_extended,
|
||||
copyMakeBorder(curr_from, curr_from_extended,
|
||||
averaging_radius, averaging_radius, averaging_radius, averaging_radius,
|
||||
BORDER_DEFAULT);
|
||||
copyMakeBorder(curr_to, curr_to_extended,
|
||||
@@ -585,7 +585,7 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
curr_cols,
|
||||
prev_from,
|
||||
confidence,
|
||||
flow,
|
||||
flow,
|
||||
upscale_averaging_radius,
|
||||
(float)upscale_sigma_dist,
|
||||
(float)upscale_sigma_color);
|
||||
@@ -604,9 +604,9 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
curr_to_extended,
|
||||
mask,
|
||||
flow,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
(float)sigma_color);
|
||||
|
||||
calcConfidence(curr_to, curr_from, flow_inv, confidence_inv, max_flow);
|
||||
@@ -614,9 +614,9 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
curr_from_extended,
|
||||
mask_inv,
|
||||
flow_inv,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
averaging_radius,
|
||||
max_flow,
|
||||
(float)sigma_dist,
|
||||
(float)sigma_color);
|
||||
|
||||
extrapolateFlow(flow, speed_up);
|
||||
@@ -627,7 +627,7 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
removeOcclusions(flow_inv, flow, (float)occ_thr, confidence_inv);
|
||||
}
|
||||
|
||||
crossBilateralFilter(flow, curr_from, confidence, flow,
|
||||
crossBilateralFilter(flow, curr_from, confidence, flow,
|
||||
postprocess_window, (float)sigma_color_fix, (float)sigma_dist_fix);
|
||||
|
||||
GaussianBlur(flow, flow, Size(3, 3), 5);
|
||||
@@ -637,11 +637,11 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
mixChannels(&flow, 1, &resulted_flow, 1, from_to, 2);
|
||||
}
|
||||
|
||||
CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
|
||||
Mat& to,
|
||||
Mat& flow,
|
||||
int layers,
|
||||
int averaging_block_size,
|
||||
int averaging_block_size,
|
||||
int max_flow) {
|
||||
calcOpticalFlowSF(from, to, flow, layers, averaging_block_size, max_flow,
|
||||
4.1, 25.5, 18, 55.0, 25.5, 0.35, 18, 55.0, 25.5, 10);
|
||||
|
||||
Reference in New Issue
Block a user