Quickly draw MSER region (in Java) [closed]
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);
}
}
please show us your java code, so far.
Sorry about that....I've edited my question to include the relevant snippet of Java code
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
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.
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 :(