简体   繁体   中英

java openimaj OutOfMemoryError when using MSER algorithm for text detection

I want to do text detection in image using java. I am using OpenIMAJ to do that using MSER algorithm (as the first stage), but it takes a lot of processing time and in most images the exception OutOfMemoryError is returned.

I tried to change the parameters, and also change the algorithm source code, but the problem still there.

When I did MSER algorithm using Matlab it was fast and no OutOfMemoryError.

This is my code:

MSERFeatureGenerator mser = new MSERFeatureGenerator(delta,  maxArea, minArea, maxVariation, minDiversity, PixelsFeature.class);
List<Component> up_regions = mser.generateMSERs(flattenImg, MSERDirection.Up);

The error actually occurs when I call the following method:

List<MergeTreeBuilder> mergeTrees = mser.performWatershed(Transforms.calculateIntensityNTSC(img));

Example of image with no problem:

在此处输入图片说明

Example2 of image that make OutOfMemoryError:

在此处输入图片说明

please help.

OpenIMAJ implements the fast MSER algorithm defined by Nister and Stewinius (see http://link.springer.com/chapter/10.1007%2F978-3-540-88688-4_14 ). The OpenIMAJ implementation is very fast at finding the pivot pixels of each maximally stable region (you can see this by removing the reference to PixelsFeature.class from your code).

The reason you are getting OOMs and bad performance using PixelsFeature is that the underlying watershed algorithm is creating a connected component for every region for every one of 256 grey-levels (this happens before the maximally stable components are found, so is going to create a really massive tree structure with overlapping pixel sets at each level). This is not something you want to do...

I don't have any code to hand to demonstrate an alternative approach, but what you probably want to do is compute the pivot pixels and then work backwards to get the ConnectedComponents using a flood-fill like approach. If the MSER direction was Up , then starting at each pivot pixel do a flood fill in the image to find the connected component made up of all pixel values less than or equal to the pivot pixel value (note that the pivot pixels represent their grey-level as an integer; you'll need to divide by 255 to get it as a lot compatible with the input image).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM