2017-04-26 6 views
0

opencvの新機能です。私は、CIEXYZを使って何かの肌検出を行ってきました。しかし、私は肌色の領域を得るためにRGBからCIE Labに変換するためのpropblemを得ました。私はthisに基づいてRGBからいくつかの計算を行いました。ciexyz/cielabを使用して肌の色を検出する方法は?

オリジナル画像

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

私のコードに何か問題がありますか?前もって感謝します!

答えて

1

もっと簡単な方法で手を分割することができます。

あなたのCIELAB画像をそのまま読んで、3つの異なるチャンネルに分割します。それぞれのチャンネルを別々に分析し、どれが手に最もよく見えるかを確認します。その後、しきい値を適用します。

次のコードは、Javaに変換することができるPythonである:

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

import cv2 

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

これは、画像の緑色チャネルであります今、あなたは最大の輪郭とsを見つけることができます手を離してください

+1

Thxあなたはとてもそうです。 U'r天才ブロンド.. –

+0

@FebryFairuzうれしい –

関連する問題