Make writing a habit together! This is my first day to participate in the “Gold Digging Day New Plan · April More text challenge”, click to see the details of the activity.

Introduction to the

Face detection is the primary link of face analysis, the problem of its processing is to confirm whether there is a face in the image, if there is face location. Face detection is widely used in many fields and is one of the important steps to realize machine intelligence. AdaBoost algorithm is a fast face detection algorithm proposed in 1995, which is a landmark progress in the field of face detection. According to the feedback of weak learning, this algorithm adaptively adjusts the error rate of hypothesis, so that the detection accuracy is greatly improved without reducing the efficiency. In this paper, the concepts and theories of Haar feature and integral graph, which are very important to the speed of AdaBoost face detection training algorithm, are carefully explained. At the same time, the algorithm of AdaBoost is given, and some key problems, such as the construction and selection of weak learner, are discussed deeply. In this paper, several strong classifiers trained by AdaBoost are connected together to form a cascade classifier with both high detection rate and low misrecognition rate — Haar classifier. Finally, face detection is realized by Haar classifier and the detection result is verified by detecting the five senses.

Calculation of Haar features

Assuming that the size of the image to be detected is W×H and the size of the rectangular feature is W×H, the horizontal and vertical scaling coefficients are as follows: X=W/ W,Y=H/ H number of initializing features count=0. For(m,n)=(1,2,, X)×(1,2,, Y) magnify rectangular features to mw×nh translate rectangular features mw×nh traverse every pixel of the image and calculate eigenvalues at each position. Forx=1, 2,… , W-mw+1

Fory = 1, 2,… , H-nh+1

Calculate the eigenvalues of each point

Count = count + 1

The end

The end

End In this way, we can easily and quickly calculate the number of different kinds of rectangular features on the image by using the above method.

Iii. Skillfully use ClassificationModel

3.1FrontalFaceCART(default) :

Training image size [20 20]; Detect upright and forward-facing faces. The model consists of weak classifiers based on classification and regression tree analysis (CART). These classifiers use haar features to encode facial features. Block-based classifiers provide the ability to model high-order dependencies between facial features.

3.2 FrontalFaceLBP:

Training image size [24 24]; Detect upright and forward-facing faces. The model consists of weak classifiers and is based on decision stumps. These classifiers encode facial features using native binary patterns (LBP). The LBP feature provides robustness against lighting changes.

3.3 UpperBody:

Training image size [18 22]: Detect the upper body region, which is defined as the head and shoulder region. This model encodes detailed information about the head and shoulder areas using the HaAR function. Because it uses more functions around the head, this model is more reliable for postural changes, such as head rotation.

3.4 EyePairBig ‘/’ EyePairSmall:

Training picture size: [11 45]/[5 22]; Test a pair of eyes. ‘EyePairSmall’ trains the ‘eye-like’ model. This allows the model to detect the smaller eyes that the ‘EyePairBig’ model can.

3.5 LeftEye ‘/’ RightEye:

Training picture size: [12 18]; The left and right eyes were examined separately. These models are made up of weak classifiers, based on decision stumps. These classifiers encode the details using the HaAR function

3.6 LeftEyeCART ‘/’ RightEyeCART:

Training picture size: [20 20]; The left and right eyes were examined separately. The weak classifier that makes up these models is the Cart-tree. Compared with the decision stump, the classifier based on CART tree can better model the high-order dependencies.

3.7 ProfileFace:

Training picture size: [20 20]; Detect upright face contours. The model consists of weak classifiers and is based on decision stumps. These classifiers encode face details using the HaAR function.

3.7 expressions using:

Training image size [15 25]; Check your mouth. The model consists of weak classifiers, which encode oral details using Haar features based on decision stumps.

3.8 the Nose:

Training image size [15 18]; The model consists of weak classifiers that encode nose details using Haar features based on decision stumps. \

4. Parameter adjustment

MinSize(minimum detectable object size): Minimum detectable object size, specified as two element vectors [height weight]. Set this property in pixels for the smallest size region that contains an object. This value must be greater than or equal to the image size used to train the model. When you know the minimum object size before processing the image, using this property can reduce computation time. If the value of this property is not specified, the detector sets it to the size of the image used to train the classification model.

MaxSize: The maximum size of a detectable object, specified as two element vectors [height weight]. Specifies the size, in pixels, of the largest object to detect. When you know the maximum object size before processing the image, using this property can reduce the computation time. If you do not specify a value for this property, the probe specifies it as size(IMG).

ScaleFactor(scaling for multi-scale object detection): Scaling for multi-scale object detection, specified as a value greater than 1.0001. The scale factor scales the detection resolution between MinSize and MaxSize by incremental MinSize. You can set the scale factor to the desired value using the following method: size(IMG)/(size(IMG)-0.5). The probe scales the search area increments between “MinSize” and MaxSize using the following relationship: Search area = round(training image size) * (ScaleFactor)^n))

MergeThreshold (detection threshold) : detection threshold. The value is an integer. A threshold defines the conditions required to declare a final detection in an area where there are multiple detections around an object. Merge co-detection groups that meet the threshold to generate a bounding box around the target object. Increasing this threshold may help suppress error detection by requiring multiple detections of the target object in the multiscale detection phase. Setting this property to 0 returns all detections without performing threshold or merge operations. This property is adjustable.

UseROI(Using areas of interest):Use the region of interest, specified as true or false. Setting this property to true detects objects within the rectangular region of interest in the input image.

Test sample

Code Appendix:

img=imread('F:\smile.png'); imshow(img); title('Original IMG'); detector = vision.CascadeObjectDetector; 1: FrontalFaceCART bboxes=step(detector,img); FrontalFaceCART=insertObjectAnnotation(img,'rectangle',bboxes,'Face'); figure(1); imshow(FrontalFaceCART); title('FrontalFaceCART'); 2: FrontalFaceLBP release(Detector); detector.ClassificationModel='FrontalFaceLBP'; bboxes=step(detector,img); FrontalFaceLBP=insertObjectAnnotation(img,'rectangle',bboxes,'Face'); figure(2); imshow(FrontalFaceLBP); title('FrontalFaceLBP'); %% Test 3: UpperBody release(Detector); detector.ClassificationModel='UpperBody'; detector.MergeThreshold=3; % add merge threshold bboxes=step(detector,img); UpperBody=insertObjectAnnotation(img,'rectangle',bboxes,'UpperBody'); figure(3); imshow(UpperBody); title('UpperBody'); detector.MergeThreshold=4; 4: EyePairBig/EyePairSmall Release (Detector); detector.ClassificationModel='EyePairBig'; bboxes=step(detector,img); EyePairBig=insertObjectAnnotation(img,'rectangle',bboxes,'Eyes'); figure(4); subplot(211); imshow(EyePairBig); title('EyePairBig'); release(detector); detector.ClassificationModel='EyePairSmall'; bboxes=step(detector,img); EyePairSmall=insertObjectAnnotation(img,'rectangle',bboxes,'Eyes'); figure(4); subplot(212); imshow(EyePairSmall); title('EyePairSmall'); Test 5: LeftEye/RightEye Release (detector); detector.ClassificationModel='LeftEye'; detector.MergeThreshold=10; % add merge threshold bboxes=step(detector,img); LeftEye=insertObjectAnnotation(img,'rectangle',bboxes,'LeftEye'); figure(5); subplot(211); imshow(LeftEye); title('LeftEye'); release(detector); detector.ClassificationModel='RightEye'; bboxes=step(detector,img); RightEye=insertObjectAnnotation(img,'rectangle',bboxes,'RightEye'); figure(5); subplot(212); imshow(RightEye); title('RightEye'); detector.MergeThreshold=4; % Restore the merge threshold %% Test 6: LeftEyeCART/RightEyeCART Release (Detector); detector.ClassificationModel='LeftEyeCART'; bboxes=step(detector,img); LeftEyeCART=insertObjectAnnotation(img,'rectangle',bboxes,'LeftEye'); figure(6); subplot(211); imshow(LeftEyeCART); title('LeftEye'); release(detector); detector.ClassificationModel='RightEyeCART'; bboxes=step(detector,img); RightEyeCART=insertObjectAnnotation(img,'rectangle',bboxes,'RightEye'); figure(6); subplot(212); imshow(RightEyeCART); title('RightEye'); Test 7: ProfileFace Release (Detector); detector.ClassificationModel='ProfileFace'; bboxes=step(detector,img); ProfileFace=insertObjectAnnotation(img,'rectangle',bboxes,'Face'); figure(7); imshow(ProfileFace); title('ProfileFace'); %% test 8: Mouth release(Detector); detector.ClassificationModel='Mouth'; detector.MergeThreshold=100; % increase merge threshold bboxes=step(detector,img); Mouth=insertObjectAnnotation(img,'rectangle',bboxes,'Mouth'); figure(8); imshow(Mouth); title('Mouth'); detector.MergeThreshold=4; %% test 9: Nose release(Detector); detector.ClassificationModel='Nose'; detector.MergeThreshold=10;; % increase merge threshold bboxes=step(detector,img); Nose=insertObjectAnnotation(img,'rectangle',bboxes,'Nose'); figure(9); imshow(Nose); title('Nose');Copy the code