0

I am doing final project about hand gesture recognition real time using android and opencv. I'm doing skin segmentation on it, by convert picture from camera frame (RGB) to YCrCb color and get the Cr and Cb value (range) from rectangle that is directed to skin color (seems like color picker). Now, i want to prove it (skin segmentation) by using thresholding function through option menu button on my android phone. But, it's not work, no effect. What should I do ? This is my threshold code :

    case MainActivity.VIEW_MODE_THRES:
    mask = rgba.clone();
    rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);

    Imgproc.cvtColor(rgbaInnerWindow, rgbaInnerWindow, Imgproc.COLOR_BGR2YCrCb);
    Imgproc.cvtColor(mask, mask, Imgproc.COLOR_BGR2GRAY);

    Core.inRange(rgbaInnerWindow, new Scalar(0, Cr_low, Cb_low), new Scalar (255, Cr_high, Cb_high), mask);

    image = mask.clone(); //save the image segmentation output
    Imgproc.blur(mask, mask, new Size(5,5));

    Imgproc.threshold(mask, mask, 13, 255, Imgproc.THRESH_OTSU);
    Core.inRange(mask, new Scalar(30), new Scalar(255), mask);
    rgbaInnerWindow.release();
    mask.release();
    break;
ichaka
  • 37
  • 3
  • You mean pushing the menu button has no effect, or the thresholding does not happen? – Gábor Bakos May 07 '15 at 08:43
  • @GáborBakos the thresholding didn't work. Could you help me? – ichaka May 07 '15 at 08:58
  • Show us the `mask` image before and after thresholding. – cyriel May 07 '15 at 12:07
  • the mask image is clone from rgba image (image input frame from camera), then i convert it to gray scale image. Is it right to do this? – ichaka May 08 '15 at 03:56
  • The mask is actually the destination for the output of the `inRange` function. It needs to be `CV_8U` and the same size as the input to `inRange( )`, i.e. the same size as `rgbaInnerWindow`. By using clone you are doing extra work (copying source data) and making `mask` bigger than the region you're performing `inRange` on. The fact that it's bigger than the source image may be a problem. Can't you just allocate `mask` as a new CV_8U matrix of appropriate size ? – Dave Durbin May 08 '15 at 05:03
  • @DaveDurbin thanks for your help, it's solved by using inRange function. – ichaka Jun 15 '15 at 06:16

1 Answers1

0

I think your treshold method isn't properly specified

Imgproc.threshold(mask, mask, 13, 255, Imgproc.THRESH_OTSU);

From docs

Also the special value THRESH_OTSU may be combined with one of the above values

I think you may need to try:

Imgproc.threshold(mask, mask, 13, 255, Imgproc.THRESH_OTSU | Imgproc.THRESH_BINARY);

For example

Dave Durbin
  • 3,562
  • 23
  • 33