Save opencv BackgroundSubtractorMOG to file?
Asked Answered
C

1

7

I use opencv for a vehicle counting process. How could I save my BackgroundSubtractorMOG object such as BackgroundSubtractorMOG2 etc to a file, so that I can read it from the file, use the trained background model again without training it for a long time?

Crest answered 9/12, 2014 at 1:54 Comment(0)
A
10

I happened to be searching for this exact thing, so I'll just share what I've learned, if someone else is still looking for it. It seems like the short answer is no. At least it does not seem to be supported by OpenCV.

BackgroundSubtractorMOG2 inherits from BackgroundSubtractor which inherits from Algorithm which has built in read/write functionality for storing parameters of the algorithms. According to the OpenCV doc on Algorithm::write it stores only the parameters for background model algorithms and not the background model itself. Quote from the link:

"However, the background model is not stored. First, it’s rather big. Then, if you have stored the background model, it would likely become irrelevant on the next run (because of shifted camera, changed background, different lighting etc.). Therefore, BackgroundSubtractorMOG and BackgroundSubtractorMOG2 also rely on the standard Algorithm::write() to store just the algorithm parameters."

As a side note I completely disagree with OpenCV, and I don't see why they feel the need to make this decision for me and not just allow me to save the background model if I see a purpose for it. Anyway, that's what I've found, if someone else knows how to store the background model or a workaround: please share.

Axinomancy answered 3/6, 2015 at 8:49 Comment(1)
Agree with you ... I found opencv don't support this feature after that.Crest

© 2022 - 2024 — McMap. All rights reserved.