0

I am new in opencv, i've been doing something skin detection using CIEXYZ. But i got propblem to convert RGB to CIE Lab to get skin-colored area, I did some calculations from RGB based on this.

Original images

enter image description here

The result is nothing nut black frame. Its from RGB to CIEXYZ enter image description here

and this is binary image

enter image description here

but i want to display it like this

enter image description here

Here's my source code :

Mat img_color_space = new Mat();
Mat mask = new Mat();

Imgproc.cvtColor(src, img_color_space, colorBgr2hsv);
Imgcodecs.imwrite(path+"CIELAB/hsv.jpg",img_color_space);
Imgproc.blur(img_color_space, img_color_space, new Size(3,3));
Mat canny_output = new Mat();

Scalar minValues = new Scalar(0,10,60);
Scalar maxValues = new Scalar(20,150,255);
// show the current selected HSV range
String valuesToPrint = "Hue range: " + minValues.val[0] + "-" + maxValues.val[0]
        + "\tSaturation range: " + minValues.val[1] + "-" + maxValues.val[1] + "\tValue range: "
        + minValues.val[2] + "-" + maxValues.val[2];
//System.out.println("tresholding:"+valuesToPrint);

Core.inRange(img_color_space, minValues, maxValues, mask);
Imgcodecs.imwrite(path+"CIELAB/mask.jpg",mask);
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();

Imgproc.findContours(mask, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE,new Point(0,0));
int s = findBiggestContour(contours);

Mat drawing = Mat.zeros(mask.size(), CvType.CV_8UC3);
Imgproc.drawContours(drawing, contours, s, new Scalar(255, 255, 255), -1,8,hierarchy,0,new Point(0,0));
Imgproc.blur(drawing, drawing, new Size(3,3));
Imgcodecs.imwrite(path+"CIELAB/biggest.jpg",drawing);

Is there something wrong in my code? Thanks in advance!

Community
  • 1
  • 1
Febry Fairuz
  • 521
  • 1
  • 10
  • 27

1 Answers1

1

You can segment the hand in a much simpler way.

Read your CIELAB image as it is and split it into three different channels. Analyze each channel separately and see which one best segments the hand. After that apply threshold.

The following code is in python which can be converted to java:

import cv2

filename = 'hand.jpg'
img = cv2.imread(filename)
blue_channel, green_channel, red_channel = cv2.split(img)
cv2.imshow('green_channel', green_channel)

This is the green channel of the image:

enter image description here

#---I split the image in blue, green and red channels because the image I saved is in BGR format  ---#

#---I applied binary threshold to the green channel---#
ret, thresh = cv2.threshold(g, 152, 255, 1)
cv2.imshow('thresh', thresh)
#--- I got the following----#

enter image description here

Now you can find the biggest contour and segment the hand alone

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87