Proper way to unload a loaded classifier? [closed]

asked 2014-09-02 20:10:36 -0500

Troup gravatar image

updated 2014-09-03 04:30:49 -0500

berak gravatar image

How do I unload a loaded classifier? I thought by name there may be something like "unload" since I call "load" to begin with, and I do see CascadeClassifier::empty();, but that just checks whether something was loaded (?).


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-07 05:56:32.393711


what do you mean with "stop" ?

berak gravatar imageberak ( 2014-09-03 00:49:54 -0500 )edit

For instance, if I'm running a classifier on live video and I want to stop the classifier from performing detectMultiScale by taking the xml document I called "load" on, and somehow unload it. I could create a conditional inside processImage to ignore detectMultiScale for whenever I choose, but I'm not comfortable with that solution. If I were to load another classifier, I'm not sure what would happen to the old one, and so I don't want to set myself up for uncertainty.

Thank you for your consideration, berak.

Troup gravatar imageTroup ( 2014-09-03 03:50:35 -0500 )edit

better use some programming logic, like a flag, to decide, whether to call detectMultiScale or not.

well, you can't make it 'forget' the old one, without making the whole thing invalid. (that's what you wanted?)

if you need another cascade, use a new CascadeClassifier instance.

berak gravatar imageberak ( 2014-09-03 03:55:01 -0500 )edit

Thanks for the quick replies - glad I didn't reply too soon before the edit. Yeah, I'd like to make it forget the old one, so I edited my question to better reflect that.

Troup gravatar imageTroup ( 2014-09-03 04:16:55 -0500 )edit

you can call release() on it, but then you're not allowed to call detectMultiScale (it will crash) unless you load another cascade file.

again, if you want to switch the detection on/off, this is not the way to do it.

berak gravatar imageberak ( 2014-09-03 04:36:29 -0500 )edit

I would use a combination of @berak his suggestions. Call the release on the object when you want to unload it, and at the same time set a boolean flag. Before adding detectmultiscale operator, check that flag, if it is set then NOT use it, if it is unset, then go ahead with processing.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-03 06:40:02 -0500 )edit

Hmm. My last question was about -nonsym being removed. Now I want the deprecated cvReleaseHaarClassifierCascade(&cascade). Maybe in a few years I'll catch up.

Troup gravatar imageTroup ( 2014-09-03 06:48:06 -0500 )edit

Well that is actually not what you were looking for. C depended on manual cleaning. However C++ has a garbage collector that destroys objects the moment they run out of scope. That is why the cvRelease functions were removed. Only time you actually should call release on an object is when you explicitly made one with the new operator.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-03 07:49:01 -0500 )edit