1 | initial version |
both watershed and grabcut require an "initial guess" . so the process here is:
you mark an initial rectangle(from mouse, or e.g.boundingRect() from a contour), and call grabcut with GC_INIT_WITH_RECT . this will produce an initial mask, where anything inside the choosen rect is set to GC_FGD.
you refine the mask, by marking additional regions as possible fg or bg pixels in that mask. (that means, you have to access the mask's pixels. (which will be painful from java, promised !)
you call grabcut again, with GC_INIT_WITH_MASK, so it can sort out, which of your selected fg/bg pixels to apply
iterate 2. and 3. , until it looks ok.
it may be hard to find, but there are some questions about doing this from java on this site..
2 | No.2 Revision |
both watershed and grabcut require an "initial guess" . so the process here is:
you mark an initial rectangle(from mouse, or e.g.boundingRect() from a contour), and call grabcut with GC_INIT_WITH_RECT . this will produce an initial mask, where anything inside the choosen rect is set to GC_FGD.
you refine the mask, by marking additional regions as possible fg or bg pixels in that mask. (that means, you have to access the mask's pixels. (which will be painful from java, promised !)
you call grabcut again, with GC_INIT_WITH_MASK, so it can sort out, which of your selected fg/bg pixels to apply
iterate 2. and 3. , until it looks ok.ok. then : isolate all mask pixels with GC_FGD, and put them into a CV_8U Mat. this finally is the mask you can use for "matting" (NOT the grabcut mask)
it may be hard to find, but there are some questions about doing this from java on this site..