Step 1 of palm print recognition on Android: 6 skin color segmentation source code and Effect Diagram Based on opencv

Source: Internet
Author: User

The six methods are: Based on RGB segmentation, based on RG same channel segmentation, ycrcb + Otsu (Ostu can refer to the http://blog.csdn.net/onezeros/article/details/6136770,

Http://wenku.baidu.com/view/05c47e03bed5b9f3f90f1ce4.html), ycrcb space, YUV space, HSV space. The next step is to use JNI to port the detection to Android. The final goal is to enable the android smart phone to use the palm print to switch the host.

The environment is in QT, and the following code is added to the. Pro file:

INCLUDEPATH += /usr/include/opencvLIBS += /usr/lib/libcv.so \/usr/lib/libcvaux.so \/usr/lib/libcxcore.so \/usr/lib/libhighgui.so \/usr/lib/libml.so

Please refer to the source code:

#include <iostream>#include "cv.h"#include "highgui.h"void SkinRGB(IplImage* rgb,IplImage* _dst);void cvSkinRG(IplImage* rgb,IplImage* gray);void cvThresholdOtsu(IplImage* src, IplImage* dst);void cvSkinOtsu(IplImage* src, IplImage* dst);void cvSkinYCbCr(IplImage* img, IplImage* mask);void cvSkinYUV(IplImage* src,IplImage* dst);void cvSkinHSV(IplImage* src,IplImage* dst);using namespace std;// skin region location using rgb limitationint main(){    IplImage *srcImg = cvLoadImage("/home/yan/download/testPalm4.jpg", 1);    IplImage *dstRGB = cvCreateImage(cvGetSize(srcImg), 8, 3);    IplImage *dstRG = cvCreateImage(cvGetSize(srcImg), 8, 1);    IplImage* dst_crotsu=cvCreateImage(cvGetSize(srcImg),8,1);    IplImage* dst_ycbcr=cvCreateImage(cvGetSize(srcImg),8,1);    IplImage* dst_yuv=cvCreateImage(cvGetSize(srcImg),8,3);    IplImage* dst_hsv=cvCreateImage(cvGetSize(srcImg),8,3);    SkinRGB(srcImg, dstRGB);    cvSaveImage("/home/yan/download/1_dstRGB.jpg", dstRGB);    cvSkinRG(srcImg, dstRG);    cvSaveImage("/home/yan/download/2_dstRG.jpg", dstRG);    cvSkinOtsu(srcImg, dst_crotsu);    cvSaveImage("/home/yan/download/3_dst_crotsu.jpg", dst_crotsu);    cvSkinYCbCr(srcImg, dst_ycbcr);    cvSaveImage("/home/yan/download/4_dst_ycbcr.jpg", dst_ycbcr);    cvSkinYUV(srcImg, dst_yuv);    cvSaveImage("/home/yan/download/5_dst_yuv.jpg", dst_yuv);    cvSkinHSV(srcImg, dst_hsv);    cvSaveImage("/home/yan/download/6_dst_hsv.jpg", dst_hsv);    cvNamedWindow("srcImg", 1);    cvShowImage("srcImg", srcImg);    cvNamedWindow("dstRGB", 1);    cvShowImage("dstRGB", dstRGB);    cvNamedWindow("dstRG", 1);    cvShowImage("dstRG", dstRG);    cvNamedWindow("dstcrotsu", 1);    cvShowImage("dstcrotsu", dst_crotsu);    cvNamedWindow("dst_ycbcr", 1);    cvShowImage("dst_ycbcr", dst_ycbcr);    cvNamedWindow("dst_yuv", 1);    cvShowImage("dst_yuv", dst_yuv);    cvNamedWindow("dst_hsv", 1);    cvShowImage("dst_hsv", dst_hsv);    cvWaitKey(0);    cout << "Hello World!" << endl;    return 0;}void SkinRGB(IplImage* rgb,IplImage* _dst){    cout<<"111"<<endl;    assert(rgb->nChannels==3&& _dst->nChannels==3);    static const int R=2;    static const int G=1;    static const int B=0;    IplImage* dst=cvCreateImage(cvGetSize(_dst),8,3);    cvZero(dst);    for (int h=0;h<rgb->height;h++) {        unsigned char* prgb=(unsigned char*)rgb->imageData+h*rgb->widthStep;        unsigned char* pdst=(unsigned char*)dst->imageData+h*dst->widthStep;        for (int w=0;w<rgb->width;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])<=15 && prgb[R]>prgb[B]&& prgb[G]>prgb[B])//lateral illumination                    ) {                memcpy(pdst,prgb,3);            }            prgb+=3;            pdst+=3;        }    }    cvCopyImage(dst,_dst);    cvReleaseImage(&dst);}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; h<rgb->height; 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; w<rgb->width; 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 (g<Gup && g>Gdown && Wr>0.004)            {                *pGray=255;            }            else            {                *pGray=0;            }            pGray++;            pRGB+=3;        }    }}void cvThresholdOtsu(IplImage* src, IplImage* dst){    int height=src->height;    int width=src->width;    //histogram    float histogram[256]= {0};    for(int i=0; i

Below is:

Test image:

Maps correspond to the preceding six methods in sequence:

Ycrcb + Ostu is undoubtedly the best. The second is the RGB and YUV methods. The reason why this image works so well is that the background of the test image is white. Then, unfortunately, when the background color is not pure, such as red and black, the effect is not ideal. The experiment found that when the background is solid and it is white or black, the best effect is achieved.

Refer:

Http://blog.sina.com.cn/s/blog_9ce5a1b501017otq.html

Http://blog.csdn.net/scyscyao/article/details/5468577

Http://wenku.baidu.com/view/05c47e03bed5b9f3f90f1ce4.html

Http://blog.csdn.net/onezeros/article/details/6136770

-------------------------- The source palm print is prepared by the author. For more information, see yanzi1225627.

Related Article

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.