HSV Skin Detection
//for skin tone detectionvoidSkindetect (iplimage* src, iplimage*DST) { //Create an image headeriplimage* HSV = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,3);//an intermediate variable used for the storage of images, which is used for dividing channels into HSV channels .iplimage* tmpH1 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1);//intermediate variables for the channel, intermediate variables for skin detectioniplimage* tmpS1 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* tmpH2 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* tmpS3 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* tmpH3 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* tmpS2 = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* H = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* S = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* V = cvcreateimage (cvgetsize (SRC), ipl_depth_8u,1); Iplimage* Src_tmp1 = cvcreateimage (cvgetsize (SRC),8,3); //Gaussian BlurCvsmooth (SRC, src_tmp1, Cv_gaussian,3,3);//Gaussian Blur//hue chroma, saturation saturation, value purityCvcvtcolor (SRC_TMP1, HSV, CV_BGR2HSV);//Color ConversionCvsplit (HSV, H, S, V,0);//divided into 3 channelscvinranges (H, Cvscalar (0.0,0.0,0,0), Cvscalar (20.0,0.0,0,0), tmpH1); Cvinranges (S, Cvscalar (75.0,0.0,0,0), Cvscalar (200.0,0.0,0,0), tmpS1); Cvand (tmpH1, tmpS1, tmpH1,0); //Red Hue with low saturation//Hue 0 to degree and SatCvinranges (H, Cvscalar (0.0,0.0,0,0), Cvscalar (13.0,0.0,0,0), tmpH2); Cvinranges (S, Cvscalar (20.0,0.0,0,0), Cvscalar (90.0,0.0,0,0), tmpS2); Cvand (tmpH2, tmpS2, tmpH2,0); //Red Hue to Pink with low saturation//Hue 340 to degree and SatCvinranges (H, Cvscalar (170.0,0.0,0,0), Cvscalar (180.0,0.0,0,0), tmpH3); Cvinranges (S, Cvscalar (15.0,0.0,0,0), Cvscalar ( -.,0.0,0,0), tmpS3); Cvand (TmpH3, TmpS3, TmpH3,0); //Combine the Hue and Sat detectionsCvor (TmpH3, tmpH2, TmpH2,0); Cvor (tmpH1, tmpH2, tmpH1,0); Cvcopy (tmpH1, DST); Cvreleaseimage (&HSV); Cvreleaseimage (&tmpH1); Cvreleaseimage (&tmpS1); Cvreleaseimage (&tmpH2); Cvreleaseimage (&tmpS2); Cvreleaseimage (&tmpH3); Cvreleaseimage (&tmpS3); Cvreleaseimage (&i); Cvreleaseimage (&S); Cvreleaseimage (&W); Cvreleaseimage (&src_tmp1);}intMainintargcChar*argv[]) { /*iplimage *src = Cvloadimage ("c:\\c_c++ Code\\photo and Video\\text009.jpg", Cv_load_image_color); Cvnamedwindow ("src", cv_window_autosize); Cvshowimage ("src", SRC); Cvnamedwindow ("Flip", cv_window_autosize); Iplimage *DSC = cvcreateimage (cvgetsize (SRC), src->depth, 1); Flip Skindetect with x-axis (SRC, DSC); Cvflip (SRC, DSC, 1); Cvshowimage ("Flip", DSC); Cvwaitkey (0); Cvdestroyallwindows (); Cvreleaseimage (&SRC); printf ("Hello world!\n"); */videocapture Video (0); Iplimage*SRC, *DST; Mat img,bigimg; Doublescalar =2; Video>>img; SRC= &(Iplimage (IMG)); DST= Cvcreateimage (cvgetsize (SRC),8,1); while(1) {Video>>img; SRC= &(Iplimage (IMG)); Skindetect (SRC, DST); IMG=Cvarrtomat (DST); //Corrosion and swellingErode (IMG, IMG, Mat ()); Erode (IMG, IMG, Mat ()); //Erode (IMG, IMG, Mat ());dilate (IMG, IMG, Mat ()); Dilate (IMG, IMG, Mat ()); Dilate (IMG, IMG, Mat ()); Dilate (IMG, IMG, Mat ()); Dilate (IMG, IMG, Mat ()); Resize (IMG, bigimg, Size (Img.cols*scalar, Img.rows*scalar),1,1,1); Imshow ("x", bigimg); if(Waitkey ( +) >0) Break; } waitkey (); return 0;}
OpenCV Skin Detection-HSV separation