A few days ago to hear a friend's needs say help people face p mosaic a bit cumbersome, so I want to use OPENCV to do a principle.
The core principle is very simple:
1. Human Face recognition
2. Gaussian Blur
Cascadeclassifier Cpufacecascade; Const stringPath =".. /data/haarcascade_frontalface_alt.xml"; if(!cpufacecascade.load (path)) {cout<<"could not find the Cascade"; return-1; } Mat img= Imread (".. /data/facetest.jpg", Imread_reduced_color_8); if(Img.empty ()) {cout<<"no photos ."; return 1; } Mat Imggray; Vector<Rect>faces; Cpufacecascade.detectmultiscale (IMG, Faces,1.1,1,5); Blur (IMG, imggray,size ( -, -), point (-1,-1),4); cout<<faces.size (); if(Faces.size () >0) { for(inti =0; I < faces.size (); i++) { if(Img.channels () = =3) { for(intK = faces[i].x; K < faces[i].x + faces[i].height; k++) { for(intJ = FACES[I].Y; J < faces[i].y+ faces[i].width; J + +) {img.at<Vec3b> (J, K) = imggray.at<vec3b>(J, K); } } } } } //get a picture of all the other black pictures on these reservationsNamedwindow ("a", window_autosize);//Create a windowImshow ("a", IMG); Waitkey (0); Destroyallwindows (); return 0;
Human face mosaic