【问题标题】:How to Find out Average Skin color of face from Face Detection part in android?如何从android中的人脸检测部分找出人脸的平均肤色?
【发布时间】:2015-05-18 14:24:06
【问题描述】:

我需要从人脸检测部分获取平均肤色...如何找到平均肤色?

现在我通过 RGB 像素值得到平均肤色...仍然与源图像不匹配。我得到面部的平均颜色完全不同。

@Override
protected void onDraw(Canvas canvas) {
    int redBucket = 0;
    int greenBucket = 0;
    int blueBucket = 0;
    long pixelCount = 0;
    canvas.drawBitmap(myBitmap, 0, 0, null);

    Paint myPaint = new Paint();
    myPaint.setColor(Color.GREEN);
    myPaint.setStyle(Paint.Style.STROKE);
    myPaint.setStrokeWidth(3);

    for (int i = 0; i < numberOfFaceDetected; i++) {
        Face face = myFace[i];
        PointF myMidPoint = new PointF();
        face.getMidPoint(myMidPoint);
        myEyesDistance = face.eyesDistance(); 
        canvas.drawRect((int) (myMidPoint.x - myEyesDistance * 2),
        (int) (myMidPoint.y - myEyesDistance * 2),
        (int) (myMidPoint.x + myEyesDistance * 2),
        (int) (myMidPoint.y + myEyesDistance * 2), myPaint);

        resizedbitmap=Bitmap.createBitmap(myBitmap,(int) (myMidPoint.x - (myEyesDistance)*2),  
        (int) (myMidPoint.y - (myEyesDistance)*2),  
        (int) (myEyesDistance*4),  
        (int) (myEyesDistance*4));       

        for (int y = 0; y < resizedbitmap.getHeight(); y++) {
            for (int x = 0; x <resizedbitmap.getWidth();x++) {                         
                int pixel = resizedbitmap.getPixel(x,y);                
                pixelCount++;
                redBucket += Color.red(pixel);
                greenBucket += Color.green(pixel);
                blueBucket += Color.blue(pixel);              
            }
        }
        int red = (int) (redBucket/pixelCount);
        int green = (int) (greenBucket/pixelCount);
        int blue = (int) (blueBucket/pixelCount);
        View colorView = (View)findViewById(R.id.screen1);
        colorView.setBackgroundColor(Color.rgb(121,104,88));
    }     
}

现在我通过 RGB 像素值得到平均肤色...仍然与源图像不匹配。我得到面部的平均颜色完全不同。

平均 RGB 颜色应用到视图中并比较源图像面部和平均 RGB 颜色不同的颜色。请任何人帮助我。这对我很有帮助。 关于我的问题的任何想法... 谢谢,

【问题讨论】:

    标签: android android-layout android-intent android-activity


    【解决方案1】:

    您可以尝试使用Palette library,并可能使用鲜艳的颜色,或尝试不同的组合

    示例 sn-p:

    // Synchronous methods.
    // --------------------------------
    // These should be used when you have access to the underlying image loading     thread.
    // Picasso allows this through a Transformation. For other libraries, YMMV.
    
    // Uses the default palette size (16).
    Palette p = Palette.generate(bitmap);
    
    // Allows you to specify the maximum palette size, in this case 24.
    Palette p = Palette.generate(bitmap, 24);
    
    
    // Asynchronous methods
    // --------------------------------
    // This is the quick and easy integration path. Internally uses an AsyncTask so 
    // this may not be optimal (since you're dipping in and out of threads)
    
    // Uses the default palette size (16).
    Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {
           // Here's your generated palette
        }
    });
    
    // Allows you to specify the maximum palette size, in this case 24.
    Palette.generateAsync(bitmap, 24, new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {
           // Here's your generated palette
        }
    });
    

    当一个调色板生成时,它会尝试挑选六个符合特定条件的色板:

    Vibrant. Palette.getVibrantSwatch()
    Vibrant dark. Palette.getDarkVibrantSwatch()
    Vibrant light. Palette.getLightVibrantSwatch()
    Muted. Palette.getMutedSwatch()
    Muted dark. Palette.getDarkMutedSwatch()
    Muted light. Palette.getLightMutedSwatch()
    

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 2013-09-24
      • 2016-11-18
      • 2016-06-24
      • 1970-01-01
      • 2019-11-18
      • 2011-05-06
      • 2012-05-06
      相关资源
      最近更新 更多