Portrait picture generation method, device and computer equipment
By detecting the face area in the video frame and triggering face beautification instructions, face beautification, background replacement and size/angle adjustment are performed, the problem of low processing efficiency of traditional image processing software is solved, and efficient portrait image processing is achieved.
Patent Information
- Application Number
- CN201910344489.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-26
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2040-03-07
AI Technical Summary
Traditional image processing software has cumbersome processing steps for portrait images and requires high picture quality, resulting in low processing efficiency.
A portrait image generation method is provided, which triggers face beautification instructions when detecting face areas in video frames, performs face beautification, background replacement and size/angle adjustment to generate target result maps.
It improves the efficiency of portrait images, allowing users to obtain beautified video frames in real time, select satisfactory target portrait photos, and automatically replace and adjust the background.
Smart Images

Figure CN110047053B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device and computer equipment for generating a portrait image. Background Art
[0002] As people's demand for photos of various forms increases, people often choose to go to professional studios to have their photos taken. For example, when people need ID photos, they will go to professional studios, which can provide the scenes required for ID photos and have professionals to take ID photos, so that people can get ID photos in standard forms. However, going to professional studios to take photos is very expensive.
[0003] With the development of computer technology, various image processing software have emerged, such as Adobe Photoshop (abbreviated as "PS"). People do not need to go to professional studios. They can use PS software at home to perform a series of processing on portrait images and get the desired images.
[0004] However, the processing steps of traditional image processing software for portrait images are too complicated, and the requirements for imported portrait images are high. If the user has a low level of mastery of image processing software and the quality of the imported portrait photos is poor, it will cause the user to spend a lot of time processing the pictures, and the final pictures may not be ideal, resulting in low efficiency in portrait picture processing. Summary of the invention
[0005] Based on this, it is necessary to provide a portrait image generation method, device, computer-readable storage medium and computer equipment that can improve the processing efficiency of portrait images in order to address the above problems.
[0006] A method for generating a portrait image, comprising:
[0007] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0008] Performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification;
[0009] Select a target video frame from the face beautified video frames to obtain a target portrait image;
[0010] The background area in the target portrait image is replaced with a specified background, and the size and angle of the target portrait image are adjusted to obtain and display a target result image corresponding to the target portrait image.
[0011] A portrait image processing device, the device comprising:
[0012] The command trigger module is used to trigger the face beautification command when there is a face area in the input video frame;
[0013] A face beautification module, used for performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification;
[0014] The image acquisition module is used to select a target video frame from the video frames after face beautification to obtain a target portrait image;
[0015] The result image generation module is used to replace the background area in the target portrait image with a specified background, and adjust the size and angle of the target portrait image to obtain a target result image corresponding to the target portrait image.
[0016] A computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the following steps:
[0017] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0018] Performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification;
[0019] Select from the video frames after face beautification to obtain the target portrait image;
[0020] The background area in the target portrait image is replaced with a specified background, and the size and angle of the target portrait image are adjusted to obtain a target result image corresponding to the target portrait image.
[0021] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the following steps:
[0022] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0023] Performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification;
[0024] Select a target video frame from the face beautified video frames to obtain a target portrait image;
[0025] The background area in the target portrait image is replaced with a specified background, and the size and angle of the target portrait image are adjusted to obtain a target result image corresponding to the target portrait image.
[0026] The above-mentioned portrait picture generation method, device, computer-readable storage medium and computer equipment, when there is a face area in the input video frame, will beautify the face of the portrait picture formed by the video frame, so that a beautified video frame can be obtained. Select the target video frame from the video frame after face beautification to obtain the target portrait picture, automatically replace the background area in the target portrait picture with the specified background, and adjust the size and angle of the target portrait picture to obtain the target result map corresponding to the target portrait picture. Using the scheme provided by the present application, when the user takes a portrait photo, the video frame after face beautification can be obtained in real time, so that the most satisfactory target portrait photo can be selected from the video frame after face beautification. And the obtained target portrait picture is automatically adjusted, so that the target result map corresponding to the target portrait picture can be efficiently generated, thereby improving the processing efficiency of the portrait picture.
[0027] A method for generating a portrait image, the method further comprising:
[0028] Performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image;
[0029] Based on the segmented binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image;
[0030] The target portrait picture is adjusted to a horizontal position, and the size of the target portrait picture adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait picture;
[0031] A target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
[0032] A portrait image processing device, the device comprising:
[0033] A portrait segmentation module, used to perform portrait segmentation on a target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image;
[0034] A background replacement module, used to replace the background area in the target portrait image with a specified background based on the segmented binary image, to obtain a first temporary portrait image;
[0035] A picture adjustment module, used for adjusting the target portrait picture to a horizontal position, and adjusting the size of the target portrait picture adjusted to the horizontal position according to a preset template to obtain a second temporary portrait picture;
[0036] A result image determining module is used to determine a target result image corresponding to the target portrait image based on the first temporary portrait image and the second temporary portrait image.
[0037] A computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the following steps:
[0038] Performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image;
[0039] Based on the segmented binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image;
[0040] The target portrait picture is adjusted to a horizontal position, and the size of the target portrait picture adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait picture;
[0041] A target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
[0042] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the following steps:
[0043] Performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image;
[0044] Based on the segmented binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image;
[0045] The target portrait picture is adjusted to a horizontal position, and the size of the target portrait picture adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait picture;
[0046] A target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
[0047] The above-mentioned portrait picture generation method, device, computer-readable storage medium and computer equipment segment the target portrait picture into a segmented binary image, and replace the background area of the target portrait with a specified background based on the segmented binary image to obtain a first temporary portrait picture. After adjusting the target portrait picture to a horizontal position, the size of the target portrait picture is adjusted according to a preset template to obtain a second temporary portrait picture. In this way, the target result image corresponding to the target portrait picture can be determined based on the first temporary portrait picture and the second temporary portrait picture. With the solution provided by the present application, the portrait picture can be automatically processed and the target result image corresponding to the portrait picture is generated, which improves the processing efficiency of the portrait picture.
[0048] A method for generating a portrait image, comprising:
[0049] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0050] Determining a portrait image formed by the video frame according to the face beautification instruction;
[0051] Performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image;
[0052] The portrait image is respectively fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images;
[0053] The video frame after face beautification is determined based on the skin smoothing result image, the deformation result image and the whitening result image.
[0054] A portrait image processing device, the device comprising:
[0055] A beautification instruction triggering module is used to trigger a face beautification instruction when a face area exists in an input video frame;
[0056] A portrait picture determination module, used to determine the portrait picture formed by the video frame according to the face beautification instruction;
[0057] A portrait picture processing module, used to perform edge-preserving filtering, deformation processing and color mapping processing on the portrait picture to obtain a filtered picture, a deformation result picture and a mapped picture;
[0058] An image fusion module is used to fuse the portrait image with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images respectively;
[0059] The target video frame determination module is used to determine the video frame after face beautification based on the skin smoothing result image, the deformation result image and the whitening result image.
[0060] A computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the following steps:
[0061] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0062] Determining a portrait image formed by the video frame according to the face beautification instruction;
[0063] Performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image;
[0064] The portrait image is respectively fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images;
[0065] The video frame after face beautification is determined based on the skin smoothing result image, the deformation result image and the whitening result image.
[0066] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the following steps:
[0067] When there is a face area in the input video frame, the face beautification instruction is triggered;
[0068] Determining a portrait image formed by the video frame according to the face beautification instruction;
[0069] Performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image;
[0070] The portrait image is respectively fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images;
[0071] The video frame after face beautification is determined based on the skin smoothing result image, the deformation result image and the whitening result image.
[0072] The above-mentioned portrait image generation method, device, computer-readable storage medium and computer equipment, as long as there is a face area in the input video frame, will perform edge-preserving filtering, deformation processing and color mapping processing on the portrait image formed by the video frame to obtain a beautified video frame. Using the solution provided by the present application, when the user takes a portrait photo, a video frame with beautified face can be obtained in real time, so that the most satisfactory target portrait photo can be selected from the video frame with beautified face, thereby improving the quality of the target portrait photo. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 is a structural block diagram of a computer device in one embodiment;
[0074] Figure 2 A schematic diagram of a process of generating a portrait image in an embodiment;
[0075] Figure 3 This is an example diagram of a portrait image subjected to edge-preserving filtering in one embodiment;
[0076] Figure 4 An example diagram of a portrait image subjected to color mapping in one embodiment;
[0077] Figure 5 This is an example diagram of a portrait image that is deformed in one embodiment;
[0078] Figure 6 This is an example diagram of a target portrait image for portrait segmentation in one embodiment;
[0079] Figure 7 An example diagram of a target portrait image with angle and size adjustment in one embodiment;
[0080] Figure 8 is a schematic diagram of a flow chart of a method for generating a portrait image in another embodiment;
[0081] Fig. 9 This is an example diagram of a shooting interface in an embodiment;
[0082] Fig.10 This is an example diagram of a shooting interface in another embodiment;
[0083] Fig.11 An example diagram of a target result graph generation interface in one embodiment;
[0084] Fig.12 An example diagram of a target result graph generation interface in another embodiment;
[0085] Fig.13 An example diagram of a target result graph generation interface in yet another embodiment;
[0086] Fig.14 An example diagram of a saving interface in an embodiment;
[0087] Fig.15 A schematic diagram of a process of generating a portrait image in another embodiment;
[0088] Fig.16 A schematic diagram of a process of generating a portrait image in another embodiment;
[0089] Fig.17 is a structural block diagram of a portrait image processing device in one embodiment;
[0090] Fig.18 is a structural block diagram of a portrait image processing device in another embodiment;
[0091] Fig.19 FIG. 4 is a structural block diagram of a portrait image processing device in yet another embodiment. DETAILED DESCRIPTION
[0092] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0093] The portrait image generation method provided in this application can be applied to Figure 1 The terminal 100 shown. The terminal 100 includes a memory, a processor, a network interface, a display screen, and an input device. A computer program is stored in the memory, and when the computer program is executed by the processor, the portrait image generation method provided by the present application can be implemented. The terminal can be a desktop terminal or a mobile terminal, and the mobile terminal can be at least one of a mobile phone, a tablet computer, a laptop computer, a portable wearable device, etc.
[0094] like Figure 2 As shown, in one embodiment, a method for generating a portrait image is provided. This embodiment mainly applies the method to the above Figure 1 The terminal 100 in FIG. Figure 2 , the portrait image generation method specifically includes the following steps:
[0095] S202: When there is a face area in the input video frame, a face beautification instruction is triggered.
[0096] The face area refers to an area where a face exists.
[0097] Specifically, an application with portrait image processing and shooting functions may be installed on the terminal. When the terminal detects that the shooting function of the application is turned on, it jumps to the shooting interface corresponding to the application and obtains the real-time input video frame through the system camera. The terminal detects the picture content of each video frame input in real time, and detects whether there is a face area in the picture content of each input video frame. When the terminal detects that there is a face area in the picture content of the input video frame, it means that the terminal needs to perform face beautification processing on the video frame, and the terminal triggers the face beautification instruction.
[0098] In one embodiment, the terminal detects whether there is a face area in the picture content of each input video frame, which can be a face key point detection on the picture content of each video frame. Face key point detection refers to the detection that can locate the key area position of the face, such as the eyebrow area, eye area, nose area, mouth area, facial contour, etc. The face key point refers to the point used to locate the key area position of the face. When the terminal detects the face key point from the input video frame, the terminal can determine that there is a face area in the video frame.
[0099] S204, performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification.
[0100] Among them, portrait pictures refer to pictures that include the face area.
[0101] Specifically, the face beautification instruction may carry at least one default beautification method, and each default beautification method has corresponding default beautification parameters. The terminal may beautify the portrait image formed by the video frame according to the default beautification parameters corresponding to the default beautification method. It is understandable that when the face beautification instruction carries more than one default beautification method, the terminal may beautify the portrait image formed by the video frame multiple times according to the multiple default beautification methods carried by the face beautification instruction. The video frame after face beautification may be displayed on the shooting interface.
[0102] In one embodiment, for example, a face beautification instruction carries a first default beautification method, a second default beautification method, and a third default beautification method, the terminal determines the first default beautification parameter, the second default beautification parameter, and the third default beautification parameter corresponding to the first default beautification method, the second default beautification method, and the third default beautification method, respectively, and performs three beautification processes on the portrait picture formed by the video frame with the face area according to the determined first default beautification parameter, the second default beautification parameter, and the third default beautification parameter.
[0103] In one embodiment, when the terminal does not detect a face region in the picture content of the real-time input video frame, the video frame without the face region is directly displayed on the terminal's shooting interface. For example, the picture content of the real-time input video frame A obtained by the terminal through the system camera contains a face region, and the picture content of the real-time input video frame B does not contain a face region. The terminal only needs to beautify the portrait image formed by the video frame A according to the default beautification parameters corresponding to the default beautification method, and display the target video frame a obtained after beautification on the terminal's shooting interface. For video frame B, the terminal does not need to do any processing on it, and directly displays video frame B on the terminal's shooting interface.
[0104] S206, selecting a target video frame from the face beautified video frames to obtain a target portrait image.
[0105] The target portrait image refers to the portrait image formed by the target video frame.
[0106] Specifically, the terminal may be provided with a shooting button. When the display screen of the terminal is a touch display screen, the shooting button may be a virtual shooting button provided in the shooting interface displayed by the terminal. It is understandable that the shooting button may also be any physical shooting button preset in the terminal. When the terminal detects that the shooting button is triggered, the terminal starts to acquire the video frame after face beautification. When the terminal detects that the shooting button is triggered again, the acquisition of the video frame after face beautification is stopped, and the target video frame is automatically selected from the acquired multiple video frames after face beautification to obtain the target portrait picture formed by the target video frame.
[0107] Of course, when the terminal detects that the shooting button is triggered, the video frame with beautified face displayed by the terminal when the shooting button is triggered can be directly determined as the target video frame to obtain the target portrait image formed by the target video frame.
[0108] S208, replacing the background area in the target portrait image with the specified background, and adjusting the size and angle of the target portrait image to obtain a target result image corresponding to the target portrait image.
[0109] The background area refers to the non-portrait area in the target portrait image.
[0110] Specifically, the terminal can perform portrait recognition on the target portrait picture, and identify the background area and foreground area in the target portrait picture. The foreground area refers to the portrait area in the target portrait picture. The foreground area in the identified target portrait picture is cut out, and the background area in the target portrait picture is replaced with the specified background to complete the background replacement. The terminal adjusts the target portrait picture to a horizontal angle, and adjusts the size of the target portrait picture according to the size parameters corresponding to the preset template, obtains and displays the target result image corresponding to the target portrait picture. Furthermore, the terminal can jump to the target result image generation interface after triggering the shooting command, and display the obtained target result image on the target result image generation interface.
[0111] The above-mentioned portrait image generation method, when there is a face area in the input video frame, will beautify the face of the portrait image formed by the video frame, so that a beautified video frame can be obtained. A target video frame is selected from the video frame after face beautification to obtain a target portrait image. The background area in the target portrait image is automatically replaced with a specified background, and the size and angle of the target portrait image are adjusted to obtain a target result image corresponding to the target portrait image.
[0112] By adopting the scheme provided by the present application, when a user takes a portrait photo, a video frame after face beautification can be obtained in real time, so that the most satisfactory target portrait photo can be selected from the video frame after face beautification. And the target portrait picture taken can be automatically adjusted, so that a target result image corresponding to the target portrait picture can be efficiently generated, thereby improving the processing efficiency of the portrait picture.
[0113] In one embodiment, face beautification is performed on a portrait image formed by a video frame according to a face beautification instruction to obtain a video frame after face beautification, including: determining a portrait image formed by a video frame according to the face beautification instruction; performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image to obtain a filtered image, a deformation result image and a mapped image; fusing the portrait image with the filtered image and the mapped image to obtain corresponding skin smoothing result images and whitening result images; determining a video frame after face beautification corresponding to the video frame based on the skin smoothing result image, the deformation result image and the whitening result image.
[0114] Among them, edge-preserving filtering refers to a special type of filtering that can effectively retain the edge information in the portrait image during the filtering process. Edge-preserving filtering includes bilateral filtering, guided filtering, weighted least squares filtering or mean filtering. Deformation processing refers to the processing used to deform the portrait area in the portrait image. Color mapping processing refers to the process of mapping the color value of the portrait image to obtain a new color value. The color value refers to the RGB value of each pixel, R represents red, G represents green, and B represents blue.
[0115] Specifically, the terminal determines a portrait image formed by a video frame containing a face area input in real time according to the face beautification instruction. The terminal performs edge-preserving filtering on the portrait image to obtain a filtered image. In order to avoid excessive skin smoothing, the terminal may preset a first color value weight of the portrait image and a second color value weight of the filtered image. The terminal coordinates and fuses the portrait image and the filtered image based on the first color value weight and the second color value weight to obtain a corresponding skin smoothing result image.
[0116] The terminal performs color mapping on the portrait image to obtain a mapped image. In order to avoid excessive whitening, the terminal can coordinate and fuse the portrait image and the mapped image based on the first color value weight and the second color value weight to obtain a corresponding whitening result image. The terminal can deform the face image based on the deformation parameter to obtain a deformation result image. The terminal can determine and display the video frame after face beautification based on the obtained skin smoothing result image, deformation result image and whitening result image.
[0117] like Figure 3 As shown, in one embodiment, for example, the portrait image formed by the currently input video frame is a portrait image 301, and after the terminal performs edge-preserving filtering on the portrait image 301, a filtered image 302 can be obtained. Based on the first color value weight corresponding to the portrait image 301 and the second color value weight corresponding to the filtered image 302, the terminal fuses the portrait image 301 and the filtered image 302 to obtain a skin resurfacing result image 303.
[0118] like Figure 4 As shown, in one embodiment, for example, the portrait picture formed by the currently input video frame is a portrait picture 401, and after the terminal performs color mapping processing on the portrait picture 401, a mapped picture 402 can be obtained. Based on the first color value weight corresponding to the portrait picture 401 and the second color value weight corresponding to the mapped picture 402, the terminal merges the portrait picture 401 and the mapped picture 402 to obtain a whitening result picture 403.
[0119] In one embodiment, the terminal performs color mapping processing on the portrait image, including the following steps: determining the color value (R value, G value and B value) of each pixel in the portrait image, searching the target color value corresponding to the color value of each pixel from the color lookup table, and determining the mapped image according to the target color value. The grayscale value corresponding to the color value of each pixel is less than the grayscale value corresponding to the target color value. Furthermore, the color lookup table can be implemented using a LUT (Look-Up-Table display lookup table).
[0120] In one embodiment, the edge-preserving filtering processing performed by the terminal on the portrait image may specifically be a mean filtering processing, and the mean filtering processing performed by the terminal on the portrait image includes: determining 8 pixels around each pixel in the portrait image; calculating the average color value of the 8 pixels around each pixel; and adjusting the color value of each pixel to the average color value of the 8 pixels around the pixel.
[0121] In the above embodiment, the face beautification of the real-time input video frame is performed and displayed by performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image, thereby achieving real-time face beautification of the video frame. When the user takes a portrait photo, the target video frame after face beautification can be obtained, so that the user can obtain a satisfactory target portrait photo, thereby improving the quality of the target portrait photo.
[0122] In one embodiment, deformation processing of a portrait image includes the following steps: identifying facial key points in the portrait image; determining the deformed target key points corresponding to each facial key point based on deformation parameters; and shifting each facial key point to the corresponding target key point.
[0123] Specifically, the terminal can identify the portrait image through a preset face recognition interface to obtain the face key points in the portrait image. The terminal is provided with deformation parameters for the face key points, and the terminal performs a shift operation on each face key point based on the deformation parameter to obtain the target key point after the shift operation of each face key point. The terminal shifts each face key point in the portrait image to the corresponding target key point to obtain a deformation result map.
[0124] like Figure 5 As shown, in one embodiment, for example, the portrait picture formed by the currently input video frame is a portrait picture 501, and the terminal recognizes the portrait picture through a preset face recognition interface to obtain the face key points in the portrait picture, such as the black dots in the shift operation picture 502. The terminal performs a shift operation on each face key point based on the deformation parameter to obtain the target key point after the shift operation on each face key point, such as the white dot in the shift operation picture 502. The terminal shifts each face key point in the portrait picture 501 to the corresponding target key point, and obtains the deformation result picture 503. The deformation-based detail fine-tuning of the portrait picture, such as thin face and big eyes, is completed.
[0125] In the above embodiment, the terminal shifts the key points of the face in the portrait image based on the deformation parameters, and can automatically deform the portrait image without the user manually deforming the portrait image, making the processing of the face image more efficient.
[0126] In one embodiment, selecting a target video frame from the face-beautified video frames to obtain a target portrait image includes: selecting a target video frame that meets automatic screening conditions from the face-beautified video frames to obtain a target portrait image; or, when a shooting instruction is triggered, selecting the face-beautified video frame displayed when the shooting instruction is triggered as the target video frame to obtain the target portrait image.
[0127] Among them, the automatic screening condition refers to the screening condition for screening the video frames after face beautification. The screening conditions include, for example, that the ratio of the face area and the non-face area in the video frame after face beautification reaches the standard ratio, that the inclination of the face area in the video frame after face beautification falls within the deviation range, etc. The shooting instruction refers to the instruction for taking a photo. For example, the display interface of the terminal displays a shooting button, and when the terminal detects that the shooting button is triggered, the shooting instruction is triggered.
[0128] Specifically, when the terminal detects that the shooting button is triggered, it starts to acquire the video frame after face beautification. When the terminal detects that the shooting button is triggered again, it stops acquiring the video frame after face beautification and determines the automatic screening condition. The terminal screens the acquired video frame after face beautification according to the automatic screening condition, obtains the target video frame that meets the automatic screening condition, and determines the target portrait image formed by the obtained target video frame.
[0129] Alternatively, when the terminal detects that the shooting button is triggered, the shooting instruction is triggered. When the terminal detects that the shooting instruction is triggered, the video frame after face beautification displayed in the shooting interface when the shooting instruction is triggered is automatically selected as the target video frame, and the target portrait picture formed by the target video frame is determined. It is understandable that when the terminal detects that the shooting button is triggered, the terminal still needs to perform face beautification on the portrait picture formed by the video frame input through the camera according to the default beautification parameters corresponding to the default beautification method. In this way, the target portrait picture selected by the terminal is the default portrait picture that has been beautified.
[0130] In one embodiment, selecting a target video frame that meets the automatic screening conditions from the face-beautified video frames to obtain a target portrait image includes: inputting the face-beautified video frames into a trained automatic screening model to obtain a target video frame that meets the automatic screening conditions to obtain a target portrait image.
[0131] Specifically, the automatic screening model is a pre-trained model, and the training of the model can be based on multiple video frames including face regions and target video frames therein to train the initial model. When multiple video frames including face regions are input into the initial model and the initial model can accurately output the target video frame therein, the training is stopped to obtain the automatic screening model.
[0132] In one embodiment, a background area in a target portrait image is replaced with a specified background, and the size and angle of the target portrait image are adjusted to obtain a target result image corresponding to the target portrait image, including: inputting the target portrait image into a trained portrait segmentation model to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes the background area of the target portrait image; based on the segmentation binary image, the background area in the target portrait image is replaced with the specified background to obtain a first temporary portrait image; the target portrait image is adjusted to a horizontal position, and the size of the target portrait image adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait image; and the target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
[0133] The segmented binary image refers to an image containing only two gray levels, and the gray value of each pixel in the segmented binary image has no intermediate transition, so that each pixel is either black or white.
[0134] Specifically, the terminal can input the target portrait picture into a trained portrait segmentation model, perform portrait segmentation on the target portrait picture through the portrait segmentation model, and obtain a segmentation binary image of the target portrait picture. The obtained segmentation binary image contains a foreground area and a background area. The foreground area corresponds to the portrait area in the target portrait picture, and the background area corresponds to the non-portrait area in the target portrait picture. Based on the correspondence between the segmentation binary image and the target portrait picture, the terminal replaces the non-portrait area of the target portrait picture corresponding to the background area in the segmentation binary image with the specified background to obtain a first temporary portrait picture. The specified background is, for example, the specified background corresponding to an ID photo, and the specified background corresponding to the ID photo is a background with a specified color.
[0135] The terminal can determine at least one rotation point in the target portrait picture, use the rotation point to rotate the target portrait picture to a horizontal position, and adjust the size of the target portrait picture adjusted to the horizontal position according to the standard size parameters in the preset template to obtain a second temporary portrait picture. The terminal determines a target result image corresponding to the target portrait picture in combination with the first temporary portrait picture and the second temporary portrait picture and displays it.
[0136] In one embodiment, the preset templates may specifically be preset templates corresponding to ID photos, preset templates corresponding to image photos, and preset templates corresponding to business photos. The preset templates corresponding to ID photos may include standard one-inch templates, small one-inch templates, large one-inch templates, standard two-inch templates, small two-inch templates, five-inch templates, identity card templates, residence permit templates, social security card templates, motor vehicle driver's license templates, resume templates, Chinese passport templates, Hong Kong and Macau Pass templates, European visa templates, US visa templates, and Japanese visa templates, etc.
[0137] like Figure 6As shown, in one embodiment, for example, the input target portrait picture is the target portrait picture 601, and the terminal inputs the target portrait picture 601 into the portrait segmentation model. The portrait segmentation model performs portrait segmentation on the target portrait picture 601 to obtain a temporary segmentation binary image 602. The white area in the temporary segmentation binary image 602 is the foreground area, and the black area is the background area. It can be seen that the portrait segmentation model may not obtain the most accurate segmentation binary image for the one-time image segmentation of the target portrait picture 601. The portrait segmentation model needs to refine the edge area where black and white intersect in the temporary segmentation binary image 602 to obtain a segmentation binary image 603. In this way, the terminal can perform a cutout process on the target portrait picture 601 based on the accurate segmentation binary image 603 to obtain a first temporary portrait picture 604.
[0138] In the above embodiment, the target portrait image is segmented into a segmented binary image using a portrait segmentation model, and the background area of the target portrait is replaced with a specified background based on the segmented binary image to obtain a first temporary portrait image. After the target portrait image is adjusted to a horizontal position, the size of the target portrait image is adjusted according to a preset template to obtain a second temporary portrait image. In this way, the target result image corresponding to the target portrait image can be determined based on the first temporary portrait image and the second temporary portrait image. In this way, the terminal only needs the user to provide a portrait image, and it can automatically process the portrait image and generate a target result image corresponding to the portrait image, thereby improving the processing efficiency of the portrait image.
[0139] In one embodiment, the portrait segmentation model is obtained based on full convolutional network training; the training steps of the portrait segmentation model include: dividing the samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples; training the training samples based on the full convolutional network to obtain more than one preliminary model; verifying each preliminary model according to the verification sample to obtain corresponding verification results; selecting the preliminary model corresponding to the verification result that meets the verification conditions as the portrait segmentation model.
[0140] Among them, the Fully Convolutional Networks (FCN) refers to a network model that converts the fully connected layers in the traditional convolutional neural network into convolutional layers one by one, so that all layers are convolutional layers.
[0141] Specifically, the terminal can divide the input multiple groups of samples into multiple groups of training samples and multiple groups of verification samples, and one group of samples includes a portrait picture sample and a corresponding standard segmentation binary image sample. For example, if the input samples are M groups, the terminal can divide the M groups of samples into N groups of training samples and G groups of verification samples, N+G=M. The terminal uses a full convolutional network model to train the training samples to obtain multiple preparatory models. The portrait picture samples in the verification samples are input into the obtained multiple preparatory models in sequence, and each preparatory model outputs the predicted segmentation binary image corresponding to each portrait picture sample in the verification sample.
[0142] The terminal compares the predicted segmentation binary image output by each preliminary model with the corresponding labeled segmentation binary image sample to obtain multiple deviation values. The terminal can calculate the average deviation value of each preliminary model, determine the preliminary model corresponding to the minimum average deviation value as the preliminary model that meets the verification conditions, and use the preliminary model that meets the verification conditions as the portrait segmentation model.
[0143] In the above embodiment, a preliminary model that meets the verification conditions is selected from a plurality of preliminary models as a portrait segmentation model through verification samples, so that the segmentation binary image output by the portrait segmentation model is more accurate.
[0144] In one embodiment, the target portrait image is adjusted to a horizontal position, and the size of the target portrait image adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait image, including: determining the center position of two eyes in the face area of the target portrait image; adjusting the target portrait image to a horizontal position based on the center position; and cropping and scaling the target portrait image adjusted to the horizontal position according to the preset template to obtain a second temporary portrait image.
[0145] Specifically, the terminal determines the center position of the two eyes in the face area of the target portrait image as the rotation point, and adjusts the target portrait image to a horizontal position based on the rotation point. The size adjustment performed by the terminal on the target portrait image adjusted to the horizontal position may include cropping and scaling. The terminal crops the target portrait image adjusted to the horizontal position according to the length and width corresponding to the preset template to obtain the cropped target portrait image. The terminal scales the cropped target portrait image according to the standard area corresponding to the preset template to obtain a second temporary portrait image.
[0146] like Figure 7As shown, in one embodiment, for example, the target portrait picture is a target portrait picture 701, and the terminal rotates the target portrait picture 701 to the level of both eyes based on the center position 702 of the two eyes in the face area, and obtains a target portrait picture 703 adjusted to a horizontal position. The terminal crops the target portrait picture 703 adjusted to a horizontal position according to a preset template, and obtains a cropped target portrait picture 704. The terminal scales the cropped target portrait picture 704 according to the preset template, and obtains a second temporary portrait picture 705.
[0147] In the above embodiment, the terminal adjusts the target portrait image to a horizontal position based on the center position of the two eyes in the face area of the target portrait image, and crops and scales the target portrait image adjusted to the horizontal position according to a preset template, so as to obtain a second temporary portrait image with a standard position and size. In this way, the terminal can obtain a more standard target result image based on the second temporary portrait image with a standard position and size and the first temporary portrait image.
[0148] In one embodiment, Figure 8 As shown, the method for generating a portrait image may include the following steps:
[0149] S802, obtaining real-time input video frames through the system camera.
[0150] S804: Detect facial key points on the input video frame.
[0151] Specifically, when a facial key point is detected, it is determined that the corresponding video frame has a face region, and steps S806, S808, and S810 are executed. When a facial key point is not detected, it is determined that the corresponding video frame does not have a face region, and step S814 is executed.
[0152] Step S806 includes:
[0153] S8062, performing edge-preserving filtering on the face image formed by the video frame having the face area, to obtain a filtered image.
[0154] S8064, fusing the face image and the filtered image to obtain a skin resurfacing result image.
[0155] Step S808 includes:
[0156] S8082, performing a shift operation on each facial key point based on the deformation parameter to obtain a target key point after the shift operation on each facial key point.
[0157] S8084, shifting each facial key point in the portrait image to the corresponding target key point to obtain a deformation result image.
[0158] Step S810 includes:
[0159] S8102, performing color mapping on each pixel in the portrait image based on the color lookup table to obtain a mapped image.
[0160] S8104, the portrait image is merged with the mapped image to obtain a whitening result image.
[0161] S812: Based on the skin grinding result map, the deformation result map and the whitening result map, a video frame corresponding to the video frame after face beautification is determined and displayed. Then, step S816 is executed.
[0162] Specifically, the shooting interface displayed by the terminal can be as follows: Fig. 9 As shown, the shooting area 901 of the shooting interface displays a video frame with beautified faces. The function area 902 of the shooting interface displays "Template", "Shoot" and "Beautify" buttons. When the "Template" button is clicked, the terminal displays the template types that can be selected, such as ID photo type, image photo type and business photo type, and the ID photo type is such as ID card, driver's license, etc. When the "Beautify" button is clicked, the user can manually beautify the target video frame based on the target video frame that has been automatically beautified.
[0163] like Fig.10 As shown, beautification adjustment may include face thinning adjustment, chin adjustment, eye enlargement adjustment, nose thinning adjustment, lip adjustment, etc. Of course, beautification adjustment may also include Fig.10 Other beautification adjustments not shown in the figure, such as whitening adjustment and dark circle lightening adjustment, etc. Each beautification adjustment can be set with multiple adjustment gears, for example, each beautification adjustment can include 100 adjustment gears for users to choose according to their needs. When the "shoot" button is clicked, the shooting command is triggered.
[0164] S814, directly display the video frame without the face area. Execute step S816.
[0165] S816, when it is detected that the shooting instruction is triggered, execute step S818; when it is detected that the shooting instruction is not triggered, return to step S802.
[0166] S818, turning off the system camera, and obtaining a target portrait image formed by the target video frame displayed when the shooting command is triggered.
[0167] S820, detecting whether there are facial key points in the target portrait image.
[0168] If there are facial key points in the target portrait image, execute step S822. If there are no facial key points in the target portrait image, return to step S802.
[0169] S822, detecting whether the target portrait image with facial key points meets the image specification corresponding to the preset template.
[0170] Specifically, the image specifications corresponding to the preset template are, for example, ID photo specifications. For example, the ID photo specifications include: uniform lighting, eyes looking directly at the camera, no obstructions, etc. When the target portrait image with facial key points meets the image specifications corresponding to the preset template, steps S824 and S826 are executed. When the target portrait image with facial key points does not meet the image specifications corresponding to the preset template, a failure prompt message may be displayed, and the failure prompt message is used to inform the user of the reason for the shooting failure and prompt the user to reshoot, and then return to step S802.
[0171] S824 includes:
[0172] S8242, input the target portrait image that meets the image specification corresponding to the preset template into the portrait segmentation model obtained by training based on the full convolutional network to obtain a segmentation binary image.
[0173] S8244, performing edge cutout on the target portrait image that meets the image specification corresponding to the preset template based on the segmented binary image.
[0174] S8246, replacing the background area in the target portrait image after edge cutout with a specified background to obtain a first temporary portrait image.
[0175] Step S826 includes:
[0176] S8262, based on the center position of two eyes in the face area of the target portrait image that meets the image specification corresponding to the preset template, rotate the target portrait image to the level of both eyes.
[0177] S8264, based on the facial key points in the target portrait image and in accordance with the image specification corresponding to the preset template, the target portrait image adjusted to a horizontal position is cropped.
[0178] S8266, scaling the cropped target portrait image to a specified size of a preset template to obtain a second temporary portrait image.
[0179] S828: Determine a target result image corresponding to the target portrait image by combining the first temporary portrait image and the second temporary portrait image, and display the target result image.
[0180] Specifically, the target result graph is shown in Fig.11The target result graph generation interface is shown. The "Size", "Beautify", "Background Color" and "Erase" buttons are displayed at the bottom of the target result graph generation interface, and the "Save" button is displayed at the top of the target result graph generation interface. Users can continue to edit the target result graph through the "Size", "Beautify", "Background Color" and "Erase" buttons, and save the final target result graph through the "Save" button.
[0181] When the "Size" button is clicked, as Fig.12 As shown, the terminal can display multiple sizes for users to choose from, such as standard one inch, small one inch, large one inch and standard two inches. Users can modify the size of the target result image by selecting the desired size. When the "Beautify" button is clicked, the user can manually beautify the target video frame based on the target video frame that has been automatically beautified. When the "Background Color" button is clicked, the terminal can display multiple background colors for users to choose from, and users can modify the background color of the target result image by selecting the desired background color.
[0182] When the "Erase" button is clicked, the user can edit the background area of the result map. Fig.13 As shown in the figure, in the "erase mode", the user can use the brush to replace the sub-area of the painted foreground area with the background color. In the "repair mode", the user can use the brush to replace the sub-area of the painted background area with the color of the sub-area of the adjacent foreground image. When the "Save" button is clicked, the terminal displays the following Fig.14 The save interface shown in the figure will be saved, and the final target result image will be saved to the local photo album of the terminal.
[0183] In one embodiment, Fig.15 As shown, a method for generating a portrait image is also provided, the method comprising the following steps:
[0184] S1502, performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image.
[0185] Specifically, the terminal can input the target portrait picture into the trained portrait segmentation model, perform portrait segmentation on the target portrait picture through the portrait segmentation model, and obtain a segmentation binary image of the target portrait picture. The obtained segmentation binary image contains a foreground area and a background area. The foreground area corresponds to the portrait area in the target portrait picture, and the background area corresponds to the non-portrait area in the target portrait picture.
[0186] S1504: Based on the segmented binary image, replace the background area in the target portrait image with a specified background to obtain a first temporary portrait image.
[0187] Specifically, based on the correspondence between the segmented binary image and the target portrait image, the terminal replaces the non-portrait area of the target portrait image corresponding to the background area in the segmented binary image with the specified background to obtain the first temporary portrait image. The specified background is, for example, the specified background corresponding to the ID photo, which is a background with a specified color.
[0188] like Figure 6 As shown, in one embodiment, for example, the input portrait picture is a target portrait picture 601, and the terminal inputs the target portrait picture 601 into a portrait segmentation model. The portrait segmentation model performs portrait segmentation on the target portrait picture 601 to obtain a temporary segmentation binary image 602. The white area in the temporary segmentation binary image 602 is the foreground area, and the black area is the background area. It can be seen that the portrait segmentation model may not obtain the most accurate segmentation binary image for a single image segmentation of the target portrait picture 601. The portrait segmentation model needs to refine the edge area where black and white intersect in the temporary segmentation binary image 602 to obtain a segmentation binary image 603. In this way, the terminal can perform a cutout process on the target portrait picture 601 based on the accurate segmentation binary image 603 to obtain a first temporary portrait picture 604.
[0189] S1506, adjusting the target portrait image to a horizontal position, and adjusting the size of the target portrait image adjusted to the horizontal position according to a preset template to obtain a second temporary portrait image.
[0190] Specifically, the terminal can determine at least one rotation point in the target portrait picture, use the rotation point to rotate the target portrait picture to a horizontal position, and adjust the size of the target portrait picture adjusted to the horizontal position according to the standard size parameters in the preset template to obtain a second temporary portrait picture.
[0191] Further, the terminal may determine the center position of the two eyes in the face area of the target portrait image as a rotation point, and adjust the target portrait image to a horizontal position based on the rotation point. The size adjustment performed by the terminal on the target portrait image adjusted to the horizontal position may include cropping and scaling. The terminal crops the target portrait image adjusted to the horizontal position according to the length and width corresponding to the preset template to obtain the cropped target portrait image. The terminal scales the cropped target portrait image according to the standard area corresponding to the preset template to obtain a second temporary portrait image.
[0192] In one embodiment, the preset templates may specifically be preset templates corresponding to ID photos, preset templates corresponding to image photos, and preset templates corresponding to business photos. The preset templates corresponding to ID photos may include standard one-inch templates, small one-inch templates, large one-inch templates, standard two-inch templates, small two-inch templates, five-inch templates, identity card templates, residence permit templates, social security card templates, motor vehicle driver's license templates, resume templates, Chinese passport templates, Hong Kong and Macau Pass templates, European visa templates, US visa templates, and Japanese visa templates, etc.
[0193] S1508: Determine a target result image corresponding to the target portrait image based on the first temporary portrait image and the second temporary portrait image.
[0194] Specifically, the terminal determines the target result image corresponding to the target portrait image in combination with the first temporary portrait image and the second temporary portrait image and displays it on the target result image generation interface. Fig.11 The target result graph generation interface shown in the figure has "Size", "Beautify", "Background Color" and "Erase" buttons at the bottom and "Save" button at the top. Users can continue to edit the target result graph through the "Size", "Beautify", "Background Color" and "Erase" buttons, and save the final target result graph through the "Save" button.
[0195] When the "Size" button is clicked, as Fig.12 As shown, the terminal can display multiple sizes for users to choose from, such as standard one inch, small one inch, large one inch and standard two inches. Users can modify the size of the target result image by selecting the desired size. When the "Beautify" button is clicked, the user can manually beautify the target video frame based on the target video frame that has been automatically beautified. When the "Background Color" button is clicked, the terminal can display multiple background colors for users to choose from, and users can modify the background color of the target result image by selecting the desired background color.
[0196] When the "Erase" button is clicked, the user can edit the background area of the target result graph. Fig.13 As shown in the figure, in the "erase mode", the user can use the brush to replace the sub-area of the painted foreground area with the background color. In the "repair mode", the user can use the brush to replace the sub-area of the painted background area with the color of the sub-area of the adjacent foreground image. When the "Save" button is clicked, the terminal displays the following Fig.14 The save interface shown in the figure will be saved, and the final target result image will be saved to the local photo album of the terminal.
[0197] The above-mentioned portrait picture generation method divides the target portrait picture into a segmented binary image, replaces the background area of the target portrait with a specified background based on the segmented binary image, and obtains a first temporary portrait picture. After adjusting the target portrait picture to a horizontal position, the size of the target portrait picture is adjusted according to a preset template to obtain a second temporary portrait picture. In this way, the target result image corresponding to the target portrait picture can be determined based on the first temporary portrait picture and the second temporary portrait picture. With the solution provided by the present application, only the user needs to provide a portrait picture, and the portrait picture can be automatically processed to generate a target result image corresponding to the portrait picture, thereby improving the processing efficiency of the portrait picture.
[0198] In one embodiment, performing portrait segmentation on a target portrait image to obtain a segmentation binary image of the target portrait image includes: inputting the target portrait image into a trained portrait segmentation model; performing portrait segmentation on the target portrait image through the portrait segmentation model to obtain a segmentation binary image of the target portrait image; the portrait segmentation model is obtained based on full convolutional network training; the training steps of the portrait segmentation model include: dividing samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples; training the training samples based on the full convolutional network to obtain more than one preliminary model; verifying each preliminary model according to the verification sample to obtain a corresponding verification result; selecting the preliminary model corresponding to the verification result that meets the verification conditions as the portrait segmentation model.
[0199] Specifically, the terminal can divide the input multiple groups of samples into multiple groups of training samples and multiple groups of verification samples, and one group of samples includes a portrait picture sample and a corresponding standard segmentation binary image sample. For example, if the input samples are M groups, the terminal can divide the M groups of samples into N groups of training samples and G groups of verification samples, N+G=M. The terminal uses a full convolutional network model to train the training samples to obtain multiple preparatory models. The portrait picture samples in the verification samples are input into the obtained multiple preparatory models in sequence, and each preparatory model outputs the predicted segmentation binary image corresponding to each portrait picture sample in the verification sample.
[0200] The terminal compares the predicted segmentation binary image output by each preliminary model with the corresponding labeled segmentation binary image sample to obtain multiple deviation values. The terminal can calculate the average deviation value of each preliminary model, determine the preliminary model corresponding to the minimum average deviation value as the preliminary model that meets the verification conditions, and use the preliminary model that meets the verification conditions as the portrait segmentation model.
[0201] In the above embodiment, a preliminary model that meets the verification conditions is selected from a plurality of preliminary models as a portrait segmentation model through verification samples, so that the segmentation binary image output by the portrait segmentation model is more accurate.
[0202] In one embodiment, Fig.16 As shown, a method for generating a portrait image is also provided, the method comprising:
[0203] S1602: When there is a face area in the input video frame, a face beautification instruction is triggered.
[0204] Specifically, an application with portrait image processing and shooting functions may be installed on the terminal. When the terminal detects that the shooting function of the application is turned on, it jumps to the shooting interface corresponding to the application and obtains the real-time input video frame through the system camera. The terminal detects the picture content of each video frame input in real time, and detects whether there is a face area in the picture content of each input video frame. When the terminal detects that there is a face area in the picture content of the input video frame, it means that the terminal needs to perform face beautification processing on the video frame, and the terminal triggers the face beautification instruction.
[0205] In one embodiment, the terminal detects whether there is a face area in the picture content of each input video frame, which can be a face key point detection on the picture content of each video frame. Face key point detection refers to the detection that can locate the key area position of the face, such as the eyebrow area, eye area, nose area, mouth area, facial contour, etc. The face key point refers to the point used to locate the key area position of the face. When the terminal detects the face key point from the input video frame, the terminal can determine that there is a face area in the video frame.
[0206] S1604: Determine a portrait image formed by the video frame according to the face beautification instruction.
[0207] Specifically, the terminal determines the portrait image formed by the video frame with the face area according to the face beautification instruction. It can be understood that the video frame is input in real time through the system camera, so the terminal will have input video frames at every moment, and as long as there is a face area in the video frame, the terminal will determine the portrait image formed by the video frame with the face area. Therefore, within a period of time, the terminal may determine the portrait images formed by multiple video frames with face areas.
[0208] S1606, performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image.
[0209] Specifically, the terminal performs edge-preserving filtering on the portrait image to obtain a filtered image. The terminal may deform the face image based on the deformation parameter to obtain a deformation result image. The terminal performs color mapping on the portrait image to obtain a mapped image. Furthermore, the edge-preserving filtering performed by the terminal on the portrait image may be specifically a mean filtering process.
[0210] In one embodiment, the terminal performs mean filtering on the portrait image, including: determining 8 pixels around each pixel in the portrait image; calculating the average color value of the 8 pixels around each pixel; and adjusting the color value of each pixel to the average color value of the 8 pixels around the pixel.
[0211] In one embodiment, the terminal may perform deformation processing on a portrait image including the following steps: identifying facial key points in the portrait image; determining the deformed target key points corresponding to each facial key point based on the deformation parameters; and shifting each facial key point to the corresponding target key point.
[0212] Specifically, the terminal can identify the portrait image through a preset face recognition interface to obtain the face key points in the portrait image. The terminal is provided with deformation parameters for the face key points, and the terminal performs a shift operation on each face key point based on the deformation parameter to obtain the target key point after the shift operation of each face key point. The terminal shifts each face key point in the portrait image to the corresponding target key point to obtain a deformation result map.
[0213] like Figure 5 As shown, in one embodiment, for example, the portrait picture formed by the currently input video frame is a portrait picture 501, and the terminal recognizes the portrait picture through a preset face recognition interface to obtain the face key points in the portrait picture, such as the black dots in the shift operation picture 502. The terminal performs a shift operation on each face key point based on the deformation parameter to obtain the target key point after the shift operation on each face key point, such as the white dot in the shift operation picture 502. The terminal shifts each face key point in the portrait picture 501 to the corresponding target key point, and obtains the deformation result picture 503. The deformation-based detail fine-tuning of the portrait picture, such as thin face and big eyes, is completed.
[0214] In one embodiment, the terminal performs color mapping processing on the portrait image, including the following steps: determining the color value (R value, G value and B value) of each pixel in the portrait image, searching the target color value corresponding to the color value of each pixel from the color lookup table, and determining the mapped image according to the target color value. The grayscale value corresponding to the color value of each pixel is less than the grayscale value corresponding to the target color value. Furthermore, the color lookup table can be implemented using a LUT (Look-Up-Table display lookup table).
[0215] S1608, the portrait image is fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images respectively.
[0216] Specifically, in order to avoid excessive skin smoothing and excessive whitening, the terminal may preset a first color value weight of the portrait image and a second color value weight of the filtered image. The terminal coordinates and fuses the portrait image and the filtered image based on the first color value weight and the second color value weight to obtain a corresponding skin smoothing result image. The terminal may coordinate and fuse the portrait image and the mapped image based on the first color value weight and the second color value weight to obtain a corresponding whitening result image.
[0217] like Figure 3 As shown, in one embodiment, for example, the portrait image formed by the currently input video frame is a portrait image 301, and after the terminal performs edge-preserving filtering on the portrait image 301, a filtered image 302 can be obtained. Based on the first color value weight corresponding to the portrait image 301 and the second color value weight corresponding to the filtered image 302, the terminal fuses the portrait image 301 and the filtered image 302 to obtain a skin resurfacing result image 303.
[0218] like Figure 4 As shown, in one embodiment, for example, the portrait picture formed by the currently input video frame is a portrait picture 401, and after the terminal performs color mapping processing on the portrait picture 401, a mapped picture 402 can be obtained. Based on the first color value weight corresponding to the portrait picture 401 and the second color value weight corresponding to the mapped picture 402, the terminal merges the portrait picture 401 and the mapped picture 402 to obtain a whitening result picture 403.
[0219] S1610: Determine a video frame after face beautification corresponding to the video frame based on the skin smoothing result image, the deformation result image, and the whitening result image.
[0220] Specifically, the terminal can determine the video frame corresponding to the video frame after face beautification by combining the obtained skin smoothing result map, deformation result map and whitening result map, and display it on the shooting interface displayed by the terminal. The shooting interface displayed by the terminal can be as follows: Fig. 9 As shown, the shooting area 901 of the shooting interface displays a video frame with beautified faces. The function area 902 of the shooting interface displays "Template", "Shoot" and "Beautify" buttons. When the "Template" button is clicked, the terminal displays the template types that can be selected, such as ID photo type, image photo type and business photo type, and the ID photo type is such as ID card, driver's license, etc. When the "Beautify" button is clicked, the user can manually beautify the target video frame based on the target video frame that has been automatically beautified.
[0221] like Fig.10 As shown, beautification adjustment may include face thinning adjustment, chin adjustment, eye enlargement adjustment, nose thinning adjustment, lip adjustment, etc. Of course, beautification adjustment may also include Fig.10Other beautification adjustments not shown in the figure, such as whitening adjustment and dark circle lightening adjustment, etc. Each beautification adjustment can be set with multiple adjustment gears, for example, each beautification adjustment can include 100 adjustment gears for users to choose according to their needs. When the "shoot" button is clicked, the shooting command is triggered.
[0222] The above-mentioned portrait image generation method, as long as there is a face area in the input video frame, will perform edge-preserving filtering, deformation processing and color mapping processing on the portrait image formed by the video frame, obtain the beautified target video frame and display it. Using the solution provided by the present application, when the user takes a portrait photo, the video frame after the face is beautified can be obtained in real time, so that the most satisfactory target portrait photo can be selected from the video frame after the face is beautified, thereby improving the quality of the target portrait photo.
[0223] In one embodiment, the portrait picture generation method also includes: when a shooting instruction is triggered, obtaining a target portrait picture formed by a target video frame displayed when the shooting instruction is triggered; performing portrait segmentation on the target portrait picture to obtain a segmentation binary image of the target portrait picture; the segmentation binary image includes a background area corresponding to the target portrait picture; based on the segmentation binary image, replacing the background area in the target portrait picture with a specified background to obtain a first temporary portrait picture; adjusting the target portrait picture to a horizontal position, and adjusting the size of the target portrait picture adjusted to the horizontal position according to a preset template to obtain a second temporary portrait picture; determining a target result image corresponding to the target portrait picture based on the first temporary portrait picture and the second temporary portrait picture.
[0224] Specifically, the terminal may be provided with a shooting button, and when the terminal detects that the shooting button is triggered, the shooting instruction is triggered. When the display screen of the terminal is a touch display screen, the shooting button may be a virtual shooting button set in the shooting interface displayed by the terminal. It is understandable that the shooting button may also be any physical shooting button of the preset terminal. When the terminal detects that the shooting instruction is triggered, the target portrait image formed by the target video frame displayed in the shooting interface when the shooting instruction is triggered is obtained.
[0225] The terminal can input the target portrait image into a trained portrait segmentation model, perform portrait segmentation on the target portrait image through the portrait segmentation model, and obtain a segmentation binary image of the target portrait image. The obtained segmentation binary image contains a foreground area and a background area. The foreground area corresponds to the portrait area in the target portrait image, and the background area corresponds to the non-portrait area in the target portrait image. Based on the correspondence between the segmentation binary image and the target portrait image, the terminal replaces the non-portrait area of the target portrait image corresponding to the background area in the segmentation binary image with the specified background to obtain a first temporary portrait image. The specified background is, for example, the specified background corresponding to an ID photo, and the specified background corresponding to the ID photo is a background with a specified color.
[0226] The terminal can determine at least one rotation point in the target portrait image, use the rotation point to rotate the target portrait image to a horizontal position, and adjust the size of the target portrait image adjusted to the horizontal position according to the standard size parameters in the preset template to obtain a second temporary portrait image. The terminal determines the target result image corresponding to the target portrait image in combination with the first temporary portrait image and the second temporary portrait image and displays it on the target result image generation interface.
[0227] In the above embodiment, the target portrait picture is segmented into segmented binary images, and the background area of the target portrait is replaced with a specified background based on the segmented binary images to obtain a first temporary portrait picture. After the target portrait picture is adjusted to a horizontal position, the size of the target portrait picture is adjusted according to a preset template to obtain a second temporary portrait picture. In this way, the target result image corresponding to the target portrait picture can be determined based on the first temporary portrait picture and the second temporary portrait picture. With the solution provided by the present application, only the user needs to provide a portrait picture, and the portrait picture can be automatically processed to generate a target result image corresponding to the portrait picture, thereby improving the processing efficiency of the portrait picture.
[0228] Figure 2 , 8 , 15 and 16 are flowcharts of a method for generating a portrait image in one embodiment. It should be understood that although Figure 2 , 8 The steps in the flowcharts of 15 and 16 are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 , 8 At least part of the steps in 1, 15 and 16 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0229] In one embodiment, Fig.17 As shown, a portrait image processing device 1700 is provided, including an instruction triggering module 1701, a face beautification module 1702, an image acquisition module 1703 and a result image generation module 1704, wherein:
[0230] The instruction triggering module 1701 is used to trigger the face beautification instruction when there is a face area in the input video frame;
[0231] The face beautification module 1702 is used to perform face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain the video frame after face beautification;
[0232] The picture acquisition module 1703 is used to select a target video frame from the face beautified video frames to obtain a target portrait picture;
[0233] The result image generating module 1704 is used to replace the background area in the target portrait image with the specified background, and adjust the size and angle of the target portrait image to obtain a target result image corresponding to the target portrait image.
[0234] In one embodiment, the face beautification module is also used to determine a portrait image formed by a video frame according to a face beautification instruction; perform edge-preserving filtering, deformation processing and color mapping processing on the portrait image to obtain a filtered image, a deformation result image and a mapped image; fuse the portrait image with the filtered image and the mapped image to obtain corresponding skin smoothing result images and whitening result images; determine a video frame after face beautification based on the skin smoothing result image, the deformation result image and the whitening result image.
[0235] In one embodiment, the face beautification module is further used to identify facial key points in the portrait image, determine the deformed target key points corresponding to each facial key point based on the deformation parameters, and shift each facial key point to the corresponding target key point.
[0236] In one embodiment, the image acquisition module is further used to select a target video frame that meets the automatic screening condition from the face beautified video frames to obtain a target portrait image; or
[0237] When the shooting command is triggered, the video frame after face beautification displayed when the shooting command is triggered is selected as the target video frame to obtain the target portrait image.
[0238] In one embodiment, the result image generation module is also used to input the target portrait image into a trained portrait segmentation model to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes the background area of the target portrait image; based on the segmentation binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image; the target portrait image is adjusted to a horizontal position, and the size of the target portrait image adjusted to the horizontal position is adjusted according to a preset template to obtain a second temporary portrait image; based on the first temporary portrait image and the second temporary portrait image, a target result image corresponding to the target portrait image is determined.
[0239] In one embodiment, the portrait segmentation model is obtained based on full convolutional network training; the portrait image processing device 1700 also includes a model training module, which is used to divide samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples; the training samples are trained based on the full convolutional network to obtain more than one preliminary model; each preliminary model is verified according to the verification sample to obtain corresponding verification results; the preliminary model corresponding to the verification result that meets the verification conditions is selected as the portrait segmentation model.
[0240] In one embodiment, the result image generation module is also used to determine the center position of the two eyes in the face area of the target portrait image; adjust the target portrait image to a horizontal position based on the center position; and crop and scale the target portrait image adjusted to the horizontal position according to a preset template to obtain a second temporary portrait image.
[0241] In one embodiment, Fig.18 As shown, a portrait picture processing device 1800 is also provided, including a portrait segmentation module 1801, a background replacement module 1802, a picture adjustment module 1803 and a result image determination module 1804, wherein:
[0242] The portrait segmentation module 1801 is used to perform portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area corresponding to the target portrait image;
[0243] A background replacement module 1802 is used to replace the background area in the target portrait image with a specified background based on the segmented binary image to obtain a first temporary portrait image;
[0244] The picture adjustment module 1803 is used to adjust the target portrait picture to a horizontal position, and adjust the size of the target portrait picture adjusted to the horizontal position according to a preset template to obtain a second temporary portrait picture;
[0245] The result image determining module 1804 is used to determine a target result image corresponding to the target portrait image based on the first temporary portrait image and the second temporary portrait image.
[0246] In one embodiment, the portrait segmentation module is also used to input the target portrait image into a trained portrait segmentation model; the target portrait image is segmented by the portrait segmentation model to obtain a segmentation binary image of the target portrait image; the portrait segmentation model is obtained based on the full convolutional network training; the portrait image processing device 1800 also includes a model training module, which is used to divide the samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples; the training samples are trained based on the full convolutional network to obtain more than one preliminary model; each preliminary model is verified according to the verification sample to obtain a corresponding verification result; the preliminary model corresponding to the verification result that meets the verification conditions is selected as the portrait segmentation model.
[0247] In one embodiment, Fig.19 As shown, a portrait picture processing device 1900 is also provided, including a beautification instruction triggering module 1901, a portrait picture determining module 1902, a portrait picture processing module 1903, a picture fusion module 1904 and a target video frame determining module 1905, wherein:
[0248] A beautification instruction triggering module 1901 is used to trigger a face beautification instruction when a face area exists in an input video frame;
[0249] A portrait picture determination module 1902 is used to determine a portrait picture formed by a video frame according to a face beautification instruction;
[0250] The portrait picture processing module 1903 is used to perform edge-preserving filtering, deformation processing and color mapping processing on the portrait picture to obtain a filtered picture, a deformation result picture and a mapped picture;
[0251] The image fusion module 1904 is used to fuse the portrait image with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images respectively;
[0252] The target video frame determination module 1905 is used to determine the video frame after face beautification based on the skin grinding result image, the deformation result image and the whitening result image.
[0253] In one embodiment, the portrait picture processing device 1900 also includes a target result image generation module, which is used to obtain a target portrait picture formed by the target video frame displayed when the shooting instruction is triggered when the shooting instruction is triggered; perform portrait segmentation on the target portrait picture to obtain a segmentation binary image of the target portrait picture; the segmentation binary image includes a background area corresponding to the target portrait picture; based on the segmentation binary image, the background area in the target portrait picture is replaced with a specified background to obtain a first temporary portrait picture; adjust the target portrait picture to a horizontal position, and adjust the size of the target portrait picture adjusted to the horizontal position according to a preset template to obtain a second temporary portrait picture; determine the target result image corresponding to the target portrait picture based on the first temporary portrait picture and the second temporary portrait picture.
[0254] Figure 1 The internal structure diagram of a computer device in one embodiment is shown. The computer device may specifically be Figure 1 The terminal 100 in FIG. Figure 1 As shown, the computer device includes a processor, a memory, a network interface, an input device and a display screen connected through a system bus. Among them, the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement the portrait image generation method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can execute the portrait image generation method. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a button, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0255] Those skilled in the art will understand that Figure 1 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0256] In one embodiment, the portrait image processing device provided by the present application can be implemented in the form of a computer program. The computer program can be Figure 1 The memory of the computer device can store various program modules constituting the portrait image processing device, for example, Fig.17 The instruction triggering module 1701, the face beautification module 1702, the picture acquisition module 1703 and the result image generation module 1704 are shown. Fig.18The portrait segmentation module 1801, the background replacement module 1802, the picture adjustment module 1803 and the result image determination module 1804 are shown. Fig.19 The beautification instruction triggering module 1901, the portrait picture determining module 1902, the portrait picture processing module 1903, the picture fusion module 1904 and the target video frame determining module 1905 are shown. The computer program composed of each program module enables the processor to execute the steps in the portrait picture generating method of each embodiment of the present application described in this specification.
[0257] For example, Figure 1 The computer device shown can be Fig.17 The instruction triggering module 1701 in the portrait picture processing device 1700 shown executes when there is a face area in the input video frame, triggering the face beautification instruction. The computer device can execute the face beautification of the portrait picture formed by the video frame according to the face beautification instruction through the face beautification module 1702, obtain the video frame after face beautification and display it. The computer device can execute through the picture acquisition module 1703 when the shooting instruction is triggered, obtain the target portrait picture formed by the target video frame displayed when the shooting instruction is triggered. The computer device can execute through the result image generation module 1704 to replace the background area in the target portrait picture with the specified background, and adjust the size and angle of the target portrait picture, obtain the target result image corresponding to the target portrait picture and display it.
[0258] For example, Figure 1 The computer device shown can be Fig.18 The portrait segmentation module 1801 in the portrait picture processing device 1800 shown in the figure performs portrait segmentation on the target portrait picture to obtain a segmentation binary image of the target portrait picture; the segmentation binary image includes a background area corresponding to the target portrait picture. The computer device can replace the background area in the target portrait picture with a specified background based on the segmentation binary image through the background replacement module 1802 to obtain a first temporary portrait picture. The computer device can adjust the target portrait picture to a horizontal position through the picture adjustment module 1803, and adjust the size of the target portrait picture adjusted to the horizontal position according to a preset template to obtain a second temporary portrait picture. The computer device can determine the target result image corresponding to the target portrait picture based on the first temporary portrait picture and the second temporary portrait picture through the result image determination module 1804 and display it.
[0259] For example, Figure 1 The computer device shown can be Fig.19The beautification instruction triggering module 1901 in the portrait picture processing device 1900 shown executes when there is a face area in the input video frame, triggering the face beautification instruction. The computer device can determine the portrait picture formed by the video frame according to the face beautification instruction through the portrait picture determination module 1902. The computer device can perform edge-preserving filtering, deformation processing and color mapping processing on the portrait picture through the portrait picture processing module 1903, and obtain the filtered picture, the deformation result map and the mapped picture. The computer device can perform the fusion of the portrait picture with the filtered picture and the mapped picture through the picture fusion module 1904, and obtain the corresponding skin grinding result map and whitening result map respectively. The computer device can determine the video frame corresponding to the face beautification based on the skin grinding result map, the deformation result map and the whitening result map through the target video frame determination module 1905 and display it.
[0260] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above-mentioned portrait image generation method. The steps of the portrait image generation method here may be the steps of the portrait image generation method in the above-mentioned various embodiments.
[0261] In one embodiment, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the processor executes the steps of the above-mentioned portrait image generation method. The steps of the portrait image generation method here can be the steps in the portrait image generation method of each of the above-mentioned embodiments.
[0262] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0263] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0264] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for generating a portrait image, comprising: When there is a face area in the input video frame, the face beautification instruction is triggered; Performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification; Select a target video frame from the face beautified video frames to obtain a target portrait image; Performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area and a foreground area of the target portrait image; the foreground area refers to a portrait area in the target portrait image; Based on the segmented binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image; Determine the center position of two eyes in the face area of the target portrait image; Taking the center position as a reference, adjusting the target portrait image to a horizontal position; The target portrait image adjusted to a horizontal position is cropped according to the length and width corresponding to the preset template to obtain a cropped target portrait image, and the cropped target portrait image is scaled according to the standard area corresponding to the preset template to obtain a second temporary portrait image; The preset template is at least one of a preset template corresponding to a ID photo, a preset template corresponding to a profile photo, and a preset template corresponding to a business photo; A target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
2. The method according to claim 1, characterized in that The performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain the video frame after face beautification comprises: Determining a portrait image formed by the video frame according to the face beautification instruction; Performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image; The portrait image is respectively fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images; The video frame after face beautification is determined based on the skin smoothing result image, the deformation result image and the whitening result image.
3. The method according to claim 2, characterized in that The deformation processing of the portrait image includes the following steps: Identify key points of the face in the portrait image; Determine the deformed target key points corresponding to each of the facial key points based on the deformation parameters; Each of the facial key points is shifted to the corresponding target key point.
4. The method according to claim 1, characterized in that The step of selecting a target video frame from the face beautified video frame to obtain a target portrait image includes: Selecting a target video frame that meets the automatic screening condition from the face beautified video frames to obtain a target portrait image; or, When the shooting command is triggered, the video frame after face beautification displayed when the shooting command is triggered is selected as the target video frame to obtain the target portrait image.
5. The method according to claim 1, characterized in that The step of performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image comprises: The target portrait image is input into a trained portrait segmentation model to obtain a segmentation binary image of the target portrait image.
6. The method according to claim 5, characterized in that The portrait segmentation model is obtained based on full convolutional network training; the training steps of the portrait segmentation model include: Dividing samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples; Training the training samples based on a fully convolutional network to obtain more than one preliminary model; Verifying each of the prepared models according to the verification samples to obtain corresponding verification results; The preliminary model corresponding to the verification result that meets the verification conditions is selected as the portrait segmentation model.
7. A method for generating a portrait image, comprising: When there is a face area in the input video frame, the face beautification instruction is triggered; Determining a portrait image formed by the video frame according to the face beautification instruction; Performing edge-preserving filtering, deformation processing and color mapping processing on the portrait image respectively to obtain a filtered image, a deformation result image and a mapped image; The portrait image is respectively fused with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images; Determine a video frame after face beautification based on the skin smoothing result image, the deformation result image and the whitening result image; Select a target video frame from the face beautified video frames to obtain a target portrait image; Performing portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area and a foreground area corresponding to the target portrait image; the foreground area refers to the portrait area in the target portrait image; Based on the segmented binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image; Determine the center position of two eyes in the face area of the target portrait image; Taking the center position as a reference, adjusting the target portrait image to a horizontal position; The target portrait image adjusted to a horizontal position is cropped according to the length and width corresponding to the preset template to obtain a cropped target portrait image, and the cropped target portrait image is scaled according to the standard area corresponding to the preset template to obtain a second temporary portrait image; The preset template is at least one of a preset template corresponding to a ID photo, a preset template corresponding to a profile photo, and a preset template corresponding to a business photo; A target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
8. A portrait image processing device, characterized in that: The device comprises: The command trigger module is used to trigger the face beautification command when there is a face area in the input video frame; A face beautification module, used for performing face beautification on the portrait image formed by the video frame according to the face beautification instruction to obtain a video frame after face beautification; The image acquisition module is used to select a target video frame from the face beautified video frames to obtain a target portrait image; A result image generation module is used to perform portrait segmentation on the target portrait image to obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area and a foreground area of the target portrait image; the foreground area refers to the portrait area in the target portrait image; based on the segmentation binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image; the center position of two eyes in the face area of the target portrait image is determined; based on the center position, the target portrait image is adjusted to a horizontal position; the target portrait image adjusted to the horizontal position is cropped according to the length and width corresponding to a preset template to obtain a cropped target portrait image; the cropped target portrait image is scaled according to a standard area corresponding to the preset template to obtain a second temporary portrait image; the preset template is at least one of a preset template corresponding to an ID photo, a preset template corresponding to an image photo, and a preset template corresponding to a business photo; a target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
9. The device according to claim 8, characterized in that The face beautification module is also used to determine the portrait image formed by the video frame according to the face beautification instruction, perform edge-preserving filtering, deformation processing and color mapping processing on the portrait image to obtain a filtered image, a deformation result image and a mapped image, fuse the portrait image with the filtered image and the mapped image to obtain corresponding skin grinding result images and whitening result images, and determine the video frame after face beautification based on the skin grinding result image, the deformation result image and the whitening result image.
10. The device according to claim 9, characterized in that The face beautification module is also used to identify the facial key points in the portrait image, determine the deformed target key points corresponding to each of the facial key points based on the deformation parameters, and shift each of the facial key points to the corresponding target key points.
11. The device according to claim 8, characterized in that The image acquisition module is also used to select a target video frame that meets the automatic screening conditions from the video frames after face beautification to obtain a target portrait image; or, when a shooting instruction is triggered, select the video frame after face beautification displayed when the shooting instruction is triggered as the target video frame to obtain a target portrait image.
12. The device according to claim 8, characterized in that The result image generation module is also used to input the target portrait image into a trained portrait segmentation model to obtain a segmentation binary image of the target portrait image.
13. The device according to claim 12, characterized in that The portrait segmentation model is obtained based on full convolutional network training; the device also includes a model training module, which is used to divide samples into training samples and verification samples; the samples include portrait image samples and corresponding segmentation binary image samples, the training samples are trained based on the full convolutional network to obtain more than one preliminary model, each of the preliminary models is verified according to the verification samples to obtain corresponding verification results, and the preliminary model corresponding to the verification result that meets the verification conditions is selected as the portrait segmentation model.
14. A portrait image processing device, characterized in that: The device comprises: A beautification instruction triggering module is used to trigger a face beautification instruction when a face area exists in an input video frame; A portrait picture determination module, used to determine the portrait picture formed by the video frame according to the face beautification instruction; A portrait picture processing module, used to perform edge-preserving filtering, deformation processing and color mapping processing on the portrait picture to obtain a filtered picture, a deformation result picture and a mapped picture; An image fusion module is used to fuse the portrait image with the filtered image and the mapped image to obtain corresponding skin resurfacing result images and whitening result images respectively; A target video frame determination module, used to determine a video frame after face beautification based on the skin resurfacing result image, the deformation result image and the whitening result image; The target result image generation module is used to select a target video frame from the video frame after face beautification to obtain a target portrait image, perform portrait segmentation on the target portrait image, and obtain a segmentation binary image of the target portrait image; the segmentation binary image includes a background area and a foreground area corresponding to the target portrait image; the foreground area refers to the portrait area in the target portrait image, based on the segmentation binary image, the background area in the target portrait image is replaced with a specified background to obtain a first temporary portrait image, determine the center position of the two eyes in the face area of the target portrait image, and use the foreground area to obtain the portrait area of the target portrait image. Based on the center position, the target portrait image is adjusted to a horizontal position, and the target portrait image adjusted to the horizontal position is cropped according to the length and width corresponding to the preset template to obtain a cropped target portrait image, and the cropped target portrait image is scaled according to the standard area corresponding to the preset template to obtain a second temporary portrait image, wherein the preset template is at least one of the preset template corresponding to the ID photo, the preset template corresponding to the image photo, and the preset template corresponding to the business photo, and the target result image corresponding to the target portrait image is determined based on the first temporary portrait image and the second temporary portrait image.
15. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 7.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Beauty image taking method and device, and computer storage medium
CN107767333A