哪个是HSV皮肤探测器openCV android的色彩空间?

时间:2015-09-08 03:07:11

标签: android opencv computer-vision hsv vision

我是计算机视觉的新手。 我根据this

在Android上制作皮肤检测器

但是我在选择色彩空间时遇到了问题。 http://www.pyimagesearch.com/2014/08/18/skin-detection-step-step-example-using-python-opencv/(Sr,我不能在没有10个声誉的情况下发布图片)

我在互联网和本网站上尝试了很多空间,但那些错误。
这是我的代码:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {    
    Mat hsv = new Mat();
    //H,S,V area
    Scalar lower = new Scalar(0, 0.28*255, 0);
    Scalar upper = new Scalar(25, 0.68*255, 255);
    //Skin detector HSV-based
    Imgproc.cvtColor(inputFrame.rgba(), hsv, Imgproc.COLOR_RGBA2RGB);
    Imgproc.cvtColor(hsv, hsv, Imgproc.COLOR_RGB2HSV_FULL);
    Mat result = new Mat(hsv.rows(), hsv.cols(), CvType.CV_8U);
    Core.inRange(hsv, lower, upper, result);
    // Perform and decrease noise
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(2, 2));
    Imgproc.erode(result, result, kernel);
    Imgproc.dilate(result, result, kernel);
    Imgproc.GaussianBlur(result, result, new Size(3,3), 0);
    // Output
    Imgproc.cvtColor(result, result, Imgproc.COLOR_GRAY2RGB);
    Imgproc.cvtColor(result, result, Imgproc.COLOR_RGB2RGBA);
    return result;
}

更新1: 我尝试通过面部检测示例来获取皮肤空间:

        for (int i = 0; i < facesArray.length; i++) {
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
                FACE_RECT_COLOR, 3);        
        Mat hsv = new Mat(inputFrame.rgba(), facesArray[i]);
        Imgproc.cvtColor(hsv, hsv, Imgproc.COLOR_RGB2HSV_FULL);
        List<Mat> hsv_channel = new ArrayList<Mat>();
        Core.split(hsv, hsv_channel);
        Log.w("Color: ", "H: " + hsv_channel.get(0) + "S: " + hsv_channel.get(1) + "V: " + hsv_channel.get(2));
    }

输出:
H:Mat [261 * 261 * CV_8UC1,isCont = true,isSubmat = false,nativeObj = 0xffffffffb8b15658,dataAddr = 0xffffffffb983d5f0]
S:Mat [261 * 261 * CV_8UC1,isCont = true,isSubmat = false,nativeObj = 0xffffffffb8b15698,dataAddr = 0xffffffffb984e030]
V:Mat [261 * 261 * CV_8UC1,isCont = true,isSubmat = false,nativeObj = 0xffffffffb8b156d8,dataAddr = 0xffffffffb985ea60]

如何将这些应用于我的代码?

1 个答案:

答案 0 :(得分:1)

那些HSV颜色范围应该可以用于皮肤检测。

我已将此图片用于测试: http://www.dance-classes.ca/photos/faces/faces_2004W_comp1.jpg enter image description here

https://fashionisrael.wordpress.com/2010/03/08/fashion-battle-royale-castro-vs-hm/

上找到

和这段代码(C ++简化为hsv转换和inRange测试:

int main()
{
    cv::Mat input = cv::imread("../inputData/faces2.jpg");

    cv::Mat hsv;
    cv::cvtColor(input,hsv,CV_BGR2HSV);

    double scaleSatLower = 0.28;
    double scaleSatUpper = 0.68;
    //double scaleSatLower = 0.18; // maybe better
    //double scaleSatLower = 0.08; // maybe too much
    //double scaleSatUpper = 0.78;
    cv::Scalar lower = cv::Scalar(0, scaleSatLower*255, 0);
    cv::Scalar upper = cv::Scalar(25, scaleSatUpper*255, 255);

    cv::Mat result;
    cv::inRange(hsv, lower, upper, result);
    cv::imshow("result", result);


    cv::imshow("input",input);
    cv::imwrite("../outputData/HSV_skin.png", result);
    cv::waitKey(0);
    return 0;
}

给我这个结果:

enter image description here

对于简单的皮肤检测仪来说,这是可以的。

您可以使用代码验证此测试图像的结果吗?