Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void detectieVideoFace(){
- VideoCapture cap(0); // open the default camera
- if (!cap.isOpened()) // check if we succeeded
- return;
- String face_cascade_name = "haarcascade_frontalface_alt.xml";
- // Load the cascades
- if (!face_cascade.load(face_cascade_name))
- {
- printf("Error loading face cascades !\n");
- return;
- }
- Mat frame_gray;
- namedWindow("camera", 1);
- for (;;)
- {
- std::vector<Rect> faces;
- Mat frame;
- cap >> frame; // get a new frame from camera
- cvtColor(frame, frame_gray, CV_BGR2GRAY);
- //GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
- equalizeHist(frame_gray, frame_gray);
- int minFaceSize = 30;
- int minEyeSize = minFaceSize / 5;
- face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE,
- Size(minFaceSize, minFaceSize));
- for (int i = 0; i < faces.size(); i++)
- {
- // get the center of the face
- Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
- // draw circle around the face
- //ellipse(frame, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0,
- //360, Scalar(255, 0, 255), 4, 8, 0);
- Point stanga_sus(faces[i].x, faces[i].y);
- Point dreapta_jos(faces[i].x + faces[i].height, faces[i].y + faces[i].width);
- rectangle(frame, stanga_sus, dreapta_jos, Scalar(255, 0, 255), 1, 8, 0);
- }
- imshow("camera", frame);
- if (waitKey(30) >= 0) break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement