肤色检测(Skin-Detection)

来源:互联网 发布:百万公众网络测试登录 编辑:程序博客网 时间:2024/04/27 23:39

为了满足图像处理的要求,博主写个一个简单的肤色检测算法代码,原理和方法见下面代码:

//Author: samylee//Contact email: ahuljx@126.com#include "stdlib.h"#include "stdio.h"#include "cv.h"#include "highgui.h"using namespace cv;void SkinRGB(Mat rgb){imshow("org", rgb);Size size;size.width = rgb.cols;size.height = rgb.rows;Mat dst = Mat::ones(size, CV_8UC3);for (int row = 0; row < size.height; row++){for (int col = 0; col < size.width; col++){int B = rgb.at<Vec3b>(row, col)[0];int G = rgb.at<Vec3b>(row, col)[1];int R = rgb.at<Vec3b>(row, col)[2];////principle////if ((R > 95 &&G > 40 &&B > 20 &&R - B > 15 &&R - G > 15)||(R > 200 &&G > 210 &&B > 170 &&abs(R - B) <= 15 &&R > B &&G > B)){dst.at<Vec3b>(row, col)[0] = B;dst.at<Vec3b>(row, col)[1] = G;dst.at<Vec3b>(row, col)[2] = R;}////principle////}}imshow("result", dst);cv::waitKey(0);}int main(){Mat img = imread("test2.jpg");SkinRGB(img);return 0;}


效果图如下

原始图:


处理图:


0 0
原创粉丝点击