Save opencv BackgroundSubtractorMOG to file?

Deadly 提交于 2019-12-23 10:26:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27370222/save-opencv-backgroundsubtractormog-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!