Draw the detected face with an ellipse. Using the haarcascades that comes with OpenCV
#include "opencv2/core/core.hpp" #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" # Include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std;using namespace cv;string face_cascade_name = "D:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml" The file exists in \sources\data\haarcascades in the OPENCV installation directory and needs to be copied to the current project directory Cascadeclassifier face_cascade;void Detectanddisplay (Mat frame), int main (int argc, char** argv) {Mat image;image = Imread ("e:\\work\\ Libfacedetection-master\\11.jpg ", 1); In the current project image directory under the Mm.jpg file, note the directory symbol if (!face_cascade.load (face_cascade_name)) {printf ("cascading classifier error, file may not be found, copy the file to the project directory! \ n "); return-1;} Detectanddisplay (image); Call Face Detection function Waitkey (0);//Pause the display. }void Detectanddisplay (Mat face) {std::vector<rect> faces; Mat Face_gray;cvtcolor (Face, Face_gray, Cv_bgr2gray); The RGB type is converted to grayscale type equalizehist (Face_gray, Face_gray); Histogram equalization Face_cascade.detectmultiscale (Face_gray, Faces, 1.1, 2, 0 | Cv_haar_scale_image, Size (1, 1)); for (int i = 0; i < faces.size (); i++) {Point Center (faces[i].x + faces[i].width*0.5, F ACES[I].Y + faces[i].height*0.5) ellipse (face, center, Size (faces[i].width*0.5, faces[i].height*0.5), 0, 0, N, Scalar (255, 0, 0), 2, 7, 0);} Namedwindow ("Face Detection", cv_window_normal), imshow (face detection);
Ellipse
Draws an elliptical arc and an ellipse sector.
void Cvellipse (cvarr* img, cvpoint Center, cvsize axes, double angle, double start_angle, double end_angle, cvscalar color, int thickness=1, int line_type=8, int shift=0);
-
C + +: void ellipse(mat&img, pointCenter, Size axes, double Angle, doublestartangle, double endangle, const scalar&color, int Thickness=1, int linetype=8, intshift=0)
C + +: void ellipse(mat&img, const rotatedrect&box, const scalar& color, int thickness=1, intlinetype=8)
-
-
Img
-
-
image.
-
-
Center
-
The
-
Ellipse Center coordinate.
-
-
Axes
-
-
the length of the shaft.
-
-
Angle
-
-
angle of deflection.
-
-
Start_angle
-
-
angle of Arc start angle:
-
-
End_angle
-
-
angle of the arc end angle.
-
-
Color
-
-
the color of the line.
-
-
Thickness
-
-
the degree of thickness of the line.
-
-
Line_type
-
The
-
type of line, see Cvline description.
-
-
Shift
-
-
the precision of the center coordinate point and the axis.
To draw a detected face with an ellipse.