首页 技术 正文
技术 2022年11月10日
0 收藏 402 点赞 2,387 浏览 4061 个字

最近一直在研究多脸谱识别以及如何分辨多个皮肤区域是否是人脸的问题

网上找了很多资料,看了很多篇文章,将其中基于RGB色彩空间识别皮肤

的统计算法做了一下总结,统计识别方法主要是简单相比与很多其它基于

机器学习的算法,本人总结了五种RGB色彩空间的统计算法源码如下:

Skin Filter1:

[java] view plaincopy

  1. public class SkinFilter1 extends AbstractBufferedImageOp {
  2. @Override
  3. public BufferedImage filter(BufferedImage src, BufferedImage dest) {
  4. int width = src.getWidth();
  5. int height = src.getHeight();
  6. if ( dest == null )
  7. dest = createCompatibleDestImage( src, null );
  8. int[] inPixels = new int[width*height];
  9. int[] outPixels = new int[width*height];
  10. getRGB( src, 0, 0, width, height, inPixels );
  11. int index = 0;
  12. for(int row=0; row<height; row++) {
  13. int ta = 0, tr = 0, tg = 0, tb = 0;
  14. for(int col=0; col<width; col++) {
  15. index = row * width + col;
  16. ta = (inPixels[index] >> 24) & 0xff;
  17. tr = (inPixels[index] >> 16) & 0xff;
  18. tg = (inPixels[index] >> 8) & 0xff;
  19. tb = inPixels[index] & 0xff;
  20. // detect skin method…
  21. double sum = tr + tg + tb;
  22. if (((double)tr/(double)tb > 1.185) &&
  23. ((double)(tr*tb)/(double)(sum*sum)>0.107) &&
  24. ((double)(tr*tg)/(double)(sum*sum)>0.112))
  25. {
  26. tr = tg = tb = 0; // black – skin detected!!
  27. } else {
  28. tr = tg = tb = 255; // white color means non-skin pixel
  29. }
  30. outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
  31. }
  32. }
  33. setRGB( dest, 0, 0, width, height, outPixels );
  34. return dest;
  35. }
  36. }

, 0, width, height, inPixels );

  • int index = 0;
  • for(int row=0; row<height; row++) {
  • int ta = 0, tr = 0, tg = 0, tb = 0;
  • for(int col=0; col<width; col++) {
  • index = row * width + col;
  • ta = (inPixels[index] >> 24) & 0xff;
  • tr = (inPixels[index] >> 16) & 0xff;
  • tg = (inPixels[index] >> 8) & 0xff;
  • tb = inPixels[index] & 0xff;
  • double sum = tr + tg + tb;
  • if(((double)3*tb*tr*tr/(double)(sum*sum*sum)>0.1276)&&
  • ((double)(tr*tb+tg*tg)/(double)(tg*tb)>2.14)&&
  • ((double)(sum)/(double)(3*tr)+(double)(tr-tg)/(double)(sum)<2.7775))
  • {
  • tr = tg = tb = 0;
  • } else {
  • tr = tg = tb = 255;
  • }
  • outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
  • }
  • }
  • setRGB( dest, 0, 0, width, height, outPixels );
  • return dest;
  • }
  • }
  • , 0, width, height, inPixels );

  • int index = 0;
  • for(int row=0; row<height; row++) {
  • int ta = 0, tr = 0, tg = 0, tb = 0;
  • for(int col=0; col<width; col++) {
  • index = row * width + col;
  • ta = (inPixels[index] >> 24) & 0xff;
  • tr = (inPixels[index] >> 16) & 0xff;
  • tg = (inPixels[index] >> 8) & 0xff;
  • tb = inPixels[index] & 0xff;
  • // detect skin method…
  • double sum = tr + tg + tb;
  • if (((double)tg / (double)tg – (double)tr / (double)tb <= -0.0905) &&
  • ((double)(sum) / (double)(3 * tr) + (double)(tr – tg) / (double)(sum) <= 0.9498))
  • {
  • tr = tg = tb = 0;
  • } else {
  • tr = tg = tb = 255;
  • }
  • outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
  • }
  • }
  • setRGB( dest, 0, 0, width, height, outPixels );
  • return dest;
  • }
  • }
  • , 0, width, height, inPixels );

  • int index = 0;
  • for(int row=0; row<height; row++) {
  • int ta = 0, tr = 0, tg = 0, tb = 0;
  • for(int col=0; col<width; col++) {
  • index = row * width + col;
  • ta = (inPixels[index] >> 24) & 0xff;
  • tr = (inPixels[index] >> 16) & 0xff;
  • tg = (inPixels[index] >> 8) & 0xff;
  • tb = inPixels[index] & 0xff;
  • // detect skin method…
  • double sum = tr + tg + tb;
  • if (((double)tb/(double)tg<1.249) &&
  • ((double)sum/(double)(3*tr)>0.696) &&
  • (0.3333-(double)tb/(double)sum>0.014) &&
  • ((double)tg/(double)(3*sum)<0.108))
  • {
  • tr = tg = tb = 0;
  • } else {
  • tr = tg = tb = 255;
  • }
  • outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
  • }
  • }
  • setRGB(dest, 0, 0, width, height, outPixels);
  • return dest;
  • }
  • }
  • , 0, width, height, inPixels );

  • int index = 0;
  • for(int row=0; row<height; row++) {
  • int ta = 0, tr = 0, tg = 0, tb = 0;
  • for(int col=0; col<width; col++) {
  • index = row * width + col;
  • ta = (inPixels[index] >> 24) & 0xff;
  • tr = (inPixels[index] >> 16) & 0xff;
  • tg = (inPixels[index] >> 8) & 0xff;
  • tb = inPixels[index] & 0xff;
  • // detect skin method…
  • double sum = tr + tg + tb;
  • if (((double)tg/(double)tb – (double)tr/(double)tg<=-0.0905)&&
  • ((double)(tg*sum)/(double)(tb*(tr-tg))>3.4857)&&
  • ((double)(sum*sum*sum)/(double)(3*tg*tr*tr)<=7.397)&&
  • ((double)sum/(double)(9*tr)-0.333 > -0.0976))
  • {
  • tr = tg = tb = 0;
  • } else {
  • tr = tg = tb = 255;
  • }
  • outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
  • }
  • }
  • setRGB( dest, 0, 0, width, height, outPixels );
  • return dest;
  • }
  • }
  • 总结一下:

    似乎Filter3的效果与Filter1的效果不是很好,Filter5, Filter4的效果感觉

    还是很好的,基本上可以符合实际要求。

    相关推荐
    python开发_常用的python模块及安装方法
    adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
    日期:2022-11-24 点赞:878 阅读:9,088
    Educational Codeforces Round 11 C. Hard Process 二分
    C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
    日期:2022-11-24 点赞:807 阅读:5,564
    下载Ubuntn 17.04 内核源代码
    zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
    日期:2022-11-24 点赞:569 阅读:6,413
    可用Active Desktop Calendar V7.86 注册码序列号
    可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
    日期:2022-11-24 点赞:733 阅读:6,186
    Android调用系统相机、自定义相机、处理大图片
    Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
    日期:2022-11-24 点赞:512 阅读:7,822
    Struts的使用
    一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
    日期:2022-11-24 点赞:671 阅读:4,905