从图像中获取脸部肤色 [英] get face skin tone color from image

查看:71
本文介绍了从图像中获取脸部肤色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码,这些代码使我返回参数中已传递的特定像素的颜色

i have tried below code that is returning me color of specific pixel which i have pass in argument

int x = (int)event.getX();
int y = (int)event.getY();
int pixel = bitmap.getPixel(x,y);


int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);   

int[] color={redValue ,blueValue ,greenValue };
btn.setBackgroundColor(getHexColor(color));


public static int getHexColor(int[] color) {
return android.graphics.Color.rgb(color[0], color[1], color[2]);
}  

我也尝试过调色板,以下链接是参考链接,该链接也未返回面部的完美肤色

i have also try color palette following link is reference link that is also not returning perfect skin tone color of face

这也是我也尝试过的

任何人都知道如何提取或获取面部肤色?

anyone have idea how to extract or get face skin tone color ??

推荐答案

使用此

Matrix inverse = new Matrix();
                    v.getMatrix().invert(inverse);
                    float[] touchPoint = new float[] {event.getX(), event.getY()};
                    inverse.mapPoints(touchPoint);
                    int xCoord = (int) touchPoint[0];
                    int yCoord = (int) touchPoint[1];
                    int intColor = ((BitmapDrawable)imageView.getDrawable()).getBitmap().getPixel(xCoord,yCoord);


btn.setBackgroundColor(intColor);

希望这会有所帮助

OR

只需在您的代码中更改此内容,请勿将颜色像素转换为十六进制。
直接在setBackGroundColor(pixel)
中使用彩色像素,例如

Simply Change this in you code, don't convert the color pixel to hex. Use the color pixel directly in setBackGroundColor(pixel) like

btn.setBackgroundColor(pixel);

这是我尝试过的完整代码

This is the full code i have tried

imageView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        if (event.getAction()==(MotionEvent.ACTION_DOWN)){

            Matrix inverse = new Matrix();
            v.getMatrix().invert(inverse);
            float[] touchPoint = new float[] {event.getX(), event.getY()};
            inverse.mapPoints(touchPoint);
            int xCoord = (int) touchPoint[0];
            int yCoord = (int) touchPoint[1];
            int intColor = ((BitmapDrawable)imageView.getDrawable()).getBitmap().getPixel(xCoord ,yCoord );


            try {
                btn.setBackgroundColor(intColor);
            }catch (Exception e){
                e.printStackTrace();
            }

            return false;
        }
        return false;
    }
});

尝试捕获不是必需的,但我只是为了预防任何计划外的错误而将其放置

Try catch is not necessary but i am putting it only for precaution for any unplanned error

这篇关于从图像中获取脸部肤色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆