Large-scale human face deformation method
Technical Field
The invention belongs to the technical field of graphic processing, and particularly relates to a large-scale face deformation method.
Background
The research of human face image deformation technology and algorithm is always an important research content in the image processing research field. The algorithm related to the face image deformation is complex, the core content of the face image deformation is that a deformation mapping function is generated according to a certain constraint condition, and a smooth and natural deformation effect is generated by controlling the characteristic points.
Nowadays, people pay more attention to details of human face image deformation, but existing deformation technologies mainly focus on small-scale deformation of local areas, such as large eyes, face thinning and the like. If large-scale face deformation is involved, the problems of unsmooth deformation edge, unnatural face after deformation and the like can be caused, so that the overall effect of the processed image is unnatural. In addition, the feature points obtained by the existing mature human face feature point recognition algorithm only cover the part below the eyebrow, so that the human face deformation based on the feature points can only be carried out on the part below the eyebrow, and the forehead cannot be deformed.
Disclosure of Invention
In view of the technical problems, the invention is used for providing a large-scale face deformation method, and mainly solves the problems of unnatural face deformation areas and unsmooth face edges generated after the face large-scale deformation is realized in the prior art.
In order to solve the technical problems, the invention adopts the following technical scheme:
a large-scale human face deformation method comprises the following steps:
s10, obtaining a plurality of face characteristic points according to the existing face characteristic point recognition algorithm;
s20, calculating the forehead feature point according to the eyebrow feature point and the size of the current face frame, wherein the formula is as follows:
P head.x =P eyebrow.x
P head.y =P eyebrow.y -αH face
wherein d is the gain factor, H face The current face frame height; p head.x ,P head.y Respectively calculating the x-axis coordinate and the y-axis coordinate of the obtained forehead characteristic point; p eyebrow.x ,P eyebrow.y Respectively representing x-axis coordinates and y-axis coordinates of the specific eyebrow feature points;
calculating cheek feature points from the nose wing feature points and the face contour, wherein the formula is as follows:
P face.xy =(P profile.xy +P nose.xy )/2.0
wherein P is face.xy Calculating the coordinates of the obtained cheek feature points; p profile.xy Coordinates of contour points of a specific face; p nose.xy Coordinates of feature points of a specific nose and wing part;
the additional characteristic points are added to cover the area which cannot be marked by the current face recognition algorithm, and then the face deformable area is added;
s30, randomly selecting n points from all the above feature points as control vertices, (where 3 ≦ n ≦ the number of feature points), and if the expected form is a face symmetric deformation mode, only selecting one side of feature points, where the symmetric feature points automatically become control vertices; if the deformation mode is the asymmetric deformation mode, the control point is the selected characteristic point;
and S40, obtaining coordinates of all the deformed human face characteristic points through moving least square method MLS calculation according to given deformation constraint conditions and control vertexes, wherein the characteristic points obtained through the algorithm enable the human face to be more natural after deformation. The MLS expression is:
f v (x)=(x-p * )M+q *
where x is the current point v coordinate, f v (x) The coordinates after deformation are respectively weighted summation and gravity center positions of control points before deformation, and M is an affine transformation matrix;
s50, interpolation processing is carried out on the feature points before and after deformation by adopting B spline interpolation, the density of the feature points is improved, edges and corners generated by deformation (especially deformation such as stretching and enlarging) are reduced, and the smoothness of the edges of the human face after large-scale deformation is improved;
s60, triangulating the feature points which are not deformed after interpolation to obtain indexes corresponding to all triangle vertexes;
s70, converting the positions of the feature points before deformation into texture coordinates,
UV x =P x /width;
UV y =P y /height;
wherein UV x ,UV y Texture x-axis coordinates and texture y-axis coordinates respectively; p x ,P y Respectively representing x-axis coordinates and y-axis coordinates of the characteristic points before deformation; width is the width of the texture; height is the texture height;
the deformed feature point positions are converted into vertex positions,
wherein Pos x ,Pos y Respectively representing vertex x and y-axis coordinates, and Px and Py respectively representing feature point x and y-axis coordinates before deformation; width is the width of the texture; height is the texture height;
and adding a vertex index obtained by triangulation, and rendering through OpenGL to obtain the final effect of the human face after large-scale deformation.
Preferably, the B-spline interpolation expression is:
wherein d is i (i is 0, 1 … N) denotes a control vertex (feature point coordinates), N i,k (i ═ 0, 1 … n) is the k-th order canonical B spline basis function, with the highest order being k.
Preferably, the deformation constraint condition includes a deformation strength, whether to symmetrically deform, a deformation amount and a deformation point index.
The invention has the following beneficial effects:
(1) calculating characteristic points of the forehead and the cheek part by using the existing face characteristic points, and ensuring that all areas of the face are marked by the characteristic points, so that the deformation of the forehead part becomes possible;
(2) calculating by adopting a Moving Least Square (MLS) method and combining deformation constraint conditions to obtain all deformed characteristic points, so that the deformed face is more natural;
(3) the B-spline interpolation method is adopted to interpolate the original face characteristic points and the deformed face characteristic points respectively, so that the problems of sharp edges and the like caused by large-scale deformation are solved, and the smoothness of the deformed face edges is improved.
Drawings
Fig. 1 is a flowchart illustrating steps of a large-scale face morphing method according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a large-scale face deformation method disclosed by the embodiment of the invention is shown, and includes the following steps:
s10, obtaining a plurality of face characteristic points according to the existing face characteristic point recognition algorithm;
s20, calculating the forehead feature point according to the eyebrow feature point and the size of the current face frame, wherein the formula is as follows:
P head.x =P eyebrow.x
P head.y =P eyebrow.y -αH face
where α is the gain factor, H face The current face frame height; p head.x ,P head.y Respectively calculating the x-axis coordinate and the y-axis coordinate of the obtained forehead characteristic point; p eyebrow.x ,P eyebrow.y The x-axis coordinates and the y-axis coordinates of the specific eyebrow feature points are respectively.
Calculating cheek feature points from the nose wing feature points and the face contour, wherein the formula is as follows:
P face.xy =(P profile.xy +P nose.xy )/2.0
wherein P is face.xy Calculating the coordinates of the obtained cheek feature points; p profile.xy Coordinates of contour points of a specific face; p nose.xy Is the specific nose and wing feature point coordinate.
The additional characteristic points are added to cover the area which cannot be marked by the current face recognition algorithm, and then the face deformable area is added;
s30, randomly selecting n points from all the above feature points as control vertices, (where 3 ≦ n ≦ the number of feature points), and if the expected form is a face symmetric deformation mode, only selecting one side of feature points, where the symmetric feature points automatically become control vertices; if the deformation mode is the asymmetric deformation mode, the control point is the selected characteristic point;
and S40, obtaining coordinates of all human face feature points after deformation through moving least square method MLS calculation according to given deformation constraint conditions (including deformation strength, whether symmetrical deformation exists, deformation amount and deformation point index) and control vertexes, and enabling the human face to be more natural after deformation through the feature points obtained through the algorithm. The MLS expression is:
f v (x)=(x-p * )M+q *
where x is the current point v coordinate, f v (x) And p and q are weighted summation and gravity center position of the control point before deformation respectively, and M is an affine transformation matrix.
S50, interpolation processing is carried out on the feature points before and after deformation by adopting B spline interpolation, the density of the feature points is improved, edges and corners generated by deformation (especially deformation such as stretching and enlarging) are reduced, and the smoothness of the edges of the human face after large-scale deformation is improved; the B spline interpolation expression is:
wherein d is i (i is 0, 1 … N) is a control vertex (feature point coordinate), N i,k (i ═ 0, 1 … n) is the k-th order canonical B spline basis function, with the highest order being k.
S60, triangulating the feature points which are not deformed after interpolation to obtain indexes corresponding to all triangle vertexes;
s70, converting the positions of the feature points before deformation into texture coordinates,
UV x =P x /width;
UV y =P y /height;
wherein UV x ,UV y Texture x-axis coordinates and texture y-axis coordinates respectively; p x ,P y Respectively representing x-axis coordinates and y-axis coordinates of the characteristic points before deformation; width is the width of the texture; height is the texture height.
The deformed feature point positions are converted into vertex positions,
wherein Pos x ,Pos y Respectively, the x-axis coordinate and the y-axis coordinate of the vertex, and Px and Py respectivelyThe coordinate of the characteristic point x and y axis before deformation; width is the width of the texture; height is the texture height.
And adding a vertex index obtained by triangulation, and rendering through OpenGL to obtain the final effect of the human face after large-scale deformation.
According to the embodiment of the invention, by the technical scheme, the characteristic points of the forehead and the cheek part are calculated by using the existing human face characteristic points, so that all areas of the human face are marked by the characteristic points, and the forehead part is possible to deform; calculating by adopting MLS and combining deformation constraint conditions to obtain all deformed characteristic points, so that the deformed face is more natural; the B-spline interpolation method is adopted to interpolate the original face characteristic points and the deformed face characteristic points respectively, so that the problems of sharp edges and the like caused by large-scale deformation are solved, and the smoothness of the deformed face edges is improved.
It is to be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the present invention have been described with reference to the accompanying drawings, it will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the following claims.