features : A result of a pixel operation .
<>Harr features
haar The characteristics are mainly divided into the following categories :
features = Whole area weight 1 + Black weight weight 2
= ( black + white )1+ black (-2)
= black + white - black 2
= white - black
Ergodic process
Traverse from top to bottom, left to right , Consider the image and template size .
When the picture size=100100 Template size=1010, need 100 Only one template can be covered. After many times of scaling, the amount of computation will be very large . The integral graph is introduced .
The main idea of integral graph : The sum of pixels in the rectangular area formed by the image starting from the starting point to each point is saved in memory as an array element , When you want to calculate the sum of pixels in a region, you can index the elements of the array directly , There is no need to recalculate the sum of pixels in this region , Thus, the calculation is speeded up ( There is a corresponding title , It's called a dynamic programming algorithm ). The integral graph can be used in many scales , Use the same time ( Constant time ) To calculate different characteristics , Therefore, the detection speed is greatly improved .
<>Adaboost classifier
Adaboost It is an iterative algorithm , Its core idea is to train different classifiers for the same training set ( Weak classifier ), Then these weak classifiers are put together , Form a stronger final classifier ( Strong Classifier ).
Strong Classifier ( cascade )<– Weak classifier ( Computing strong classifier features )<–node node
At most 3 individual haar The feature corresponds to one node node .
Training termination conditions :
1, Maximum number of cycles
2, Minimum detection probability
Training steps
1, Initialization data weight distribution - Each data is assigned an equal weight
2, Ergodic threshold p Find the minimum threshold
3,
4, Weight distribution update
#1 load xml ; 2 load jpg ; 3 haar gray ; 4 detect 5 ;draw import cv2 import
numpyas np #load xml face_xml = cv2.CascadeClassifier(
'haarcascade_frontalface_default.xml') eye_aml = cv2.CascadeClassifier(
'haarcascade_eye.xml') #load jpg img = cv2.imread('face.jpg')
#cv2.imshow('src',img) #haar(openCV) gray gray = cv2.cvtColor(img,cv2.
COLOR_BGR2GRAY) #detect 1 data 2 scale 3 5 faces = face_xml.detectMultiScale(
gray,1.3,5) print("faces=",len(faces)) #draw for (x,y,w,h) in faces: cv2.
rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) roi_face = gray[y:y+h,x:x+w]
roi_color= img[y:y+h,x:x+w] eyes = eye_aml.detectMultiScale(roi_face) print(
'eye=',len(eyes)) for (e_x,e_y,e_w,e_h) in eyes: cv2.rectangle(roi_color,(e_x,
e_y),(e_x+e_w,e_y+e_h),(0,255,0),2) cv2.imshow("img",img) cv2.waitKey(0)
Technology