Opencv-Based Skin Detection

Source: Internet
Author: User

Modify the adaptiveskindetector. cpp of opencv and remove the complicated command line parameter input. You only need a Network Camera to run it.

In terms of principles, I roughly looked at the usage of the color information in the HSV space.

The effect is good, but it seems that the detection effect is poor for white walls, especially milky white walls and wall panels.

This is the first small item published here. update it every week with the source code (C ++, vs2008)

 

Skin Detection

 /************************************************************************/
/* adaptive skin detection
modified from opencv's adaptiveskindetector.cpp
opencv2.0 is required
welcome to visit my website: http://yangyangwenjia.appspot.com/
*/
/************************************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cvaux.h>
#include
int main(int argc, char** argv )
{
CvAdaptiveSkinDetector filter(1, CvAdaptiveSkinDetector::MORPHING_METHOD_ERODE_DILATE);

int camWidth = 640;
int camHeight = 480;

IplImage *maskImg = cvCreateImage( cvSize(camWidth, camHeight), IPL_DEPTH_8U, 1);
IplImage *skinImg = cvCreateImage( cvSize(camWidth, camHeight), IPL_DEPTH_8U, 3);

cvNamedWindow("skin", CV_WINDOW_AUTOSIZE);
cvNamedWindow("source", CV_WINDOW_AUTOSIZE);

CvCapture* capture = cvCaptureFromCAM( 0 );
IplImage* frame = 0;

for(;;)
{
cvZero(skinImg);

frame = cvQueryFrame( capture );
if( !frame )
break;

filter.process(frame, maskImg); // process the frame
cvCopy(frame,skinImg,maskImg);

cvShowImage ("skin", skinImg);
cvShowImage ("source", frame);
if (cvWaitKey(1) == 27)
break;

}

cvReleaseImage(&skinImg);
cvReleaseImage(&maskImg);
cvReleaseCapture( &capture );

cvDestroyWindow("skin");
cvDestroyWindow("source");

return 0;
}

 

 

Hope you find it useful ~

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.