Quickly draw MSER region (in Java) [closed]

asked 2019-07-29 18:10:15 -0600

huckw gravatar image

updated 2019-07-30 09:05:06 -0600

I have several MSER regions detected and for each one I'd like to convert them into a binary mask. All the existing solutions say to just loop over every point in each MSER and set that pixel to 255. This indeed works....but it is very slow! Is there any better/faster solution?

In Python it is very easy and very fast...

regions, boxes = mser.detectRegions(img)
mask=np.zeros(img.shape)
for n,p in enumerate(regions):
    mask[p[:,1],p[:,0]]=n+1

But I'm needing a solution in Java.

mser.detectRegions(img,regions,boxesmat);
mask.setTo(new Scalar(0));
for ( int n = 0; n < regions.size(); n++){
    for ( int p = 0; p < regions.get(n).rows(); p++){
        int r = (int)regions.get(n).get(p,0)[1];
        int c = (int)regions.get(n).get(p,0)[0];
        mask.put(r,c,n+1);
    }
}
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-09-29 01:14:10.723346

Comments

please show us your java code, so far.

berak gravatar imageberak ( 2019-07-30 07:03:33 -0600 )edit
1

Sorry about that....I've edited my question to include the relevant snippet of Java code

huckw gravatar imagehuckw ( 2019-07-30 09:05:35 -0600 )edit

thanks a lot, much nicer.

what should the mask look like, in the end ?

does the current java / python code achieve that ?

you could e.g. get the hull around each region, and draw a polygon into the mask

berak gravatar imageberak ( 2019-07-30 11:55:16 -0600 )edit
1

Both the python and Java implementations work. The Python one is wicked fast, the Java one is painfully slow (even when I shrink the image to QVGA). In the end, the mask should look like a hand. So the convex hull method, while really fast, does not get me the individual fingers like I want/need.

huckw gravatar imagehuckw ( 2019-07-30 12:43:02 -0600 )edit

I've found another oddity in Java version of OpenCV MSER...the mindiversity parameter seems to have no effect. I would expect to see a a reduction in the number of regions found as I increase mindiversity. However I get absolutely zero change in the number of returned regions with drastically different mindiversity values (I tried values from 0.01 to 0.99 and saw no difference). The resulting regions I get back are often very similar to one another which is what mindiversity is supposed to control.

BTW....I still have not found a very fast way to draw the detected MSER regions in an image in Java :(

huckw gravatar imagehuckw ( 2019-08-20 12:26:36 -0600 )edit