Foreground Detector - how do I save/load an existing background model?

2 views (last 30 days)
Hi all, I am trying to come up with a way of saving and re-loading the Gaussian mixture model generated by the vision.ForegroundDetector. Basically I want to be able to:
  • Run the foreground detector
  • Train it on an empty scene to learn the background of the scene
  • SAVE this trained foreground detector so that I can use it in the future without re-training
  • LOAD this trained foreground detector and use it on new data.
Would anyone have any idea how this can be done? I have tried saving and loading a trained foreground detector instance to/from a .mat file, but all this does it copy the public properties, and does not appear to save the trained model. If I can't get this to work I will need to completely change my approach, this is literally the last step in what I am needing to do. Your help would be really, really appreciated.

Accepted Answer

Birju Patel
Birju Patel on 14 Oct 2014
You'll need to execute:
to enable the save/load to work correctly for vision.ForegroundDetector. You should use that command right before you call SAVE on the vision.ForegroundDetector object.
Also, you should save the “locked” object (i.e. do not call release prior to saving). You can execute the isLocked method on the vision.ForegroundDetector object to check if it's locked or not.
Hope that helps.
Birju Patel
Birju Patel on 16 Apr 2018
Hi Keir,
You don't need to enable the SystemObjectsFullSaveLoad feature any longer. Saving and loading the vision.ForegroundDetector should work without it.
The command errors out now because that feature keyword has been removed.

Sign in to comment.

More Answers (0)


Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!