www.pudn.com > ColorSegment.rar > main.cpp


// 这个程序用HSV颜色空间来检测皮肤的颜色 
 
#include "cv.h" 
#include "highgui.h" 
 
#include "iplwrapper.h" 
#include "colorseg.h" 
#include "iostream.h" 
 
int th_h1 = 40; 
int th_h2 = 255; 
int th_s1 = 130; 
int th_s2 = 255; 
int th_v1 = 0; 
int th_v2 = 255; 
 
 
 
void main() 
{ 
	// Capture from Camera 
	CvCapture* capture =cvCaptureFromCAM(0); 
	if(capture == NULL) 
	{ 
		cout << "Can't open Cam!\n"; 
		return; 
	} 
 
	// Create windows to show images 
	cvNamedWindow("original",1); 
	cvNamedWindow("color segmentation",1); 
 
	// trackbars in the window to adjust variables 
	cvCreateTrackbar("track h1", "color segmentation", &th_h1, 255, NULL); 
	cvCreateTrackbar("track s1", "color segmentation", &th_s1, 255, NULL); 
 
	int key = 0; 
	IplImage* frame = NULL; // for original image 
	IplImage* dst = NULL; // for processed image 
 
	do // main loop to process frames 
	{ 
		frame = cvQueryFrame(capture); // get a frame image 
		cvShowImage("original",frame); // show the image 
 
		// do color segmentation 
		dst = colorSeg(frame, th_h1, th_h2, th_s1, th_s2, th_v1, th_v2); 
		cvShowImage("color segmentation", dst); 
		 
		key = cvWaitKey(10); // wait for 10 ms 
	} while (key != 27); //press "Esc" to exit 
}