Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:52:34+00:00 2026-06-12T22:52:34+00:00

OpenCV library version 2.42. I’d like to set a parameter in BackgroundSubtractorMOG2 object, e.g.

  • 0

OpenCV library version 2.42. I’d like to set a parameter in BackgroundSubtractorMOG2 object, e.g.

BackgroundSubtractorMOG2 bgr;  

// the following doesn't work because 'nmixtures', 'backgroundRatio' 
// and 'fVarMin' are a protected members.
bgr.nmixtures = 3;   
bgr.backgroundRatio = 0.9;
bgr.fVarMin = 5; 

// the following works 
bgr.set('nmixtures', 3); 

// both of the following lines will give a run-time error 
// `Access violation reading location 0x0000000000000008.`
bgr.set("backgroundRatio", 0.9);  
bgr.set("fVarMin", 5);     

backgroundRatio and fVarMin are parameters that control the algorithm. User should be able to change these parameters according to the documentation.

How can I set the parameters of BackgroundSubtractorMOG2?

EDIT As correctly mentioned in the answer below, this was a bug in OpenCV. The bug was fixed in OpenCV version 2.4.6.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:52:35+00:00Added an answer on June 12, 2026 at 10:52 pm

    I’ve just looked OpenCV source code and found interesting initialization in file /modules/video/src/video_init.cpp. Here it is:

    CV_INIT_ALGORITHM(BackgroundSubtractorMOG2, "BackgroundSubtractor.MOG2",
        obj.info()->addParam(obj, "history", obj.history);
        obj.info()->addParam(obj, "nmixtures", obj.nmixtures);
        obj.info()->addParam(obj, "varThreshold", obj.varThreshold);
        obj.info()->addParam(obj, "detectShadows", obj.bShadowDetection));
    

    It seems that it’s possible to set only these four parameters using method set.

    And also take a look at file modules/video/src/bgfg_gaussmix2.cpp, which has a BackgroundSubtractorMOG2 class. It has the following fields:

    float fVarInit;
    float fVarMax;
    float fVarMin;
    //initial standard deviation  for the newly generated components.
    //It will will influence the speed of adaptation. A good guess should be made.
    //A simple way is to estimate the typical standard deviation from the images.
    //I used here 10 as a reasonable value
    

    And the value fVarMin (which you want to change) is set to:

    fVarMin = defaultVarMin2
    

    in both constructors. Here are all of them:

    static const float defaultVarInit2 = 15.0f; // initial variance for new components
    static const float defaultVarMax2 = 5*defaultVarInit2;
    static const float defaultVarMin2 = 4.0f;
    

    And interesting fact that this value is not used in any other file, so it seems that it’s impossible to change it for now. You can post this issue directly to OpenCV bugtracker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using OpenCV library. It doesn't have a modulo operator that can be
I am working with OpenCV and I would like to put the entire library
I would like some help in continuing my code using openCV library in order
I'm trying to compile OpenCV version 2.3.1 on an Ubuntu 11.10 following instructions described
I would like to link against OpenCV library (debian squeeze package) in my Qt
I have just installed the OpenCV 2.2 library with VS 2010 following the willowgarage
I have a program that uses the OpenCV library (version 2.4.1) to capture video
I just started learning the opencv library for c++. In my previous c++ experience
I'm trying to discover opencv library at the moment, but it seems a bit
I am writing an algorithm using opencv library on an embedded processor (NIOS 2)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.