基于opencv的皮肤检测

修改自opencv的adaptiveskindetector.cpp,去掉了复杂的命令行参数输入,只需要一个网络摄像头即可运行。

原理方面大致看了下,主要还是利用HSV空间的色调信息。

效果还可以,但似乎对于白色,尤其是乳白色的墙壁,壁板等检测效果较差。

这是在这里公布的第一个小东西,尽量一周更新一个,基本都会附带源代码(C++, VS2008)

 

皮肤检测
/************************************************************************/
/* 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
<highgui.h>

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~

posted @ 2010-05-14 16:00  yangyangcv  阅读(6589)  评论(6编辑  收藏  举报