java - 如何使用ciexyz/cielab检测肤色?

标签 java opencv image-processing

我是 opencv 的新手,我一直在使用 CIEXYZ 进行皮肤检测。但是我遇到了将 RGB 转换为 CIE Lab 以获得肤色区域的问题,我根据 this 从 RGB 进行了一些计算.

原始图片

enter image description here

结果就是没有什么黑框。从 RGB 到 CIEXYZ enter image description here

这是二值图像

enter image description here

但我想像这样显示它

enter image description here

这是我的源代码:

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);

我的代码有问题吗?提前致谢!

最佳答案

您可以用更简单的方式分割手。

按原样读取 CIELAB 图像并将其分成三个不同的 channel 。分别分析每个 channel ,看看哪个 channel 最能分割手部。之后应用阈值。

以下代码是Python代码,可以转换为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)

这是图像的绿色 channel :

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

现在您可以找到最大的轮廓并单独分割手部

关于java - 如何使用ciexyz/cielab检测肤色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43638470/

相关文章:

运行 cv2.Canny() 时 Emacs 中的 python opencv 错误

iphone - 如何在 IOS 5 上使用 Open CV 查找模式的出现?

java - 如果任何请求在 tomcat 线程池中创建更多线程怎么办

java - 为什么 RecyclerView onBindViewHolder 只调用一次?

c++ - 如何从 AVI 视频中提取帧

python - “good_new = p1[st==1]”在OpenCV中的Lucas-Kanade Optical Flow代码中意味着什么

java - 如何检查曲线是否相似

c++ - 图像中的物体检测

java - 使用 quartz 进行数据检索

Java 泛型 ECLIPSE 错误?