A kind of hair based on gradient direction divides to determination methodsTechnical field
The present invention relates to one kind to be applied to technical field of face recognition, and in particular to a kind of hair based on gradient direction pointTo determination methods.
Background technology
The processing of face head portrait is the important research direction of image processing field.In recent years based on the various of face head portrait processingVarious face U.S. face beautifying functions that cell phone application software provides, are welcome by user's particularly female user very much.
Based on the hair treatment of face head portrait, extremely abundant function can be provided for the face beautification of face U.S..Such as faceThe hair dyeing related to hair in U.S. face, the hair style selection in the function, and human face cartoon such as restyle the hair generate with hair lines,The hair treatment of face head portrait can largely influence the whole structure of beautifying faces processing, provide the user abundant comprehensiveBeautifying faces are experienced.
Hair is the basis of hair treatment in face head portrait point to judgement, and it can instruct follow-up restyle the hair, have hair dyed, sending outType selection is equal to the related processing of hair.Existing hair point mainly passes through binaryzation face and hair zones to determination methodsImage, the edge lines of image-region on eyebrow are then extracted, changed by the bifurcated of hair edge lines, to judge hairPoint to.Such method is had a great influence by photoenvironment, and many complicated edge lines bifurcated situations can not be judged, correctlyRate is relatively low.
The content of the invention
To divide in order to solve the above technical problems, it is an object of the invention to provide a kind of hair based on gradient direction to judgementMethod, the image of any angle shot can be handled, and accuracy rate is high, and processing speed is fast.
To realize above-mentioned technical purpose, the present invention provides a kind of hair based on gradient direction point to determination methods, specificallyComprise the following steps:
(1) Dlib facial feature points detection algorithms are used, detect that 68 characteristic points of face in face head portrait picture (are dividedBiao Ji not be);
(2) 68 characteristic points according to face, rotation image cause face to be in the horizontal level of image, then intercepted outFace entirety photographic region comprising hair;
(3) for the complete human face region after conversion, the image of hair zones is intercepted out, then calculates the area imageThe gradient direction of each pixel;
(4) gradient direction of each pixel of whole hair zones is traveled through, according to the situation of change of gradient direction, is judgedHair point to.
Specifically, step (2) comprises the following steps:
(2.1) straight line of facial contour B1 and B17 point composition and horizontal angle α are calculated;
(2.2) by image clockwise rotation alpha, the image of horizontal face is obtained, while correct 68 human face characteristic point coordinates;
(2.3) face center C coordinate (X is determinedc, Yc);
(2.4) sat based on C points and B1 and B17 point coordinates, the X in the upper left corner and the lower right corner that calculate rectangle human face region are satMark;
(2.5) sat based on C points and B1 and B17 point coordinates, the Y in the upper left corner and the lower right corner that calculate rectangle human face region are satMark;
(2.6) coordinate based on the upper left corner and the lower right corner, it is determined that and intercepting face and hair zones image.
Specifically, step (3) comprises the steps of:
(3.1) hair zones in facial image are determined;
(3.2) the gradient angle θ of each pixel in hair zones is calculated;
(3.3) the gradient angle matrix of hair zones pixel is obtained.
Specifically, step (4) comprises the steps of:
(4.1) the gradient angle matrix is normalized;
(4.2) the hair zones image is divided into 2N blocks zonule (N is positive integer), calculates the ladder in each piece of regionAngle average value is spent, and to the average value normalized;
(4.3) the gradient angle average value in left side N blocks region and right side N blocks region is calculated;
(4.4) according to the gradient angle average value in left and right sides N blocks region, judge hair point to.
Specifically, the angleWherein (XB1,YB1) it is B1 point coordinates, (XB17,YB17)For B17 point coordinates.
Specifically, the calculation formula of the X-coordinate in the upper left corner of the rectangle human face region and the lower right corner is as follows:The upper left cornerThe X-coordinate X of pointLIt can be calculated by formula below, XL=XC-1.3×(XC-XB1), if XLLess than 0, then XL=0;The X in the lower right cornerCoordinates XRIt can be calculated by formula below, XR=XC+1.3×(XB17-XC);If X computed aboveRMore than imageWidth Width, then XR=Width;Wherein, the coordinate of C points
Specifically, the calculation formula of the Y-coordinate in the upper left corner of the rectangle human face region and the lower right corner is as follows:The upper left cornerThe Y-coordinate Y of pointLIt can be calculated by formula below, YL=YC-1.5×(YB9-YC), wherein, B9 is to indicate chin in facial contourThe edge of lower bound, if YLLess than 0, then YL=0;The Y-coordinate Y in the lower right cornerRIt can be calculated by formula below, YR=YC+1.5×(YB9-YC), if Y computed aboveRMore than the height Height of image, then YR=Height;Wherein, the coordinate of C points
Specifically, the computational methods of the gradient angle of each pixel are as follows in the calculating hair zones:Remember point Pi(i,J) pixel value is I (i, j), calculates pixel P firstiIn the gradient D of X-directionxThe gradient D of (I, J) and Y-directiony(I, J), itsCalculation formula is respectively:Dx(I, J)=I (I+1, J)-I (I-1, J), Dy(I, J)=I (I, J+1)-I (I, J-1), pixel PiGradient angle θ=atan2 (Dy(I, J), Dx(I, J)).
Specifically, gradient angle matrix normalization formula is:WhenWhen think toward right avertence, θ is set to 1;WhenWhen think toward left avertence, θ is set to -1;WhenWhen think to have no bias for, θ is set to 0.
Specifically, the hair zones image is divided into 12 pieces of zonules, division methods are:With characteristic point B1 andB17 central point C is the center of circle, and one piece of sector region can be marked every 15 degree from B1 points, and traversing B17 points just can be with12 sector regions are obtained, are designated as S1 to S12 respectively;Calculate the gradient angle average value in each piece of region and normalized processFor:Then the gradient angle of each pixel in the Si of region is added divided by pixel number, the zone leveling that can obtain Si are terracedAngle value Ti;When 0.3<During Ti≤1, it is believed that put 1 to right avertence, Ti in the region;The region is thought as -1≤θ≤- 0.3 toward left avertence,Ti is set to -1;When -0.3<Think that the region has no bias for during θ≤0.3, Ti is set to 0.
From above technical scheme, the hair provided by the present invention based on gradient direction point uses to determination methodsDlib facial feature points detection algorithms, 68 characteristic points of face in face head portrait picture are detected, and according to feature thereinPair graph picture is rotated, and is horizontal face head portrait, can handle the image of any angle shot;In processing procedureIn, the facial image region comprising hair is intercepted from general image, is judging hair point during, calculating gradient sideOnly need to carry out in hair zones to, traversal processing gradient information, can effectively reduce the overall calculation amount of algorithm, lifting processingSpeed;Because hair zones gradient direction can reflect the trend of hair well, so the change of gradient direction, can very certainlyThe change in hair direction so is deduced, the present invention is based on this principle, can judge hair point to higher exactlyAccuracy rate.
Brief description of the drawings
(1) Fig. 1 is the step flow chart of the present invention.
(2) Fig. 2 is the particular flow sheet of step in the present invention (2).
Embodiment
The present invention will be further described below in conjunction with the accompanying drawings:
Refer to Fig. 1-Fig. 2, the hair based on gradient direction provided in the present embodiment point is to determination methods, specific bagInclude following steps:
(1) Dlib facial feature points detection algorithms are used, detect 68 characteristic points of face in face head portrait picture;PeopleThe detection of face characteristic point, the facial feature points detection algorithm for the storehouse Dlib that increases income can be used to complete, Dlib built-in functions can detectGo out 68 characteristic points of face, its detection speed is fast, characteristic point position is accurate, is facial feature points detection popular at presentMethod, in the human face characteristic point that Dlib is detected, face mask edge has used 17 points, and two eyebrows have used 10 points,Eyes have used 12 points, and nose uses 9 points, and face has used 20 points, by this 68 points, can easily determineThe particular location of each organ of face;
(2) 68 characteristic points for detecting Dlib are labeled as B1-B68, and wherein the 17 of face mask edge point is B1-The straight line of B17, B1 and B17 composition, slope calculationsThe straight line and horizontal angle α can be obtained,Wherein (XB1,YB1) it is B1 point coordinates, (XB17,YB17) it is B17 point coordinates;
(3) by whole pictures using B1 as the center of circle, turn clockwise α angles, obtains a revised facial image so thatFace is horizontal level, meanwhile, 68 characteristic points are also turned clockwise α angles, amendment obtains the spy being in horizontal faceSign point;
(4) in revised 68 characteristic points, the 1st point B1 and the 17th point B17 center is labeled as C points, is wholeThe central point of individual hair and facial image, central point C coordinate can be calculated
(5) coordinate based on C point coordinates and face edge starting point B1 and terminating point B17, the face of interception is calculatedWith the X-coordinate of hair zones rectangle frame upper left angle point and bottom right angle point;Wherein, the X-coordinate X of upper left angle pointLFollowing public affairs can be passed throughFormula calculates, XL=XC-1.3×(XC-XB1), if XLLess than 0, then XL=0;The X-coordinate coordinate X in the lower right cornerRFollowing public affairs can be passed throughFormula calculates, XR=XC+1.3×(XB17-XC);If X computed aboveRMore than the width Width of image, then XR=Width;
(6) coordinate based on C point coordinates and face edge starting point B1 and terminating point B17, the face of interception is calculatedWith the Y-coordinate of hair zones rectangle frame upper left angle point and bottom right angle point, the Y-coordinate Y of upper left angle pointLFormula below meter can be passed throughCalculate, YL=YC-1.5×(YB9-YC), wherein, B9 is the edge that chin lower bound is indicated in facial contour, if YLLess than 0, then YL=0;The Y-coordinate Y in the lower right cornerRIt can be calculated by formula below, YR=YC+1.5×(YB9-YC), if Y computed aboveRGreatlyIn the height Height of image, then YR=Height;
(7) top left co-ordinate (XL, YL) and bottom right angular coordinate (XR, YR), the rectangular area that it is indicated, as face andHair zones image, the image-region is zoomed in and out so that the picture traverse after scaling is 480 pixels;
(8) characteristic point BiFormer coordinate be (XBi, YBi), B in the new images obtained through step 2iCoordinate be (X'Bi,YBi') can be calculated by formula below, wherein X-coordinate calculation formula is:Y-coordinateCalculation formula is:
(9) using the region on ear as hair zones, interception Y-coordinate is less than y=max (YB1, YB17) region as headSend out region;
(10) gradient angle of each pixel (i, j) in hair zones is calculated, the pixel value of note point (i, j) is I (i, j),Gradient D of the pixel in X-direction is calculated firstxThe gradient D of (I, J) and Y-directiony(I, J), its calculation formula are respectively:Dx(I,J)=I (I+1, J)-I (I-1, J), Dy(I, J)=I (I, J+1)-I (I, J-1), gradient angle θ=atan2 (D of pixely(I,J), Dx(I, J));
(11) the gradient angle matrix of new images is obtained, Y-coordinate is more than y=max (YB1, YB17) other regions in, pixelGradient angle θ be set to 0;
(12) the gradient angle matrix of normalized image, by following formula, the gradient angle of pixel is normalized:WhenWhen think toward right avertence, θ is set to 1;WhenWhen think toward left avertence, θ is set to -1;WhenWhen think to have no bias for, θ is set to 0;
(13) using characteristic point B1 and B17 central point C as the center of circle, one piece of sector can be marked every 15 degree from B1 pointsRegion, 12 sector regions can be obtained just by traversing B17 points, S1 to S12 is designated as respectively, for the gradient angle after normalizationMatrix, to each sector region Si, by the gradient angle of each pixel in its region be added and then divided by pixel number, can be withObtain Si zone leveling Grad Ti;
(14) sector region average gradient value Ti is normalized, by formula below, 12 regions computed above are put downEqual gradient Ti is normalized:When 0.3<During Ti≤1, it is believed that put 1 to right avertence, Ti in the region;Think this as -1≤θ≤- 0.3Region is set to -1 toward left avertence, Ti;When -0.3<Think that the region has no bias for during θ≤0.3, Ti is set to 0;
(15) the subregional 6 sector region average gradient values summation in hair image left side, can obtain Grad TL;Right half6 sector region average gradient values summation of subregion, can obtain Grad TR;For TLAnd TR, when it is less than 0, show headLeft avertence is sent to, is set to -1;During more than 0, show that hair to right avertence, is set to 1;
(16) it is based on TLAnd TRDifferent value, judge hair point to;Hair divides to a total of 4 kinds of states:In point, left point, it is rightPoint, without point to;Work as TLFor -1 and TRFor 1 when, in being judged as point;Work as TL+TR<When 0, it is judged as left point;Work as TL+TR>When 0, judgeFor the right side point;Outside situation in above-mentioned point, TL+TRWhen=0, hair without point to.
The present invention uses Dlib facial feature points detection algorithms, detects 68 features of face in face head portrait picturePoint, the image of any angle shot can be handled;In processing procedure, by the facial image region comprising hair from general imageMiddle interception, hair point is being judged during, is calculating gradient direction, traversal processing gradient information only needs to enter in hair zonesOK, the overall calculation amount of algorithm can be effectively reduced, lifts processing speed;Because hair zones gradient direction can be anti-wellThe trend of hair is reflected, so the change of gradient direction, can naturally enough deduce the change in hair direction, the present invention is based on thisPrinciple, hair point can be judged to having higher accuracy rate exactly;The present invention has good application value.
Embodiment described above is only that the preferred embodiment of the present invention is described, not to the model of the present inventionEnclose and be defined, on the premise of design spirit of the present invention is not departed from, technical side of the those of ordinary skill in the art to the present inventionThe various modifications and improvement that case is made, it all should fall into the protection domain of claims of the present invention determination.