如何进行肤色匹配 [英] How to perform skin tone matching

查看:193
本文介绍了如何进行肤色匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面对http://oi44.tinypic.com/2s7771l.jpg (面对)

body http://oi40.tinypic。 com / 15wewpw.jpg (正文)

我是图像处理和openCV C / C ++的新手。我想知道是否有可能从第一张图片(脸部)中提取肤色。然后应用于第二个图像(正文)。

Hi, i am new to image processing and openCV C/C++. I am wondering that is it possible to extract skin tone from the first image (face). And then applied to the second image (body).

换句话说,用户上传他的脸部图像,程序从该图像中提取肤色并将其应用于身体。

In other words, user upload his face image and the program extract the skin tone from that image and apply it to the body.

谢谢,

Aisha

推荐答案

为了寻找皮肤,您可以使用以下公式之一:

For finding skin you can use one of this formulas:

1)使用正常的RGB空间:

1) With normilized RGB space:

for(int i = 0; i < m_image->height; ++i)
{
    for(int j = 0; j < m_image->width; ++j)
    {
        if (m_image->nChannels == 3)
        {
            int valueR = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3 + 2];
            int valueG = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3 + 1];
            int valueB = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3];

            float normR = static_cast<float>(valueR) / static_cast<float>(valueR + valueG + valueB);
            float normG = static_cast<float>(valueG) / static_cast<float>(valueR + valueG + valueB);
            float normB = static_cast<float>(valueB) / static_cast<float>(valueR + valueG + valueB);

            if ((normB / normG < 1.249) &&
                (( normR + normG + normB ) / ( 3 * normR ) > 0.696 ) &&
                ( 1/3.0 - normB/( normR + normG + normB ) > 0.014 ) &&
                (normG/(3* (normR + normG + normB)) < 0.108 ))
            {
              //pixel is skin
            }
        }
 }


$ b RGB空间中的$ b

2):

2) in RGB space:

for(size_t i = 0; i < m_image->height; ++i)
{
    for(size_t j = 0; j < m_image->width; ++j)
    {
        if (m_image->nChannels == 3)
        {
            int R = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3 + 2];
            int G = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3 + 1];
            int B = (reinterpret_cast<uchar*>(m_image->imageData + i * m_image->widthStep))[j * 3];

            if (( R > 95) && ( G > 40 ) && ( B > 20 ) &&
                (std::max(R, std::max( G, B) ) - std::min(R, std::min(G, B) ) > 15) &&
                (std::abs(R - G) > 15) && (R > G) && (R > B))
            {
                //skin pixel
            }

        }
    }

3)在YCrCb空间:

3) in YCrCb space:

for(size_t i = 0; i < m_image->height; ++i)
{
    for(size_t j = 0; j < m_image->width; ++j)
    {
        if (m_image->nChannels == 3)
        {
            int Cr = (reinterpret_cast<uchar*>(image->imageData + i * image->widthStep))[j * 3 + 2];
            int Cb = (reinterpret_cast<uchar*>(image->imageData + i * image->widthStep))[j * 3 + 1];
            int Y = (reinterpret_cast<uchar*>(image->imageData + i * image->widthStep))[j * 3];

            if (( Y > 80 ) && ( Cb > 85 ) && ( Cb < 135 ) &&
                (Cr > 135) && (Cr < 180))
            {
              //skin pixel
            }           
        }
    }
}

这篇关于如何进行肤色匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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