blobImage() method has memory leak
Found that calling blobImage() method has a slow memory leak. The more this method is called, the more memory is consumed. To reproduce the issue, open a python shell and create an image object called img which must contain blobs and run the code below. Use a system monitor to watch your memory usage and you will see that after a couple minutes of execution the memory usage is increasing on the python thread.
for i in range(1000000): blobs = img.invert().findBlobs() blobImg = blobs[-1].blobImage()
Tracked issue down to Blob.py -> cv.FillPoly(retVal,holes,(0,0,0),8) Fortunately this has already been corrected in cv2 library, need to use cv2.fillPoly(im, npHoles, 0) instead.
Instead of: cv.FillPoly(retVal,[[(p[0] - l, p[1] - t) for p in self.mContour]],(255,255,255),8) use: a3 = np.array( [[(p[0] - l, p[1] - t) for p in blob.mContour]], dtype=np.int32 ) im = np.zeros([blob.height(), blob.width()], dtype=np.uint8) cv2.fillPoly(im, a3, 255)
Instead of: return Image(retVal) use: return Image(cv.fromarray(im))