我是计算机视觉的新手。
我在基于http://www.pyimagesearch.com/2014/08/18/skin-detection-step-step-example-using-python-opencv/的Android上制作了皮肤检测器

但是我在选择色彩空间时遇到问题。
http://imgur.com/DxNOXd9(高级,没有10个信誉我无法发布图片)

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

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]

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

最佳答案

那些HSV颜色范围应该适合皮肤检测。

我已使用此图像进行测试:
http://www.dance-classes.ca/photos/faces/faces_2004W_comp1.jpg
android - HSV皮肤检测器openCV android的色彩空间是哪个?-LMLPHP

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

给我这个结果:

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

对于简单的皮肤检测器来说,这没关系。

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

08-06 10:16