added dedicated <modname>_init.cpp files with initModule_<modname>() functions and all the relevant structures; made BackgroundSubtractorMOG/MOG2 derivatives from Algorithm; cleaned up MOG2 implementation and made it multi-threaded.

pull/13383/head
Vadim Pisarevsky 13 years ago
parent 3d108958e7
commit 5b6b30ba0e
  1. 44
      modules/contrib/src/contrib_init.cpp
  2. 9
      modules/core/include/opencv2/core/core.hpp
  3. 9
      modules/core/src/precomp.hpp
  4. 212
      modules/features2d/src/detectors.cpp
  5. 263
      modules/features2d/src/features2d_init.cpp
  6. 1
      modules/legacy/include/opencv2/legacy/legacy.hpp
  7. 84
      modules/legacy/src/bgfg_gaussmix.cpp
  8. 23
      modules/ml/src/em.cpp
  9. 80
      modules/ml/src/ml_init.cpp
  10. 118
      modules/nonfree/src/nonfree_init.cpp
  11. 7
      modules/nonfree/src/precomp.cpp
  12. 7
      modules/nonfree/src/sift.cpp
  13. 70
      modules/nonfree/src/surf.cpp
  14. 43
      modules/objdetect/src/objdetect_init.cpp
  15. 34
      modules/video/include/opencv2/video/background_segm.hpp
  16. 29
      modules/video/src/bgfg_gaussmix.cpp
  17. 1079
      modules/video/src/bgfg_gaussmix2.cpp
  18. 119
      modules/video/src/video_init.cpp
  19. 8
      samples/cpp/bgfg_segm.cpp

@ -0,0 +1,44 @@
/*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) 2009, 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*/
#include "precomp.hpp"

@ -2020,6 +2020,15 @@ public:
}; };
typedef void (*BinaryFunc)(const uchar* src1, size_t step1,
const uchar* src2, size_t step2,
uchar* dst, size_t step, Size sz,
void*);
CV_EXPORTS BinaryFunc getConvertFunc(int sdepth, int ddepth);
CV_EXPORTS BinaryFunc getConvertScaleFunc(int sdepth, int ddepth);
CV_EXPORTS BinaryFunc getCopyMaskFunc(size_t esz);
//! swaps two matrices //! swaps two matrices
CV_EXPORTS void swap(Mat& a, Mat& b); CV_EXPORTS void swap(Mat& a, Mat& b);

@ -176,15 +176,6 @@ struct NoVec
extern volatile bool USE_SSE2; extern volatile bool USE_SSE2;
typedef void (*BinaryFunc)(const uchar* src1, size_t step1,
const uchar* src2, size_t step2,
uchar* dst, size_t step, Size sz,
void*);
BinaryFunc getConvertFunc(int sdepth, int ddepth);
BinaryFunc getConvertScaleFunc(int sdepth, int ddepth);
BinaryFunc getCopyMaskFunc(size_t esz);
enum { BLOCK_SIZE = 1024 }; enum { BLOCK_SIZE = 1024 };
#ifdef HAVE_IPP #ifdef HAVE_IPP

@ -144,40 +144,6 @@ void GFTTDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, co
} }
} }
static Algorithm* createGFTT() { return new GFTTDetector; }
static Algorithm* createHarris()
{
GFTTDetector* d = new GFTTDetector;
d->set("useHarris", true);
return d;
}
static AlgorithmInfo gftt_info("Feature2D.GFTT", createGFTT);
static AlgorithmInfo harris_info("Feature2D.HARRIS", createHarris);
AlgorithmInfo* GFTTDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
GFTTDetector obj;
gftt_info.addParam(obj, "nfeatures", obj.nfeatures);
gftt_info.addParam(obj, "qualityLevel", obj.qualityLevel);
gftt_info.addParam(obj, "minDistance", obj.minDistance);
gftt_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
gftt_info.addParam(obj, "k", obj.k);
harris_info.addParam(obj, "nfeatures", obj.nfeatures);
harris_info.addParam(obj, "qualityLevel", obj.qualityLevel);
harris_info.addParam(obj, "minDistance", obj.minDistance);
harris_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
harris_info.addParam(obj, "k", obj.k);
initialized = true;
}
return &gftt_info;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* /*
@ -215,29 +181,6 @@ void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypo
KeyPointsFilter::runByPixelsMask( keypoints, mask ); KeyPointsFilter::runByPixelsMask( keypoints, mask );
} }
static Algorithm* createDense() { return new DenseFeatureDetector; }
static AlgorithmInfo dense_info("Feature2D.Dense", createDense);
AlgorithmInfo* DenseFeatureDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
DenseFeatureDetector obj;
dense_info.addParam(obj, "initFeatureScale", obj.initFeatureScale);
dense_info.addParam(obj, "featureScaleLevels", obj.featureScaleLevels);
dense_info.addParam(obj, "featureScaleMul", obj.featureScaleMul);
dense_info.addParam(obj, "initXyStep", obj.initXyStep);
dense_info.addParam(obj, "initImgBound", obj.initImgBound);
dense_info.addParam(obj, "varyXyStepWithScale", obj.varyXyStepWithScale);
dense_info.addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale);
initialized = true;
}
return &dense_info;
}
/* /*
* GridAdaptedFeatureDetector * GridAdaptedFeatureDetector
@ -359,161 +302,6 @@ void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, vector<KeyPoin
if( !mask.empty() ) if( !mask.empty() )
KeyPointsFilter::runByPixelsMask( keypoints, mask ); KeyPointsFilter::runByPixelsMask( keypoints, mask );
} }
/////////////////////// AlgorithmInfo for various detector & descriptors ////////////////////////////
/* NOTE!!!
All the AlgorithmInfo-related stuff should be in the same file as initModule_features2d().
Otherwise, linker may throw away some seemingly unused stuff.
*/
static Algorithm* createBRIEF() { return new BriefDescriptorExtractor; }
static AlgorithmInfo& brief_info()
{
static AlgorithmInfo brief_info_var("Feature2D.BRIEF", createBRIEF);
return brief_info_var;
}
static AlgorithmInfo& brief_info_auto = brief_info();
AlgorithmInfo* BriefDescriptorExtractor::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
BriefDescriptorExtractor brief;
brief_info().addParam(brief, "bytes", brief.bytes_);
initialized = true;
}
return &brief_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createFAST() { return new FastFeatureDetector; }
static AlgorithmInfo& fast_info()
{
static AlgorithmInfo fast_info_var("Feature2D.FAST", createFAST);
return fast_info_var;
}
static AlgorithmInfo& fast_info_auto = fast_info();
AlgorithmInfo* FastFeatureDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
FastFeatureDetector obj;
fast_info().addParam(obj, "threshold", obj.threshold);
fast_info().addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression);
initialized = true;
}
return &fast_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createStarDetector() { return new StarDetector; }
static AlgorithmInfo& star_info()
{
static AlgorithmInfo star_info_var("Feature2D.STAR", createStarDetector);
return star_info_var;
}
static AlgorithmInfo& star_info_auto = star_info();
AlgorithmInfo* StarDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
StarDetector obj;
star_info().addParam(obj, "maxSize", obj.maxSize);
star_info().addParam(obj, "responseThreshold", obj.responseThreshold);
star_info().addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected);
star_info().addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized);
star_info().addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize);
initialized = true;
}
return &star_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createMSER() { return new MSER; }
static AlgorithmInfo& mser_info()
{
static AlgorithmInfo mser_info_var("Feature2D.MSER", createMSER);
return mser_info_var;
}
static AlgorithmInfo& mser_info_auto = mser_info();
AlgorithmInfo* MSER::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
MSER obj;
mser_info().addParam(obj, "delta", obj.delta);
mser_info().addParam(obj, "minArea", obj.minArea);
mser_info().addParam(obj, "maxArea", obj.maxArea);
mser_info().addParam(obj, "maxVariation", obj.maxVariation);
mser_info().addParam(obj, "minDiversity", obj.minDiversity);
mser_info().addParam(obj, "maxEvolution", obj.maxEvolution);
mser_info().addParam(obj, "areaThreshold", obj.areaThreshold);
mser_info().addParam(obj, "minMargin", obj.minMargin);
mser_info().addParam(obj, "edgeBlurSize", obj.edgeBlurSize);
initialized = true;
}
return &mser_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createORB() { return new ORB; }
static AlgorithmInfo& orb_info()
{
static AlgorithmInfo orb_info_var("Feature2D.ORB", createORB);
return orb_info_var;
}
static AlgorithmInfo& orb_info_auto = orb_info();
AlgorithmInfo* ORB::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
ORB obj;
orb_info().addParam(obj, "nFeatures", obj.nfeatures);
orb_info().addParam(obj, "scaleFactor", obj.scaleFactor);
orb_info().addParam(obj, "nLevels", obj.nlevels);
orb_info().addParam(obj, "firstLevel", obj.firstLevel);
orb_info().addParam(obj, "edgeThreshold", obj.edgeThreshold);
orb_info().addParam(obj, "patchSize", obj.patchSize);
orb_info().addParam(obj, "WTA_K", obj.WTA_K);
orb_info().addParam(obj, "scoreType", obj.scoreType);
initialized = true;
}
return &orb_info();
}
bool initModule_features2d(void)
{
Ptr<Algorithm> brief = createBRIEF(), orb = createORB(),
star = createStarDetector(), fastd = createFAST(), mser = createMSER();
return brief->info() != 0 && orb->info() != 0 && star->info() != 0 &&
fastd->info() != 0 && mser->info() != 0;
}
} }

@ -0,0 +1,263 @@
/*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) 2009, 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*/
#include "precomp.hpp"
namespace cv
{
/////////////////////// AlgorithmInfo for various detector & descriptors ////////////////////////////
/* NOTE!!!
All the AlgorithmInfo-related stuff should be in the same file as initModule_features2d().
Otherwise, linker may throw away some seemingly unused stuff.
*/
static Algorithm* createBRIEF() { return new BriefDescriptorExtractor; }
static AlgorithmInfo& brief_info()
{
static AlgorithmInfo brief_info_var("Feature2D.BRIEF", createBRIEF);
return brief_info_var;
}
static AlgorithmInfo& brief_info_auto = brief_info();
AlgorithmInfo* BriefDescriptorExtractor::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
BriefDescriptorExtractor brief;
brief_info().addParam(brief, "bytes", brief.bytes_);
initialized = true;
}
return &brief_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createFAST() { return new FastFeatureDetector; }
static AlgorithmInfo& fast_info()
{
static AlgorithmInfo fast_info_var("Feature2D.FAST", createFAST);
return fast_info_var;
}
static AlgorithmInfo& fast_info_auto = fast_info();
AlgorithmInfo* FastFeatureDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
FastFeatureDetector obj;
fast_info().addParam(obj, "threshold", obj.threshold);
fast_info().addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression);
initialized = true;
}
return &fast_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createStarDetector() { return new StarDetector; }
static AlgorithmInfo& star_info()
{
static AlgorithmInfo star_info_var("Feature2D.STAR", createStarDetector);
return star_info_var;
}
static AlgorithmInfo& star_info_auto = star_info();
AlgorithmInfo* StarDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
StarDetector obj;
star_info().addParam(obj, "maxSize", obj.maxSize);
star_info().addParam(obj, "responseThreshold", obj.responseThreshold);
star_info().addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected);
star_info().addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized);
star_info().addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize);
initialized = true;
}
return &star_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createMSER() { return new MSER; }
static AlgorithmInfo& mser_info()
{
static AlgorithmInfo mser_info_var("Feature2D.MSER", createMSER);
return mser_info_var;
}
static AlgorithmInfo& mser_info_auto = mser_info();
AlgorithmInfo* MSER::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
MSER obj;
mser_info().addParam(obj, "delta", obj.delta);
mser_info().addParam(obj, "minArea", obj.minArea);
mser_info().addParam(obj, "maxArea", obj.maxArea);
mser_info().addParam(obj, "maxVariation", obj.maxVariation);
mser_info().addParam(obj, "minDiversity", obj.minDiversity);
mser_info().addParam(obj, "maxEvolution", obj.maxEvolution);
mser_info().addParam(obj, "areaThreshold", obj.areaThreshold);
mser_info().addParam(obj, "minMargin", obj.minMargin);
mser_info().addParam(obj, "edgeBlurSize", obj.edgeBlurSize);
initialized = true;
}
return &mser_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createORB() { return new ORB; }
static AlgorithmInfo& orb_info()
{
static AlgorithmInfo orb_info_var("Feature2D.ORB", createORB);
return orb_info_var;
}
static AlgorithmInfo& orb_info_auto = orb_info();
AlgorithmInfo* ORB::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
ORB obj;
orb_info().addParam(obj, "nFeatures", obj.nfeatures);
orb_info().addParam(obj, "scaleFactor", obj.scaleFactor);
orb_info().addParam(obj, "nLevels", obj.nlevels);
orb_info().addParam(obj, "firstLevel", obj.firstLevel);
orb_info().addParam(obj, "edgeThreshold", obj.edgeThreshold);
orb_info().addParam(obj, "patchSize", obj.patchSize);
orb_info().addParam(obj, "WTA_K", obj.WTA_K);
orb_info().addParam(obj, "scoreType", obj.scoreType);
initialized = true;
}
return &orb_info();
}
static Algorithm* createGFTT() { return new GFTTDetector; }
static Algorithm* createHarris()
{
GFTTDetector* d = new GFTTDetector;
d->set("useHarris", true);
return d;
}
static AlgorithmInfo gftt_info("Feature2D.GFTT", createGFTT);
static AlgorithmInfo harris_info("Feature2D.HARRIS", createHarris);
AlgorithmInfo* GFTTDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
GFTTDetector obj;
gftt_info.addParam(obj, "nfeatures", obj.nfeatures);
gftt_info.addParam(obj, "qualityLevel", obj.qualityLevel);
gftt_info.addParam(obj, "minDistance", obj.minDistance);
gftt_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
gftt_info.addParam(obj, "k", obj.k);
harris_info.addParam(obj, "nfeatures", obj.nfeatures);
harris_info.addParam(obj, "qualityLevel", obj.qualityLevel);
harris_info.addParam(obj, "minDistance", obj.minDistance);
harris_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
harris_info.addParam(obj, "k", obj.k);
initialized = true;
}
return &gftt_info;
}
static Algorithm* createDense() { return new DenseFeatureDetector; }
static AlgorithmInfo dense_info("Feature2D.Dense", createDense);
AlgorithmInfo* DenseFeatureDetector::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
DenseFeatureDetector obj;
dense_info.addParam(obj, "initFeatureScale", obj.initFeatureScale);
dense_info.addParam(obj, "featureScaleLevels", obj.featureScaleLevels);
dense_info.addParam(obj, "featureScaleMul", obj.featureScaleMul);
dense_info.addParam(obj, "initXyStep", obj.initXyStep);
dense_info.addParam(obj, "initImgBound", obj.initImgBound);
dense_info.addParam(obj, "varyXyStepWithScale", obj.varyXyStepWithScale);
dense_info.addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale);
initialized = true;
}
return &dense_info;
}
bool initModule_features2d(void)
{
Ptr<Algorithm> brief = createBRIEF(), orb = createORB(),
star = createStarDetector(), fastd = createFAST(), mser = createMSER(),
dense = createDense(), gftt = createGFTT(), harris = createHarris();
return brief->info() != 0 && orb->info() != 0 && star->info() != 0 &&
fastd->info() != 0 && mser->info() != 0 && dense->info() != 0 &&
gftt->info() != 0 && harris->info() != 0;
}
}

@ -3365,6 +3365,7 @@ typedef struct CvGaussBGModel
CvGaussBGStatModelParams params; CvGaussBGStatModelParams params;
CvGaussBGPoint* g_point; CvGaussBGPoint* g_point;
int countFrames; int countFrames;
void* mog;
} CvGaussBGModel; } CvGaussBGModel;

@ -50,10 +50,9 @@ icvReleaseGaussianBGModel( CvGaussBGModel** bg_model )
if( *bg_model ) if( *bg_model )
{ {
delete (cv::Mat*)((*bg_model)->g_point); delete (cv::BackgroundSubtractorMOG*)((*bg_model)->mog);
cvReleaseImage( &(*bg_model)->background ); cvReleaseImage( &(*bg_model)->background );
cvReleaseImage( &(*bg_model)->foreground ); cvReleaseImage( &(*bg_model)->foreground );
cvReleaseMemStorage(&(*bg_model)->storage);
memset( *bg_model, 0, sizeof(**bg_model) ); memset( *bg_model, 0, sizeof(**bg_model) );
delete *bg_model; delete *bg_model;
*bg_model = 0; *bg_model = 0;
@ -64,70 +63,15 @@ icvReleaseGaussianBGModel( CvGaussBGModel** bg_model )
static int CV_CDECL static int CV_CDECL
icvUpdateGaussianBGModel( IplImage* curr_frame, CvGaussBGModel* bg_model, double learningRate ) icvUpdateGaussianBGModel( IplImage* curr_frame, CvGaussBGModel* bg_model, double learningRate )
{ {
int region_count = 0;
cv::Mat image = cv::cvarrToMat(curr_frame), mask = cv::cvarrToMat(bg_model->foreground); cv::Mat image = cv::cvarrToMat(curr_frame), mask = cv::cvarrToMat(bg_model->foreground);
cv::BackgroundSubtractorMOG mog; cv::BackgroundSubtractorMOG* mog = (cv::BackgroundSubtractorMOG*)(bg_model->mog);
mog.bgmodel = *(cv::Mat*)bg_model->g_point; CV_Assert(mog != 0);
mog.frameSize = mog.bgmodel.data ? cv::Size(cvGetSize(curr_frame)) : cv::Size();
mog.frameType = image.type();
mog.nframes = bg_model->countFrames;
mog.history = bg_model->params.win_size;
mog.nmixtures = bg_model->params.n_gauss;
mog.varThreshold = bg_model->params.std_threshold*bg_model->params.std_threshold;
mog.backgroundRatio = bg_model->params.bg_threshold;
mog(image, mask, learningRate);
bg_model->countFrames = mog.nframes;
if( ((cv::Mat*)bg_model->g_point)->data != mog.bgmodel.data )
*((cv::Mat*)bg_model->g_point) = mog.bgmodel;
//foreground filtering
//filter small regions
cvClearMemStorage(bg_model->storage);
//cvMorphologyEx( bg_model->foreground, bg_model->foreground, 0, 0, CV_MOP_OPEN, 1 );
//cvMorphologyEx( bg_model->foreground, bg_model->foreground, 0, 0, CV_MOP_CLOSE, 1 );
#if 0
CvSeq *first_seq = NULL, *prev_seq = NULL, *seq = NULL;
cvFindContours( bg_model->foreground, bg_model->storage, &first_seq, sizeof(CvContour), CV_RETR_LIST );
for( seq = first_seq; seq; seq = seq->h_next )
{
CvContour* cnt = (CvContour*)seq;
if( cnt->rect.width * cnt->rect.height < bg_model->params.minArea )
{
//delete small contour
prev_seq = seq->h_prev;
if( prev_seq )
{
prev_seq->h_next = seq->h_next;
if( seq->h_next ) seq->h_next->h_prev = prev_seq;
}
else
{
first_seq = seq->h_next;
if( seq->h_next ) seq->h_next->h_prev = NULL;
}
}
else
{
region_count++;
}
}
bg_model->foreground_regions = first_seq;
cvZero(bg_model->foreground);
cvDrawContours(bg_model->foreground, first_seq, CV_RGB(0, 0, 255), CV_RGB(0, 0, 255), 10, -1);
#endif
CvMat _mask = mask; (*mog)(image, mask, learningRate);
cvCopy(&_mask, bg_model->foreground); bg_model->countFrames++;
return region_count; return 0;
} }
CV_IMPL CvBGStatModel* CV_IMPL CvBGStatModel*
@ -161,15 +105,17 @@ cvCreateGaussianBGModel( IplImage* first_frame, CvGaussBGStatModelParams* parame
bg_model->params = params; bg_model->params = params;
//prepare storages cv::BackgroundSubtractorMOG* mog =
bg_model->g_point = (CvGaussBGPoint*)new cv::Mat(); new cv::BackgroundSubtractorMOG(params.win_size,
params.n_gauss,
params.bg_threshold,
params.variance_init);
bg_model->background = cvCreateImage(cvSize(first_frame->width, bg_model->mog = mog;
first_frame->height), IPL_DEPTH_8U, first_frame->nChannels);
bg_model->foreground = cvCreateImage(cvSize(first_frame->width,
first_frame->height), IPL_DEPTH_8U, 1);
bg_model->storage = cvCreateMemStorage(); CvSize sz = cvGetSize(first_frame);
bg_model->background = cvCreateImage(sz, IPL_DEPTH_8U, first_frame->nChannels);
bg_model->foreground = cvCreateImage(sz, IPL_DEPTH_8U, 1);
bg_model->countFrames = 0; bg_model->countFrames = 0;

@ -671,29 +671,6 @@ void EM::read(const FileNode& fn)
computeLogWeightDivDet(); computeLogWeightDivDet();
} }
static Algorithm* createEM()
{
return new EM;
}
static AlgorithmInfo em_info("StatModel.EM", createEM);
AlgorithmInfo* EM::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
EM obj;
em_info.addParam(obj, "nclusters", obj.nclusters, true);
em_info.addParam(obj, "covMatType", obj.covMatType, true);
em_info.addParam(obj, "weights", obj.weights, true);
em_info.addParam(obj, "means", obj.means, true);
em_info.addParam(obj, "covs", obj.covs, true);
initialized = true;
}
return &em_info;
}
} // namespace cv } // namespace cv
/* End of file. */ /* End of file. */

@ -0,0 +1,80 @@
/*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) 2009, 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*/
#include "precomp.hpp"
namespace cv
{
static Algorithm* createEM()
{
return new EM;
}
static AlgorithmInfo em_info("StatModel.EM", createEM);
AlgorithmInfo* EM::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
EM obj;
em_info.addParam(obj, "nclusters", obj.nclusters);
em_info.addParam(obj, "covMatType", obj.covMatType);
em_info.addParam(obj, "maxIters", obj.maxIters);
em_info.addParam(obj, "epsilon", obj.epsilon);
em_info.addParam(obj, "weights", obj.weights, true);
em_info.addParam(obj, "means", obj.means, true);
em_info.addParam(obj, "covs", obj.covs, true);
initialized = true;
}
return &em_info;
}
bool initModule_ml(void)
{
Ptr<Algorithm> em = createEM();
return em->info() != 0;
}
}

@ -0,0 +1,118 @@
/*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) 2009, 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*/
#include "precomp.hpp"
namespace cv
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createSURF()
{
return new SURF;
}
static AlgorithmInfo& surf_info()
{
static AlgorithmInfo surf_info_var("Feature2D.SURF", createSURF);
return surf_info_var;
}
static AlgorithmInfo& surf_info_auto = surf_info();
AlgorithmInfo* SURF::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
SURF obj;
surf_info().addParam(obj, "hessianThreshold", obj.hessianThreshold);
surf_info().addParam(obj, "nOctaves", obj.nOctaves);
surf_info().addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
surf_info().addParam(obj, "extended", obj.extended);
surf_info().addParam(obj, "upright", obj.upright);
initialized = true;
}
return &surf_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createSIFT() { return new SIFT; }
static AlgorithmInfo& sift_info()
{
static AlgorithmInfo sift_info_var("Feature2D.SIFT", createSIFT);
return sift_info_var;
}
static AlgorithmInfo& sift_info_auto = sift_info();
AlgorithmInfo* SIFT::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
SIFT obj;
sift_info().addParam(obj, "nFeatures", obj.nfeatures);
sift_info().addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
sift_info().addParam(obj, "contrastThreshold", obj.contrastThreshold);
sift_info().addParam(obj, "edgeThreshold", obj.edgeThreshold);
sift_info().addParam(obj, "sigma", obj.sigma);
initialized = true;
}
return &sift_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
bool initModule_nonfree(void)
{
Ptr<Algorithm> sift = createSIFT(), surf = createSURF();
return sift->info() != 0 && surf->info() != 0;
}
}

@ -7,10 +7,11 @@
// copy or use the software. // copy or use the software.
// //
// //
// Intel License Agreement // License Agreement
// For Open Source Computer Vision Library // For Open Source Computer Vision Library
// //
// Copyright (C) 2000, Intel Corporation, all rights reserved. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners. // Third party copyrights are property of their respective owners.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
@ -23,7 +24,7 @@
// 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 Intel Corporation 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.
// //
// This software is provided by the copyright holders and contributors "as is" and // This software is provided by the copyright holders and contributors "as is" and

@ -7,10 +7,11 @@
// copy or use the software. // copy or use the software.
// //
// //
// Intel License Agreement // License Agreement
// For Open Source Computer Vision Library // For Open Source Computer Vision Library
// //
// Copyright (C) 2000, Intel Corporation, all rights reserved. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners. // Third party copyrights are property of their respective owners.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
@ -23,7 +24,7 @@
// 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 Intel Corporation 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.
// //
// This software is provided by the copyright holders and contributors "as is" and // This software is provided by the copyright holders and contributors "as is" and

@ -938,76 +938,6 @@ void SURF::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat&
void SURF::computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors) const void SURF::computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors) const
{ {
(*this)(image, Mat(), keypoints, descriptors, true); (*this)(image, Mat(), keypoints, descriptors, true);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createSURF()
{
return new SURF;
}
static AlgorithmInfo& surf_info()
{
static AlgorithmInfo surf_info_var("Feature2D.SURF", createSURF);
return surf_info_var;
}
static AlgorithmInfo& surf_info_auto = surf_info();
AlgorithmInfo* SURF::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
SURF obj;
surf_info().addParam(obj, "hessianThreshold", obj.hessianThreshold);
surf_info().addParam(obj, "nOctaves", obj.nOctaves);
surf_info().addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
surf_info().addParam(obj, "extended", obj.extended);
surf_info().addParam(obj, "upright", obj.upright);
initialized = true;
}
return &surf_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createSIFT() { return new SIFT; }
static AlgorithmInfo& sift_info()
{
static AlgorithmInfo sift_info_var("Feature2D.SIFT", createSIFT);
return sift_info_var;
}
static AlgorithmInfo& sift_info_auto = sift_info();
AlgorithmInfo* SIFT::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
SIFT obj;
sift_info().addParam(obj, "nFeatures", obj.nfeatures);
sift_info().addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
sift_info().addParam(obj, "contrastThreshold", obj.contrastThreshold);
sift_info().addParam(obj, "edgeThreshold", obj.edgeThreshold);
sift_info().addParam(obj, "sigma", obj.sigma);
initialized = true;
}
return &sift_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
bool initModule_nonfree(void)
{
Ptr<Algorithm> sift = createSIFT(), surf = createSURF();
return sift->info() != 0 && surf->info() != 0;
} }
} }

@ -0,0 +1,43 @@
/*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) 2009, 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*/
#include "precomp.hpp"

@ -54,7 +54,7 @@ namespace cv
The class is only used to define the common interface for The class is only used to define the common interface for
the whole family of background/foreground segmentation algorithms. the whole family of background/foreground segmentation algorithms.
*/ */
class CV_EXPORTS_W BackgroundSubtractor class CV_EXPORTS_W BackgroundSubtractor : public Algorithm
{ {
public: public:
//! the virtual destructor //! the virtual destructor
@ -93,6 +93,9 @@ public:
//! re-initiaization method //! re-initiaization method
virtual void initialize(Size frameSize, int frameType); virtual void initialize(Size frameSize, int frameType);
virtual AlgorithmInfo* info() const;
protected:
Size frameSize; Size frameSize;
int frameType; int frameType;
Mat bgmodel; Mat bgmodel;
@ -130,6 +133,9 @@ public:
//! re-initiaization method //! re-initiaization method
virtual void initialize(Size frameSize, int frameType); virtual void initialize(Size frameSize, int frameType);
virtual AlgorithmInfo* info() const;
protected:
Size frameSize; Size frameSize;
int frameType; int frameType;
Mat bgmodel; Mat bgmodel;
@ -137,24 +143,24 @@ public:
int nframes; int nframes;
int history; int history;
int nmixtures; int nmixtures;
//! here it is the maximum allowed number of mixture comonents. //! here it is the maximum allowed number of mixture components.
//! Actual number is determined dynamically per pixel //! Actual number is determined dynamically per pixel
float varThreshold; double varThreshold;
// threshold on the squared Mahalan. dist. to decide if it is well described // threshold on the squared Mahalanobis distance to decide if it is well described
//by the background model or not. Related to Cthr from the paper. // 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 // This does not influence the update of the background. A typical value could be 4 sigma
//and that is varThreshold=4*4=16; Corresponds to Tb in the paper. // and that is varThreshold=4*4=16; Corresponds to Tb in the paper.
///////////////////////// /////////////////////////
//less important parameters - things you might change but be carefull // less important parameters - things you might change but be carefull
//////////////////////// ////////////////////////
float backgroundRatio; float backgroundRatio;
//corresponds to fTB=1-cf from the paper // corresponds to fTB=1-cf from the paper
//TB - threshold when the component becomes significant enough to be included into // TB - threshold when the component becomes significant enough to be included into
//the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0. // the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0.
//For alpha=0.001 it means that the mode should exist for approximately 105 frames before // For alpha=0.001 it means that the mode should exist for approximately 105 frames before
//it is considered foreground // it is considered foreground
//float noiseSigma; // float noiseSigma;
float varThresholdGen; float varThresholdGen;
//correspondts to Tg - threshold on the squared Mahalan. dist. to decide //correspondts to Tg - threshold on the squared Mahalan. dist. to decide
//when a sample is close to the existing components. If it is not close //when a sample is close to the existing components. If it is not close

@ -134,17 +134,19 @@ template<typename VT> struct MixData
}; };
static void process8uC1( BackgroundSubtractorMOG& obj, const Mat& image, Mat& fgmask, double learningRate ) static void process8uC1( const Mat& image, Mat& fgmask, double learningRate,
Mat& bgmodel, int nmixtures, double backgroundRatio,
double varThreshold, double noiseSigma )
{ {
int x, y, k, k1, rows = image.rows, cols = image.cols; int x, y, k, k1, rows = image.rows, cols = image.cols;
float alpha = (float)learningRate, T = (float)obj.backgroundRatio, vT = (float)obj.varThreshold; float alpha = (float)learningRate, T = (float)backgroundRatio, vT = (float)varThreshold;
int K = obj.nmixtures; int K = nmixtures;
MixData<float>* mptr = (MixData<float>*)obj.bgmodel.data; MixData<float>* mptr = (MixData<float>*)bgmodel.data;
const float w0 = (float)defaultInitialWeight; const float w0 = (float)defaultInitialWeight;
const float sk0 = (float)(w0/(defaultNoiseSigma*2)); const float sk0 = (float)(w0/(defaultNoiseSigma*2));
const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4); const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4);
const float minVar = (float)(obj.noiseSigma*obj.noiseSigma); const float minVar = (float)(noiseSigma*noiseSigma);
for( y = 0; y < rows; y++ ) for( y = 0; y < rows; y++ )
{ {
@ -259,17 +261,20 @@ static void process8uC1( BackgroundSubtractorMOG& obj, const Mat& image, Mat& fg
} }
} }
static void process8uC3( BackgroundSubtractorMOG& obj, const Mat& image, Mat& fgmask, double learningRate )
static void process8uC3( const Mat& image, Mat& fgmask, double learningRate,
Mat& bgmodel, int nmixtures, double backgroundRatio,
double varThreshold, double noiseSigma )
{ {
int x, y, k, k1, rows = image.rows, cols = image.cols; int x, y, k, k1, rows = image.rows, cols = image.cols;
float alpha = (float)learningRate, T = (float)obj.backgroundRatio, vT = (float)obj.varThreshold; float alpha = (float)learningRate, T = (float)backgroundRatio, vT = (float)varThreshold;
int K = obj.nmixtures; int K = nmixtures;
const float w0 = (float)defaultInitialWeight; const float w0 = (float)defaultInitialWeight;
const float sk0 = (float)(w0/(defaultNoiseSigma*2*sqrt(3.))); const float sk0 = (float)(w0/(defaultNoiseSigma*2*sqrt(3.)));
const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4); const float var0 = (float)(defaultNoiseSigma*defaultNoiseSigma*4);
const float minVar = (float)(obj.noiseSigma*obj.noiseSigma); const float minVar = (float)(noiseSigma*noiseSigma);
MixData<Vec3f>* mptr = (MixData<Vec3f>*)obj.bgmodel.data; MixData<Vec3f>* mptr = (MixData<Vec3f>*)bgmodel.data;
for( y = 0; y < rows; y++ ) for( y = 0; y < rows; y++ )
{ {
@ -403,9 +408,9 @@ void BackgroundSubtractorMOG::operator()(InputArray _image, OutputArray _fgmask,
CV_Assert(learningRate >= 0); CV_Assert(learningRate >= 0);
if( image.type() == CV_8UC1 ) if( image.type() == CV_8UC1 )
process8uC1( *this, image, fgmask, learningRate ); process8uC1( image, fgmask, learningRate, bgmodel, nmixtures, backgroundRatio, varThreshold, noiseSigma );
else if( image.type() == CV_8UC3 ) else if( image.type() == CV_8UC3 )
process8uC3( *this, image, fgmask, learningRate ); process8uC3( image, fgmask, learningRate, bgmodel, nmixtures, backgroundRatio, varThreshold, noiseSigma );
else else
CV_Error( CV_StsUnsupportedFormat, "Only 1- and 3-channel 8-bit images are supported in BackgroundSubtractorMOG" ); CV_Error( CV_StsUnsupportedFormat, "Only 1- and 3-channel 8-bit images are supported in BackgroundSubtractorMOG" );
} }

File diff suppressed because it is too large Load Diff

@ -0,0 +1,119 @@
/*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) 2009, 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*/
#include "precomp.hpp"
namespace cv
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createMOG()
{
return new BackgroundSubtractorMOG;
}
static AlgorithmInfo& mog_info()
{
static AlgorithmInfo mog_info_var("BackgroundSubtractor.MOG", createMOG);
return mog_info_var;
}
static AlgorithmInfo& mog_info_auto = mog_info();
AlgorithmInfo* BackgroundSubtractorMOG::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
BackgroundSubtractorMOG obj;
mog_info().addParam(obj, "history", obj.history);
mog_info().addParam(obj, "nmixtures", obj.nmixtures);
mog_info().addParam(obj, "backgroundRatio", obj.backgroundRatio);
mog_info().addParam(obj, "noiseSigma", obj.noiseSigma);
initialized = true;
}
return &mog_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
static Algorithm* createMOG2()
{
return new BackgroundSubtractorMOG2;
}
static AlgorithmInfo& mog2_info()
{
static AlgorithmInfo mog2_info_var("BackgroundSubtractor.MOG2", createMOG2);
return mog2_info_var;
}
static AlgorithmInfo& mog2_info_auto = mog2_info();
AlgorithmInfo* BackgroundSubtractorMOG2::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
BackgroundSubtractorMOG2 obj;
mog2_info().addParam(obj, "history", obj.history);
mog2_info().addParam(obj, "varThreshold", obj.varThreshold);
mog2_info().addParam(obj, "detectShadows", obj.bShadowDetection);
initialized = true;
}
return &mog2_info();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
bool initModule_video(void)
{
Ptr<Algorithm> mog = createMOG(), mog2 = createMOG2();
return mog->info() != 0 && mog2->info() != 0;
}
}

@ -1,4 +1,5 @@
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/background_segm.hpp" #include "opencv2/video/background_segm.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include <stdio.h> #include <stdio.h>
@ -17,7 +18,7 @@ void help()
const char* keys = const char* keys =
{ {
"{c |camera |false | use camera or not}" "{c |camera |true | use camera or not}"
"{fn|file_name|tree.avi | movie file }" "{fn|file_name|tree.avi | movie file }"
}; };
@ -49,7 +50,8 @@ int main(int argc, const char** argv)
namedWindow("foreground image", CV_WINDOW_NORMAL); namedWindow("foreground image", CV_WINDOW_NORMAL);
namedWindow("mean background image", CV_WINDOW_NORMAL); namedWindow("mean background image", CV_WINDOW_NORMAL);
BackgroundSubtractorMOG2 bg_model; BackgroundSubtractorMOG2 bg_model;//(100, 3, 0.3, 5);
Mat img, fgmask, fgimg; Mat img, fgmask, fgimg;
for(;;) for(;;)
@ -59,6 +61,8 @@ int main(int argc, const char** argv)
if( img.empty() ) if( img.empty() )
break; break;
//cvtColor(_img, img, COLOR_BGR2GRAY);
if( fgimg.empty() ) if( fgimg.empty() )
fgimg.create(img.size(), img.type()); fgimg.create(img.size(), img.type());

Loading…
Cancel
Save