您当前的位置: 首页 >  opencv

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

OpenCV肤色检测

鱼儿-1226 发布时间:2020-07-22 10:16:21 ,浏览量:0

前三种方式转载:http://blog.csdn.net/onezeros/article/details/6342567

 

第一种:RGB color space

第二种:RG color space

第三种:Ycrcb之cr分量+otsu阈值化

第四种:YCrCb中133widthStep;    

  •         for (int w=0;wwidth;w++) {    
  •             if ((prgb[R]>95 && prgb[G]>40 && prgb[B]>20 &&    
  •                 prgb[R]-prgb[B]>15 && prgb[R]-prgb[G]>15/*&&  
  •                 !(prgb[R]>170&&prgb[G]>170&&prgb[B]>170)*/)||//uniform illumination      
  •                 (prgb[R]>200 && prgb[G]>210 && prgb[B]>170 &&    
  •                 abs(prgb[R]-prgb[B])prgb[B]&& prgb[G]>prgb[B])//lateral illumination     
  •                 ) {    
  •                     memcpy(pdst,prgb,3);    
  •             }               
  •             prgb+=3;    
  •             pdst+=3;    
  •         }    
  •     }    
  •     cvCopyImage(dst,_dst);    
  •     cvReleaseImage(&dst);    
  • }    
  • // skin detection in rg space     
  • void cvSkinRG(IplImage* rgb,IplImage* gray)    
  • {    
  •     assert(rgb->nChannels==3&&gray->nChannels==1);    
  •         
  •     const int R=2;    
  •     const int G=1;    
  •     const int B=0;    
  •     
  •     double Aup=-1.8423;    
  •     double Bup=1.5294;    
  •     double Cup=0.0422;    
  •     double Adown=-0.7279;    
  •     double Bdown=0.6066;    
  •     double Cdown=0.1766;    
  •     for (int h=0;hheight;h++) {    
  •         unsigned char* pGray=(unsigned char*)gray->imageData+h*gray->widthStep;    
  •         unsigned char* pRGB=(unsigned char* )rgb->imageData+h*rgb->widthStep;    
  •         for (int w=0;wwidth;w++)     
  •         {    
  •             int s=pRGB[R]+pRGB[G]+pRGB[B];    
  •             double r=(double)pRGB[R]/s;    
  •             double g=(double)pRGB[G]/s;    
  •             double Gup=Aup*r*r+Bup*r+Cup;    
  •             double Gdown=Adown*r*r+Bdown*r+Cdown;    
  •             double Wr=(r-0.33)*(r-0.33)+(g-0.33)*(g-0.33);    
  •             if (gGdown && Wr>0.004)    
  •             {    
  •                 *pGray=255;    
  •             }    
  •             else    
  •             {     
  •                 *pGray=0;    
  •             }    
  •             pGray++;    
  •             pRGB+=3;    
  •         }    
  •     }    
  •     
  • }    
  • // implementation of otsu algorithm     
  • // author: onezeros#yahoo.cn     
  • // reference: Rafael C. Gonzalez. Digital Image Processing Using MATLAB     
  • void cvThresholdOtsu(IplImage* src, IplImage* dst)    
  • {    
  •     int height=src->height;    
  •     int width=src->width;    
  •     
  •     //histogram     
  •     float histogram[256]={0};    
  •     for(int i=0;iimageData+src->widthStep*i;    
  •         for(int j=0;jimageData+h*ycrcb->widthStep;    
  •         unsigned char* psrc=(unsigned char*)src->imageData+h*src->widthStep;    
  •         unsigned char* pdst=(unsigned char*)dst->imageData+h*dst->widthStep;    
  •         for (int w=0;wwidth;w++) {    
  •             if (pycrcb[Cr]>=133&&pycrcb[Cr]=77&&pycrcb[Cb]imageData+h*hsv->widthStep;    
  •         unsigned char* psrc=(unsigned char*)src->imageData+h*src->widthStep;    
  •         unsigned char* pdst=(unsigned char*)dst->imageData+h*dst->widthStep;    
  •         for (int w=0;wwidth;w++) {    
  •             if (phsv[H]>=7&&phsv[H]
  • 关注
    打赏
    1604459285
    查看更多评论
    立即登录/注册

    微信扫码登录

    0.0406s