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?
相关问题
- How to get the background from multiple images by
- Try to load image with Highgui.imread (OpenCV + An
- CV2 Image Error: error: (-215:Assertion failed) !s
- Is it a bug of opencv RotatedRect?
- How do I apply a perspective transform with more t
相关文章
- opencv fails to build with ipp support enabled
- Code completion is not working for OpenCV and Pyth
- Face unlock code in Android open source project?
- How to compile a c++ application using static open
- Why cv2.rectangle sometimes return np.ndarray, whi
- Fastest way to compute image dataset channel wise
- TypeError: unsupported operand type(s) for +: '
- Error installing OpenCV on Ubuntu 16.04
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.