A case of skin tone detection-using the RGB color model

Source: Internet
Author: User

Code:

/*input: RGB image output: Grayscale image with the same size as the input image, if a pixel in the RGB image is detected as skin color, the corresponding pixel in the grayscale map is 255, otherwise 0*/voidSkinrgb (Mat &rgb,mat &DST) {Assert (Rgb.channels ()==3 ); Const intR =2; Const intG =1; Const intB =0; DST=Mat::zeros (Rgb.rows, Rgb.cols, cv_8u);  for(inti =0; i < rgb.rows; i++) {vec3b* ptr = rgb.ptr<vec3b>(i); Uchar* Ptr_mask = dst.ptr<uchar>(i);  for(intj =0; J < Rgb.cols; J + +) {vec3b pixel=Ptr[j]; if((Pixel[r) > the&& pixel[g]> +&& Pixel[b] > -&&Pixel[r]-Pixel[b]> the&& Pixel[r]-pixel[g]> the) ||(Pixel[r]> $&& pixel[g]> About&& pixel[b]> the&&ABS (PIXEL[R)-Pixel[b]) <= the&& Pixel[r]>pixel[b] && pixel[g]>Pixel[b])) {Ptr_mask[j]=255; }        }    }}

Effect:

A case of skin tone detection-using the RGB color model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.