我是opencv的新手,我一直在用CIEXYZ做皮肤检测。但是我有问题要把RGB转换成CIE实验室来获得肤色区域,我做了一些基于this的RGB计算。
原始图像

其结果不是螺母黑框。从RGB到CIEXYZ

这是二值图像

但我想像这样展示

这是我的源代码:
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);我的代码有什么问题吗?提前感谢!
发布于 2017-04-26 16:22:41
你可以用一种简单得多的方式把手分开。
读取您的CIELAB图像,并将其分成三个不同的通道。分别分析每一条通道,看看哪一条是最好的。在那之后应用阈值。
以下代码在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)这是图像的绿色通道:

#---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----#

现在,您可以找到最大的轮廓,并单独分割手。
https://stackoverflow.com/questions/43638470
复制相似问题