I have successfully used OpenCVSharp, specifically the BackgroundSubtractorGMG, BackgroundSubtractorKNN, and BackgroundSubtractorMOG2, to perform background subtraction on images. However, when attempting to save the trained model, I have found that I can only save and load the parameters used to configure it!
Do you have any suggestions on how I can save the entire model with its learned state for future use? If there isn’t a direct way to achieve this, is it feasible to make modifications to the library to enable such functionality?
you cant save the state (or learned model)
(it’s not a csharp problem)
what is your actual use-case, which would require this ?
it’s meant to be used on continuous video streams to find moving objects (and assumes you have a few hundred frames to spare on startup to ‘train’ it.)
can it be, you’re looking for some more general object segmentation on single images ?
cv::algorithm has read(), write(), save() instance methods and load(), read() static methods
BackgroundSubtractor, being a subclass of cv::algorithm, should mean that further subclasses implement those… hopefully with sensible semantics.
Thanks for your response, Berak,
I aim to kick off the inference right from the get-go, skipping the training process every time the system starts. Consequently, I aim to store the most recent model state and start using it promptly upon startup.
As far as I am concerned, there is no direct way to do that. I want to know where can I modify the implementation or, maybe, add a new method for that functionality!
it’s not about you, there IS no way to do that builtin.
you’d have to dig into the resp. cpp source here
again, there are read/write methods, so it might even go without modifying interfaces