Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

both watershed and grabcut require an "initial guess" . so the process here is:

  1. 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.

  2. 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 !)

  3. you call grabcut again, with GC_INIT_WITH_MASK, so it can sort out, which of your selected fg/bg pixels to apply

  4. 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..

both watershed and grabcut require an "initial guess" . so the process here is:

  1. 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.

  2. 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 !)

  3. you call grabcut again, with GC_INIT_WITH_MASK, so it can sort out, which of your selected fg/bg pixels to apply

  4. 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..