RGB 颜色空间肤色检测

RGB 颜色空间肤色检测主要依据在“human skin color clustering for face detection”一文中提出了肤色RGB的阈值判别算式。
void SkinRGB(Mat * src,Mat * mask)  //mask为单通道的与原图大小一致的黑色模板。
    {  
        //RGB颜色空间  
        //均匀照明:R>95,G>40,B>20,R-B>15,R-G>15  
        //侧向照明:R>200,G>210,B>170,R-B<=15,R>B,G>B  
        Mat srcImg;
        src->copyTo(srcImg);
        int rows = src->rows ;
        int cols = src->cols ;  
        int b=0,g=1,r=2;  

        for(int i=0;i<rows;i++)  
        {  
            for(int j=0;j  
            {  
                if((srcImg.at<Vec3b>(i,j)[2]>95 && srcImg.at<Vec3b>(i,j)[1]>40&&srcImg.at<Vec3b>(i,j)[1]>20&&  
                    (srcImg.at<Vec3b>(i,j)[2]-srcImg.at<Vec3b>(i,j)[0])>15 &&(srcImg.at<Vec3b>(i,j)[2]-srcImg.at<Vec3b>(i,j)[1])>15)
                    || (srcImg.at<Vec3b>(i,j)[2]>200 && srcImg.at<Vec3b>(i,j)[1]>210 && srcImg.at<Vec3b>(i,j)[0]>170 &&  
                    (srcImg.at<Vec3b>(i,j)[2]-srcImg.at<Vec3b>(i,j)[0])<=15 && srcImg.at<Vec3b>(i,j)[2]>srcImg.at<Vec3b>(i,j)[0]&&  
                    srcImg.at<Vec3b>(i,j)[1] > srcImg.at<Vec3b>(i,j)[0]))  
                    mask->at<uchar>(i, j)=255;  
            }  
        }  
        imshow("mask", *mask);
    } 

参考文献
https://blog.csdn.net/wj080211140/article/details/23384927

你可能感兴趣的:(【OpenCV】)