Image Processing Method and Device for Preventing Head Distortion

Through the face recognition model and OpenGL rendering technology, the head distortion caused by one-click body beauty is solved, and the smooth transition between body beautification and head protection is achieved, ensuring the authenticity and beauty of the image.

CN114882562BActive Publication Date: 2025-07-22GUANGZHOU GUANGZHUIYUAN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210505326.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-10
Publication Date
2025-07-22
Estimated Expiration
2042-05-10

AI Technical Summary

Technical Problem

In the prior art, the one-click body beauty function of the software can easily cause unnaturally distorted face and head, affect the beauty and easily detect the traces of photo editing.

Method used

The pre-constructed face recognition model recognizes the face key point data, determines the deformation area and performs proportional adjustments, and combines OpenGL rendering technology to achieve a smooth transition between the head and the deformation area, preventing the head from twisting and deforming.

Benefits of technology

While achieving one-click body beautification, it prevents head distortion and deformation, ensuring the true and beautiful image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114882562B_ABST
    Figure CN114882562B_ABST
Patent Text Reader

Abstract

The present invention relates to an image processing method and apparatus for preventing head distortion. The method includes inputting an image to be processed into a pre-built face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of the facial features and the facial contour in the image to be processed; determining a local area of the image to be processed as a deformation area, adjusting the deformation area according to a preset ratio to obtain an optimized portrait image; restoring the facial contour of the optimized portrait image to the original ratio according to the face key point data, and adjusting the pixel values around the face key point data after restoring the ratio, so that the head and the deformation area present a smooth transition. The present invention can not only perform one-key body shaping, but also specifically introduce algorithm protection measures for the head and face to ensure a real and beautiful effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image processing, and particularly relates to an image processing method and device for preventing head distortion and deformation. Background Art

[0002] Nowadays, we have entered the digital age, and people rely on image editing software to modify portraits in pictures to create a satisfactory image in terms of appearance and figure.

[0003] In the related art, in current photo editing software, due to the wide application of face key point recognition technology, there are already many functions for one-key automatic beautification of faces. However, for figure modification, such as beautiful shoulders, enhanced breasts, slender waists, long legs, etc., users still need to manually edit. There is a lack of a "one-key body beautification" function corresponding to "one-key beauty". Or, even if there is a function for one-key beautification of the figure of a portrait, although the one-key beautification function of the figure of a portrait is convenient for users, it has the problem of inability to perform fine-grained image editing. Especially for the face with fine elements and sensitive perception, the stretching and distortion processing of the whole body one-key beautification process on the picture often causes unnatural distortion of the face and head, which not only affects the beauty of the face but also is easy to be seen as retouched. Summary of the Invention

[0004] In view of this, the purpose of the present invention is to overcome the deficiencies of the prior art and provide an image processing method and device for preventing head distortion and deformation, so as to solve the problem that the one-key body beautification function in the existing software causes unnatural distortion of the face and head.

[0005] To achieve the above purpose, the present invention adopts the following technical solutions: An image processing method for preventing head distortion and deformation, comprising:

[0006] Input the image to be processed into a pre-constructed face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of the facial features and the facial contour in the image to be processed.

[0007] Determine a local area of the image to be processed as a deformation area, and adjust the deformation area according to a preset ratio to obtain an optimized portrait image.

[0008] Restore the facial contour of the optimized portrait image according to the face key point data, and adjust the pixel values around the face key point data after restoration to make the head and the deformation area present a smooth transition.

[0009] Further, the step of determining a local area of the image to be processed as a deformation area, adjusting the deformation area according to a preset ratio to obtain an optimized portrait image includes:

[0010] Decode the image to be processed to obtain the decoded image data, process the image data to obtain a texture P suitable for OpenGL rendering, and record the width and height of the image texture;

[0011] Determine the horizontal normalized coordinates of the deformation region and represent the deformation region using the normalized coordinates;

[0012] Stretch the deformation region according to a preset stretching strength value to obtain the width of the target image after deformation; wherein, the height of the image to be processed remains unchanged;

[0013] Determine the horizontal normalized coordinates of the width of the target image;

[0014] Construct vertex coordinates and texture coordinates for OpenGL rendering, as well as the mapping relationship between vertex coordinates and texture coordinates; wherein, when assigning vertex coordinates to the preset parameters of the OpenGL vertex shader, they need to be mapped to the range of [-1, 1];

[0015] Construct OpenGL triangle primitives according to the mapping relationship between vertex coordinates and texture coordinates;

[0016] Render the texture P according to the OpenGL triangle primitives to obtain the deformed texture T1.

[0017] Further, the original proportion restoration of the facial contour of the portrait optimized image according to the facial key point data includes:

[0018] Perform reverse stretching on the facial contour of the portrait optimized image according to the facial key point data;

[0019] Wherein the facial contour is the head area wrapped by the facial key point data.

[0020] Further, adjusting the pixel values around the facial key point data after adjusting the restoration ratio to make the head and the deformation region present a smooth transition includes:

[0021] Calculate the average value of all facial key points kps to obtain the head center point center;

[0022] Construct outer protection points ops. The number of outer protection points ops is the same as that of the facial key points kps and they correspond one by one. For each point op in the outer protection points ops and the corresponding point kp of the facial key points kps, there is the following relationship:

[0023] op = center + (kp - center) * k;

[0024] Among them, k is a scaling factor, and its value range must be greater than 1. The circular area formed by the outer protection points ops and the face key points kps is the smooth transition area between the head and the deformation area;

[0025] Calculate all the point coordinates of the optimized portrait image, including the deformed face key points tkps, the deformed outer protection points tops, and the deformed head center point tcenter;

[0026] For each deformed point tp and the corresponding point p of the image to be processed, there is the following relationship;

[0027] tp.x = (p.x - left) / (right - left) * (tright - tleft) + tleft;

[0028] tp.y = p.y;

[0029] Construct texture coordinates [tcenter, tkps, tops] for OpenGL rendering;

[0030] Construct vertex coordinates [vcenter, vkps, vops] for OpenGL rendering;

[0031] Among them, vcenter = tcenter;

[0032] The number of points of the vertex coordinates vkps is the same as that of the deformed face key points tkps and they correspond one by one. For each point vkp in vkps and the corresponding point tkp in tkps, there is the following relationship:

[0033] vkp.x = tcenter.x + (tkp.x - tcenter.x) * (1.0 / scale); vkp.y = tkp.y;

[0034] Among them, scale is the stretching strength value in the body beautification module;

[0035] vops = tops;

[0036] In addition, when assigning the vertex coordinates to the preset parameter gl_Position of the OpenGL vertex shader, it needs to be mapped to the range of [-1, 1];

[0037] Construct OpenGL triangle primitives. Each two adjacent points of tcenter and tkps form a triangle primitive, and each two corresponding adjacent points of tkps and vops form two triangle primitives;

[0038] Input texture T1, and after OpenGL rendering, texture T2 is obtained.

[0039] Further, it further includes:

[0040] The face recognition model recognizes the to-be-processed image;

[0041] If there is a face in the to-be-processed image, face key point data is output; otherwise, the process ends.

[0042] Further, when there are multiple heads in the input image, anti-distortion processing is performed on each head in sequence until the last head.

[0043] Further, the value range of the stretching strength value is 0.9 to 1.1, and the stretching strength value represents the scaling factor of the width of the deformation area. If it is greater than 1, the width expands; if it is less than 1, the width shrinks.

[0044] An embodiment of the present application provides an image processing device for preventing head distortion, including:

[0045] A face recognition module, configured to input a to-be-processed image into a pre-constructed face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of facial features and facial contours in the to-be-processed image;

[0046] A portrait optimization module, configured to determine a local area of the to-be-processed image as a deformation area, and adjust the deformation area according to a preset ratio to obtain a portrait optimization image;

[0047] A head anti-distortion module, configured to restore the facial contour of the portrait optimization image to the original proportion according to the face key point data, and adjust the pixel values around the face key point data after restoring the proportion, so that the head and the deformation area present a smooth transition.

[0048] Further, it further includes:

[0049] A detection and positioning module, configured to recognize the to-be-processed image through a face recognition model;

[0050] If there is a face in the to-be-processed image, face key point data is output; otherwise, the process ends.

[0051] An embodiment of the present application provides a mobile terminal, including: a memory and a processor, where the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the above generation methods or the steps of any one of the above query methods.

[0052] The present invention adopts the above technical solutions, and the beneficial effects that can be achieved include:

[0053] The present invention provides an image processing method and device for preventing head distortion. The technical solution provided by this application combines face key point recognition, body key point recognition, portrait area discrimination, distortion and anti-distortion, and invents a one-key automatic beautification function for photo body correction. It can automatically locate the key areas of the body and optimize the shapes of areas such as the neck, shoulders, chest, and waist through algorithms such as image distortion and stretching. At the same time, although the one-key beautification function for the portrait body is convenient for users, protective measures for preventing head distortion are also specifically introduced for the head and face to ensure a real and beautiful effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0055] Figure 1 Schematic diagram of the steps of the image processing method for preventing head distortion of the present invention;

[0056] Figure 2 Schematic diagram of the structure of the OpenGL triangle primitive of the present invention;

[0057] Figure 3 Schematic diagram of the deformed texture of the present invention;

[0058] Figure 4 Schematic diagram of the deformed head of the present invention;

[0059] Figure 5 Schematic diagram of the head after the operation of preventing head distortion of the present invention;

[0060] Figure 6 Schematic diagram of the structure of the image processing device for preventing head distortion of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0061] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be described in detail below. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments of the present invention belong to the scope protected by the present invention.

[0062] The following introduces a specific image processing method and device for preventing head distortion provided in the embodiments of this application in conjunction with the drawings.

[0063] As Figure 1 shown, the image processing method for preventing head distortion and deformation provided in the embodiments of the present application includes:

[0064] S101. Input the image to be processed into a pre-constructed face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of the facial features and the facial contour in the image to be processed;

[0065] In the present application, first, multiple images containing complete faces are obtained as training images to train a preset first neural network model in the mobile client. The first neural network model can receive an input image and output the face information in the image. Preferably, the face information is face key point data, and the face key point data includes the two-dimensional coordinates of facial features, facial contour, etc. in the image. The denser the key points, the finer the subsequent facial optimization effect. The specific number of key points can be flexibly set according to needs.

[0066] Among them, the face recognition model recognizes the image to be processed;

[0067] If there is a face in the image to be processed, output the face key point data; otherwise, end the process.

[0068] Specifically, in the present application, the first neural network model is used to detect and locate the image data. When and only when the first neural network model detects and locates the face key point data in the image, the face key point data is output.

[0069] S102. Determine a local area of the image to be processed as the deformation area, and adjust the deformation area according to a preset ratio to obtain an optimized portrait image;

[0070] In some embodiments, the original ratio reduction of the facial contour of the optimized portrait image according to the face key point data includes:

[0071] Performing reverse stretching on the facial contour of the optimized portrait image according to the face key point data;

[0072] Wherein the facial contour is the head area wrapped by the face key point data.

[0073] In some embodiments, changing the aspect ratio of an image can deform the image. Taking horizontal stretching as an example, when changing the width of a portrait image, if the width is reduced and the aspect ratio becomes smaller, the portrait in the image will become slimmer. Conversely, if the width is increased and the aspect ratio becomes larger, the portrait in the image will become shorter and fatter. Further, a local area where the portrait is located can be specified as the deformation area, and only the deformation area is horizontally stretched, so that while the portrait is deformed, the deformation of surrounding objects is not affected as much as possible. Based on this principle, the figure of the portrait in the image can be beautified. There are many image processing frameworks that support image deformation. The following further details the algorithm steps based on OpenGL.

[0074] 1. Input the original image to be decoded to obtain image data, and load it into a texture P suitable for OpenGL rendering, and record the image width and height as w*h;

[0075] 2. Input the horizontal normalized coordinates left and right of the deformation area, indicating that [left, right] is the deformation area;

[0076] 3. Input the stretching strength value scale, and the reference value range is [0.9~1.1]. This value represents the scaling ratio of the width of the deformation area. If it is greater than 1, the width is expanded, and if it is less than 1, the width is reduced;

[0077] 4. Calculate the width tw of the target image after deformation as tw = w - w*(right - left)*(1.0 - scale), and the image height remains unchanged;

[0078] 5. Calculate the horizontal normalized coordinates of the deformation area after deformation;

[0079] tleft = left*w / tw;

[0080] tright = 1.0 - (1.0 - right)*w / tw;

[0081] 6. Construct the vertex coordinates and texture coordinates for OpenGL rendering, and the mapping relationship is as follows

[0082]

[0083] Among them, when the vertex coordinates are assigned to the preset parameter gl_Position of the OpenGL vertex shader, they need to be mapped to the range [-1, 1]. Assuming the vertex coordinates are position, then gl_Position = vec4(position.xy*2.0 - 1.0, 0.0, 1.0);

[0084] 7. Construct OpenGL triangle primitives, which are divided as follows. There are a total of 6 triangle primitives, specifically as Figure 2 shown;

[0085] 8. After rendering by OpenGL, the deformed texture T1 is obtained. Assuming the scale is 0.9, after rendering Figure 2 it, the texture T1 is obtained. The texture T1 is as Figure 3 shown.

[0086] S103. According to the face key point data, the facial contour of the portrait optimized image is restored to the original proportion, and the pixel values around the face key point data after the restoration proportion is adjusted, so that the head and the deformed area present a smooth transition.

[0087] Specifically, after the image to be processed is stretched and deformed by the portrait body beautification, the human body shape is optimized, but at the same time, the face and head will be distorted. The head contour key points kps are detected by the face detection model, and the head area wrapped by the key points is reversely stretched, so that the head proportion remains the same as the original Figure 1 one, and at the same time, the pixels around the outer circle of the key points are adjusted to make the head and the deformed area smoothly transition. The algorithm steps are further refined based on OpenGL below. Specifically, it includes:

[0088] 1. Input the original image. The head contour key points kps are detected by the first detection and positioning module, and the key points are arranged in a counterclockwise direction;

[0089] 2. Calculate the mean value of all key points kps to obtain the head center point center;

[0090] 3. Construct the outer protection points ops. The number of ops points is the same as that of kps and they correspond one by one. For each point op in ops and the corresponding point kp in kps, there is op = center+(kp - center)*k, where k is the scaling factor, and the value range must be greater than 1. In the present invention, k is taken as 1.3. The circular area formed by the outer protection points ops and the head contour key points kps is the smooth transition area between the head and the deformed area;

[0091] 4. Calculate the coordinates of all points after deformation by the portrait body beautification module, including the deformed face key points tkps, the deformed outer protection points tops, and the deformed head center point tcenter;

[0092] For each deformed point tp and the corresponding point p in the original image, there is

[0093] tp.x = (p.x - left) / (right - left)*(tright - tleft)+tleft;

[0094] tp.y = p.y;

[0095] 5. Construct texture coordinates [tcenter, tkps, tops] for OpenGL rendering;

[0096] 6. Construct vertex coordinates [vcenter, vkps, vops] for OpenGL rendering, where

[0097] vcenter = tcenter;

[0098] The number of points in vkps is the same as that in tkps and they correspond one by one. For each point vkp in vkps and the corresponding point tkp in tkps, there is vkp.x = tcenter.x + (tkp.x - tcenter.x) * (1.0 / scale); vkp.y = tkp.y; where scale is the stretching intensity value in the body beautification module. It should be noted that tkps refers to the texture coordinates corresponding to the facial key points, which determines the texture sampling position, and vkps refers to the vertex coordinates corresponding to the facial key points, which determines the viewport drawing position. The deformation effect can be achieved by using the difference between the texture coordinates and the vertex coordinates.

[0099] vops = tops;

[0100] In addition, when assigning the vertex coordinates to the OpenGL vertex shader preset parameter gl_Position, it needs to be mapped to the range of [-1, 1]. Assuming the vertex coordinate is position, then gl_Position = vec4(position.xy * 2.0 - 1.0, 0.0, 1.0);

[0101] 7. Construct OpenGL triangle primitives. Each two adjacent points of tcenter and tkps form a triangle primitive, and each two corresponding adjacent points of tkps and vops form two triangle primitives. The head example diagram is as Figure 4 shown;

[0102] 8. Input texture T1, and after OpenGL rendering, texture T2 is obtained. Assuming scale is 0.9, the head example diagram of T2 is obtained, as Figure 5 shown.

[0103] It should be noted that there are multiple human bodies in a single image, and there is a situation where multiple heads need to prevent distortion. For multiple heads, they are processed in two cases. ① When the distance between multiple head regions is large, the regions do not intersect, or the intersection degree is small, the deformed texture T1 can be processed through Module 4 in sequence to obtain the anti-distortion results of multiple heads. ② When the distance between multiple head regions is small and the intersection degree is large, multiple head regions with an intersection degree reaching a preset value are merged to form a set of contour key points containing multiple heads, and the key points are arranged in a counterclockwise direction. Then, the deformed texture T1 is processed through Module 4 in sequence to obtain the anti-distortion results of multiple heads.

[0104] As Figure 6 shown, an embodiment of the present application provides an image processing device for preventing head distortion, including:

[0105] A face recognition module 201, configured to input an image to be processed into a pre-constructed face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of facial features and facial contours in the image to be processed;

[0106] A portrait optimization module 202, configured to determine a local area of the image to be processed as a deformed area, and adjust the deformed area according to a preset ratio to obtain a portrait optimized image;

[0107] A head anti-distortion module 203, configured to restore the facial contour of the portrait optimized image to the original ratio according to the face key point data, and adjust the pixel values around the face key point data after restoration to make the head and the deformed area present a smooth transition.

[0108] The working principle of the image processing device for preventing head distortion provided by the embodiment of the present application is that the face recognition module 201 inputs the image to be processed into the pre-constructed face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two-dimensional coordinates of facial features and facial contours in the image to be processed; the portrait optimization module 202 determines a local area of the image to be processed as a deformed area, and adjusts the deformed area according to a preset ratio to obtain a portrait optimized image; the head anti-distortion module 203 restores the facial contour of the portrait optimized image to the original ratio according to the face key point data, and adjusts the pixel values around the face key point data after restoration to make the head and the deformed area present a smooth transition.

[0109] In some embodiments, it further includes:

[0110] A detection and positioning module, configured to identify the image to be processed through the face recognition model;

[0111] If there is a human face in the image to be processed, output the facial key point data; otherwise, end the process.

[0112] In summary, the present invention provides an image processing method and apparatus for preventing head distortion. The technical solution provided in this application combines facial key point recognition, body key point recognition, portrait area discrimination, distortion and anti-distortion, and invents a one-key automatic beautification function for photo body correction, which can automatically locate the key body areas and optimize the shapes of areas such as the neck, shoulders, chest, and waist through algorithms such as image distortion and stretching. At the same time, although the one-key beautification function for portrait body can facilitate user use, it also specifically introduces protective measures for preventing head distortion for the head and face to ensure a real and beautiful effect.

[0113] It can be understood that the method embodiments provided above correspond to the apparatus embodiments above, and the corresponding specific contents can be referred to each other and will not be elaborated here.

[0114] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0115] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the processes and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0116] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction method that implements the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0117] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are executed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions for implementing the steps of the function specified in one process or a plurality of processes and / or blocks Figure 1 one process or a plurality of processes and / or blocks Figure 1 in one block or a plurality of blocks.

[0118] As described above, only the specific embodiments of the present invention are provided, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. An image processing method for preventing head distortion, characterized in that, Including: Input the image to be processed into a pre - built face recognition model to obtain face information; the face information includes face key point data; the face key point data includes the two - dimensional coordinates of facial features and the facial contour in the image to be processed; Determine a local area of the image to be processed as the deformation area, and adjust the deformation area according to a preset ratio to obtain an optimized portrait image; Restore the facial contour of the optimized portrait image to the original ratio according to the face key point data, and adjust the pixel values around the face key point data after restoration of the ratio, so that the head and the deformation area show a smooth transition. Among them, adjusting the pixel values around the face key point data after restoration of the ratio so that the head and the deformation area show a smooth transition includes: Calculate the mean value of all face key points kps to obtain the head center point center; Construct an outer protection point ops. The number of outer protection points ops is the same as that of face key points kps and they correspond one by one. For each point op in the outer protection point ops and the corresponding point kp of the face key point kps, there is the following relationship: op = center+(kp - center)*k; Where k is a scaling factor, and its value range must be greater than 1. The circular area formed by the outer protection point ops and the face key point kps is the smooth transition area between the head and the deformation area; Calculate all point coordinates of the optimized portrait image, including the deformed face key points tkps, the deformed outer protection points tops, and the deformed head center point tcenter; For each deformed point tp and the corresponding point p of the image to be processed, there is the following relationship; tp.x=(p.x - left) / (right - left)*(tright - tleft)+tleft; tp.y = p.y; Construct texture coordinates [tcenter, tkps, tops] for OpenGL rendering; Construct vertex coordinates [vcenter, vkps, vops] for OpenGL rendering; Where, vcenter = tcenter; The number of vertex coordinates vkps is the same as that of the deformed face key points tkps and they correspond one by one. For each point vkp in vkps and the corresponding point tkp of tkps, there is the following relationship: vkp.x = tcenter.x+(tkp.x - tcenter.x)*(1.0 / scale); vkp.y = tkp.y; Where scale is the stretching intensity value in the body beautification module; vops = tops; In addition, when assigning vertex coordinates to the preset parameter gl_Position of the OpenGL vertex shader, it needs to be mapped to the range of [-1, 1]; Construct OpenGL triangle primitives. Each two adjacent points of tcenter and tkps form a triangle primitive, and each two corresponding adjacent points of tkps and vops form two triangle primitives; Input texture T1, and obtain texture T2 after OpenGL rendering.

2. The method according to claim 1, wherein Determining a local area of the image to be processed as a deformation area, and adjusting the deformation area according to a preset ratio to obtain a portrait optimization image, including: Decoding the image to be processed to obtain decoded image data, processing the image data to obtain a texture P suitable for OpenGL rendering, and recording the width and height of the image texture; Determining the horizontal normalized coordinates of the deformation area, and representing the deformation area using the normalized coordinates; Stretching the deformation area according to a preset stretching intensity value to obtain the width of the deformed target image; wherein, the height of the image to be processed remains unchanged; Determining the horizontal normalized coordinates of the width of the target image; Constructing vertex coordinates and texture coordinates for OpenGL rendering, and the mapping relationship between the vertex coordinates and the texture coordinates; wherein, when the vertex coordinates are assigned to the preset parameters of the OpenGL vertex shader, they need to be mapped to the range of [-1, 1]; Constructing OpenGL triangle primitives according to the mapping relationship between the vertex coordinates and the texture coordinates; Rendering the texture P according to the OpenGL triangle primitives to obtain a deformed texture T1.

3. The method according to claim 1, wherein The original ratio restoration of the facial contour of the portrait optimization image according to the facial key point data includes: Performing reverse stretching on the facial contour of the portrait optimization image according to the facial key point data; Wherein the facial contour is the head area wrapped by the facial key point data.

4. The method according to claim 1, wherein Further includes: The face recognition model recognizes the image to be processed; If there is a face in the image to be processed, outputting facial key point data; Otherwise, end the process.

5. The method according to claim 1, wherein When there are multiple heads in the input image, perform anti-distortion processing on each head in sequence until the last head.

6. The method according to claim 2, wherein The value range of the stretching intensity value is 0.9 to 1.1, and the stretching intensity value represents the scaling factor of the width of the deformation area. If it is greater than 1, the width expands; if it is less than 1, the width shrinks.

7. An image processing device for preventing head distortion, characterized in that, Includes: A face recognition module, configured to input the image to be processed into a pre-constructed face recognition model to obtain face information; the face information includes facial key point data; the facial key point data includes the two-dimensional coordinates of the facial features and the facial contour in the image to be processed; A portrait optimization module, configured to determine a local area of the image to be processed as a deformation area, and adjust the deformation area according to a preset ratio to obtain a portrait optimization image; A head anti-distortion module, configured to restore the original ratio of the facial contour of the portrait optimization image according to the facial key point data, and adjust the pixel values around the facial key point data after restoring the ratio, so that the head and the deformation area present a smooth transition. Among them, adjusting the pixel values around the facial key point data after restoring the ratio so that the head and the deformation area present a smooth transition includes: Calculating the average value of all facial key points kps to obtain the head center point center; Construct the outer protection points ops. The number of the outer protection points ops is the same as that of the face key points kps and they correspond one by one. For each point op in the outer protection points ops and the corresponding point kp in the face key points kps, the following relationship exists: op = center + (kp - center) * k; where k is the scaling factor and its value range must be greater than 1. The circular region formed by the outer protection points ops and the face key points kps is the smooth transition region between the head and the deformation region; Calculate all the point coordinates of the optimized portrait image, including the deformed face key points tkps, the deformed outer protection points tops, and the deformed head center point tcenter; For each deformed point tp and the corresponding point p in the image to be processed, the following relationship exists; tp.x = (p.x - left) / (right - left) * (tright - tleft) + tleft; tp.y = p.y; Construct the texture coordinates [tcenter, tkps, tops] for OpenGL rendering; Construct the vertex coordinates [vcenter, vkps, vops] for OpenGL rendering; where, vcenter = tcenter; The number of the vertex coordinates vkps is the same as that of the deformed face key points tkps and they correspond one by one. For each point vkp in vkps and the corresponding point tkp in tkps, the following relationship exists: vkp.x = tcenter.x + (tkp.x - tcenter.x) * (1.0 / scale); vkp.y = tkp.y; where scale is the stretching intensity value in the body beautification module; vops = tops; In addition, when assigning the vertex coordinates to the preset parameter gl_Position of the OpenGL vertex shader, it needs to be mapped to the range of [-1, 1]; Construct the OpenGL triangle primitives. Each two adjacent points of tcenter and tkps form a triangle primitive, and each two corresponding adjacent points of tkps and vops form two triangle primitives; Input the texture T1, and obtain the texture T2 after OpenGL rendering.

8. The device according to claim 7, characterized in that It also includes: A detection and positioning module for identifying the image to be processed through a face recognition model; If there is a face in the image to be processed, output the face key point data; otherwise, end the process.

Citation Information

Patent Citations

  • Method and device for enhancing three-dimensional sense of five sense organs of portrait in photo

    CN112150387A

  • Face distortion correction method and device, electronic equipment, chip and storage medium

    CN113870148A