Hi there,
I’m using the Foundation.CreateDynamicThesholdImage to pre-process an image before being passed through to the FBlob function.
Previously, I was doing simple thresholding all worked well. Since implementing Foundation.CreateDynamicThresholdImage, I see leaking memory issues. Removing the call removes the leak.
I’ve attached a simplified overview of the function that uses this method, below (hopefully the formatting will not go awry!);
if (Cvb.Image.IsImage((Cvb.Image.IMG)RawImage)) {
// 1. Create temporary Image to run through dynamic thresholding before passing to FBlob...
Image.IMG _imageForThresholding = new Image.IMG((Image.IMG)RawImage);
Foundation.CreateDynamicThresholdImage(_imageForThresholding, _maskSize, _threshold, out
Image.IMG _imageForBlobDetection);
Foundation.FBLOB blob = Foundation.FBlobCreate(_imageForBlobDetection, 0);
// 2. Look for blobs within a specific area (the ROI)...
Foundation.FBlobSetArea(blob, 0, ROI.Left, ROI.Top, ROI.Right, ROI.Bottom);
// 3. Look for black blobs on a white field, and with a specific black/white threshold...
Foundation.FBlobSetObjectFeature(blob, _threshold,
(int)Foundation.BlobFeatureType.FBLOB_BLACK_TO_FEATURE);
// 4. Run blob detection...
Foundation.FBlobExec(blob);
...doing something useful with the blobs found...
Image.ReleaseObj(blob);
}
This method is call continuously so that we can track objects within a live stream.
The garbage collector does not seem to handle the disposing of any resource associated with calls to CreateDynamicThresholdImage.
Is there a requirement for me to call something similar to the ReleaseObj used for the blob object? I can’t seem to find anything that does this job.
The key issue with both source codes is the life-time management of the Images/IMGs. With the new wrappers the Image can be properly garbage collected as it is a ‘proper’ .Net object, but you will run out of memory nevertheless if the calls to this method happen to frequently. Thus I managed the life-time of the temporaries via using.
In your source code you also need to release the _imageForBlobDetection temporary via Image.ReleaseObj(_imageForBlobDetection);. IMGs are essentially just IntPtrs which point to a native IImageVpa object. And for these you must manually call ReleaseObj as otherwise you leak memory.
Hi @parsd,
Many thanks for your (very) quick response and snippet. I’m currently using 13.01.000 so will update to the suggested version to look at your suggested approach.
You are welcome. The forum is the place where you get the most up-to-date information about . But I cannot promise that we are always able to answer that fast …
It’s a useful facility - and I don’t expect such a quick response all of the time
Just a FYI; it seems that the forum download facility does not like Chrome very much (repeatedly comes up with a ‘might be temporarily down or it may have moved permanently to a new web address.’ error). However, MS Edge works a treat…