Method and device for repairing face in image
Through blur detection and weight value judgment of faces in the video, the face repair process is optimized, solving the problem of video face repair when the face is blurred and the background is complex, and a more natural and consistent repair effect is achieved.
Patent Information
- Application Number
- CN202410727762.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-09-03
AI Technical Summary
Existing video face repair technology can easily lead to inconsistent repair effects when the face is blurred and the background is complex, and failure to repair when a face cannot be detected results in a sudden change in the video effect.
By performing face detection and blur detection on the image to be processed, the repair weight value is determined based on the fuzziness to determine whether to perform face repair and the degree of repair, thereby filtering out scenes that are not suitable for repair, such as blurred faces and highly blurred faces. .
It avoids unnecessary repairs, enhances the face repair effect in the video, ensures that the repair results are consistent with the original video scene, and avoids visual defects.
Smart Images

Figure CN118587126A
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Internet technology, and in particular, to a method, apparatus, computer device, computer-readable storage medium, and computer program product for repairing faces in images. Background Art
[0002] In the conventional video face restoration process, all faces that appear in the video will be repaired indiscriminately. However, due to the diversity of video shooting, blurred faces often appear. For example, in close-up shots or clips of characters in TV dramas, the background is generally blurred. In this case, if there is a face in the background, it is likely to be detected and repaired. This will cause the face presented in the background of the repaired picture to be very strange and not in line with the expectations of the original video scene. In addition, the blurred situation will also cause the face detection algorithm to have two situations: detecting faces and not detecting faces. Repairing when faces are detected and not repairing when faces are not detected may cause a sudden change in the face part of the repaired video effect, resulting in the video repair effect not meeting expectations.
[0003] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the invention
[0004] The embodiments of the present application provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for repairing faces in images to solve or alleviate one or more of the technical problems raised above.
[0005] One aspect of an embodiment of the present application provides a method for repairing a face in an image, the method comprising:
[0006] Acquire an image to be processed, and perform face detection on the image to be processed to obtain one or more face positions;
[0007] Perform blur detection on each face position respectively to obtain the blur corresponding to each face position;
[0008] Determine a restoration weight value corresponding to each face position according to the blurriness corresponding to each face position;
[0009] Face restoration is performed on the face position according to the restoration weight value corresponding to each face position.
[0010] Optionally, the performing blur detection on each face position respectively to obtain the blur corresponding to each face position includes:
[0011] Through the Laplace operator, the blurriness of each face position is detected respectively to obtain the blurriness corresponding to each face position.
[0012] Optionally, determining the restoration weight value corresponding to each face position according to the blurriness corresponding to each face position includes:
[0013] The restoration weight value corresponding to each face position is determined according to the position of the blurriness corresponding to each face position in the preset blurriness range; wherein the minimum value of the preset blurriness range is the first preset threshold value, and the maximum value is the second preset threshold value.
[0014] Optionally, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness interval includes:
[0015] When the blurriness corresponding to the face position is less than or equal to a first preset threshold, the restoration weight value corresponding to the face position is determined to be 0.
[0016] Optionally, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness interval includes:
[0017] When the blurriness corresponding to the face position is greater than or equal to a second preset threshold, the restoration weight value corresponding to the face position is determined to be 1.
[0018] Optionally, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness interval includes:
[0019] When the blurriness corresponding to the face position is greater than a first preset threshold and less than a second preset threshold, a restoration weight value corresponding to the face position is determined according to a preset linear relationship.
[0020] Optionally, performing face restoration on the face position according to the restoration weight value corresponding to each face position includes:
[0021] Repairing the face position by a preset face repair algorithm to obtain a repaired face;
[0022] Extracting a face mask from the face position;
[0023] According to the restoration weight value, the restored face is fused into the face mask to obtain a target face.
[0024] Another aspect of an embodiment of the present application provides a device for repairing a face in an image, the device comprising:
[0025] A face position determination module is used to obtain an image to be processed and perform face detection on the image to be processed to obtain one or more face positions;
[0026] A blur detection module is used to perform blur detection on each face position to obtain blur corresponding to each face position;
[0027] A restoration weight value determination module, used to determine the restoration weight value corresponding to each face position according to the blurriness corresponding to each face position;
[0028] The face restoration module is used to perform face restoration on the face position according to the restoration weight value corresponding to each face position.
[0029] Another aspect of an embodiment of the present application provides a computer device, including:
[0030] at least one processor; and
[0031] a memory communicatively coupled to the at least one processor;
[0032] Wherein: the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for repairing faces in images as described above.
[0033] Another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method for repairing a face in an image as described above is implemented.
[0034] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method for repairing faces in an image as described above.
[0035] The embodiments of the present application adopting the above-mentioned technical scheme may include the following advantages: by optimizing the process of face restoration and adding a blur detection process, that is, by performing blur detection on the detected face position and determining a restoration weight value based on the blur, the restoration weight value may indicate whether further face restoration is needed and the degree of restoration required, thereby screening out some scenes that are not suitable for face restoration based on the blur of the face, such as face restoration in scenes such as blurred faces, highly blurred faces, and misdetected faces in videos, thereby achieving the best effect of face image restoration while avoiding defective restoration video results. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0037] Figure 1 A diagram schematically shows an operating environment of a method for restoring a face in an image according to Embodiment 1 of the present application;
[0038] Figure 2 The flowchart of the method for repairing a face in an image according to the first embodiment of the present application is schematically shown;
[0039] Figure 3 A system block diagram of a traditional face restoration process is schematically shown;
[0040] Figure 4 A system block diagram of the face restoration process optimized according to the first embodiment of the present application is schematically shown;
[0041] Figure 5 A schematic diagram schematically shows a linear relationship between a restoration weight value and blur;
[0042] Figure 6 A block diagram schematically shows a device for restoring a face in an image according to the second embodiment of the present application; and
[0043] Figure 7 The hardware architecture diagram of the computer device according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions 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 intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0045] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0046] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0047] First, the following terms are explained:
[0048] Face Restoration: refers to the process of repairing blurred or damaged images through deep learning methods, which can make the blurred facial features and skin of the face clearer and improve the expression and details.
[0049] Face Detection: It is a computer technology that finds the position and size of a face in any digital image. Face Keypoint Detection is to detect subtle features of the face, such as eyes, nose, mouth and other fine positions.
[0050] Ambiguity detection in images: It is a technology that uses a certain gradient calculation method to obtain a boundary value to judge the clarity of an image. Commonly used methods include Laplacian operator, Sobel operator, Canny operator, etc. Through ambiguity detection, the blur degree of different images can be obtained, thereby achieving the purpose of screening blurry images.
[0051] Laplace Operator: It is a second-order differential operator in n-dimensional Euclidean space, defined as the gradient Divergence The Laplacian operator measures the second derivative of an image, highlighting areas of the image that contain rapid intensity changes. If the variance is low, it means that the image has very few edges. From the spatial domain, the gradient of a blurred image is relatively small.
[0052] Secondly, in order to facilitate those skilled in the art to understand the technical solutions provided in the embodiments of the present application, the relevant technologies are described below:
[0053] Face restoration refers to restoring a high-quality face image from a low-quality input face image. It can be used in scenarios such as old photo restoration, old video restoration, and restoration of blurred surveillance. The complete restoration process is as follows:
[0054] First, detect the face position in a given image through face detection algorithm;
[0055] Second, use the face restoration algorithm to perform face restoration on the detection results of the previous step;
[0056] Third, extract the face part through the semantic segmentation model and only select the enhanced face range;
[0057] Fourth, overwrite the repaired result to the face position of the original image.
[0058] Through the above steps, the complete function of face restoration is completed, which is applicable to scenes such as image restoration and video restoration. In video restoration, the video is decoded, and the above restoration operation is performed on each frame of the image to generate a restored new frame, and then the restored video is encoded and output. This is the widely used method for video restoration.
[0059] At present, in the conventional video face restoration process, all faces appearing in the video will be repaired indiscriminately. However, due to the diversity of video shooting, blurred faces often appear. For example, in close-up shots or clips of characters in TV dramas, the background is generally blurred. If there is a face in the background, it is likely to be detected and repaired. This will cause the repair result to be very strange and not in line with the expectations of the original video scene. In addition, the blurring situation will also cause the face detection algorithm to have two situations: detecting faces and not detecting faces. When faces are detected, repair is performed, and when faces are not detected, no repair is performed. This may cause a sudden change in the face part of the repaired video effect, which is also a shortcoming of the background technology. For some highly blurred faces, considering the limitations of conventional face restoration algorithms, in order to ensure the effect, it is not recommended to perform indiscriminate restoration.
[0060] To this end, the embodiment of the present application provides a technical solution for face restoration in an image. In this technical solution, by acquiring an image to be processed and performing face detection on the image to be processed to obtain one or more face positions; performing blur detection on each face position to obtain the blur corresponding to each face position; determining the restoration weight value corresponding to each face position according to the blur corresponding to each face position; and performing face restoration on the face position according to the restoration weight value corresponding to each face position. By optimizing the process of face restoration and adding the process of blur detection, that is, by performing blur detection on the detected face position and performing reasonable logical judgment based on the blur to determine the restoration weight value, the restoration weight value can indicate whether further face restoration is required and the degree of restoration required, so that some scenes that are not suitable for face restoration can be screened out based on the blur of the face, such as face restoration in scenes such as blurred faces, highly blurred faces, and misdetected faces in videos can be screened out, avoiding the result of defective restoration of videos and enhancing the face restoration effect in videos. See below for details.
[0061] Finally, for ease of understanding, an exemplary operating environment is provided below.
[0062] like Figure 1 As shown, the environment diagram includes a service platform 2, a network 4, and a client 6, wherein:
[0063] The service platform 2 may be composed of a single or multiple computing devices. The multiple computing devices may include virtualized computing instances. Virtualized computing instances may include virtual machines, such as simulations of computer systems, operating systems, servers, etc. The computing device may load a virtual machine based on a virtual image and / or other data defining specific software (e.g., operating system, dedicated application, server) for simulation. As the demand for different types of processing services changes, different virtual machines may be loaded and / or terminated on one or more computing devices. A hypervisor may be implemented to manage the use of different virtual machines on the same computing device.
[0064] The service platform 2 may be configured to communicate with the client 6 or the like via a network 4. The network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 4 may include physical links, such as coaxial cable links, twisted pair cable links, optical fiber links, combinations thereof, and the like, or wireless links, such as cellular links, satellite links, Wi-Fi links, and the like.
[0065] The service platform 2 can provide storage, reading, writing, querying, deleting and other services, such as providing face restoration services in images for clients.
[0066] Client 6 can be a Windows, Android TM ) or iOS operating systems, such as smartphones, tablet devices, laptops, virtual reality devices, gaming devices, set-top boxes, in-vehicle terminals, and smart TVs. Based on the above operating systems, various applications, such as face restoration in images, can be run.
[0067] The client 6 may provide / configure a user access page for manipulating the service platform 2 or uploading an object, etc.
[0068] It should be noted that the above devices are exemplary, and the number and type of devices are adjustable in different scenarios or according to different needs.
[0069] The following uses the service platform 2 as the execution subject to introduce the technical solution of the present application through multiple embodiments. It should be noted that these embodiments can be implemented in a variety of different forms and should not be interpreted as being limited to the embodiments described here.
[0070] Embodiment 1
[0071] Figure 2 The flowchart of the method for repairing a face in an image according to the first embodiment of the present application is schematically shown.
[0072] like Figure 2 As shown, the method for repairing faces in an image may include steps S202 to S208, wherein:
[0073] Step S202, obtaining an image to be processed, and performing face detection on the image to be processed to obtain one or more face positions;
[0074] Step S204, performing blur detection on each face position respectively to obtain blur corresponding to each face position;
[0075] Step S206, determining a restoration weight value corresponding to each face position according to the blurriness corresponding to each face position;
[0076] Step S208: performing face restoration on the face position according to the restoration weight value corresponding to each face position.
[0077] The face restoration method in an image provided by the present embodiment optimizes the face restoration process and adds a blur detection process, that is, by performing blur detection on the detected face position and making a reasonable logical judgment based on the blur to determine the restoration weight value. The restoration weight value can indicate whether further face restoration is needed and the degree of restoration required, so that some scenes that are not suitable for face restoration can be screened out based on the blur of the face, thereby avoiding the occurrence of defective restoration video results and enhancing the face restoration effect in the video.
[0078] The following combination Figure 2 , each step in steps S202 to S208 and other optional steps are described in detail.
[0079] Step S202 , obtaining an image to be processed, and performing face detection on the image to be processed to obtain one or more face positions;
[0080] The images to be processed are some images that currently need to be restored for human faces. These images can be captured from videos or downloaded from the cloud, or can be images captured in real time by calling a camera in a terminal device. The video to be processed can be in a variety of formats, such as bmp, jpg, png, tif, gif, and tga, etc., and the embodiments of the present application do not impose specific restrictions on this.
[0081] In this embodiment, after obtaining the image to be processed, face detection can be performed on the image to be processed to obtain one or more face positions, wherein each face position is used to record the position of a face in the image. In a specific implementation, many face detection algorithms are disclosed in the prior art, such as feature-based methods, statistical model-based methods, image transformation-based methods, deep learning methods, and traditional machine learning methods. Face detection can be performed on the image to be processed based on the existing face detection algorithm to obtain one or more face positions.
[0082] Among them, the feature-based method: This method performs face recognition by extracting key features of the face, such as the coordinates, contours, colors, and other information of the eyes, nose, mouth, and other parts. The feature extraction algorithm mainly includes descriptors of geometric structures, local texture patterns, and local binary patterns.
[0083] Methods based on statistical models: This method uses statistical models, such as Gaussian mixture models, principal component analysis (PCA), linear discriminant analysis, etc., to model facial features and recognize faces through sample training. Eigenfaces and Fisherfaces are representatives of this method, which encode and decode faces through machine learning and use facial components in statistical databases as features.
[0084] Image transformation based method: This method mainly extracts features by performing a series of transformations on face images, such as integral image, wavelet transform, rotation invariant LBP, etc.
[0085] Deep learning methods: Deep learning face recognition algorithms mainly include convolutional neural networks (CNN), deep belief networks (DBN) and ensemble learning algorithms. CNN and DBN obtain highly abstract representations of facial features by training convolutional neural networks with multiple layers of neural networks, while ensemble learning algorithms combine multiple different deep learning algorithms for face recognition.
[0086] Traditional machine learning methods: such as the method of combining the Histogram of Oriented Gradients (HoG) with the Support Vector Machine (SVM), and the Haar Cascade method, etc. HoG feature extraction combined with the SVM classifier is a traditional machine learning method, while HaarCascade is an object detection method for locating objects on an image.
[0087] Each of the above face detection methods has its own specific advantages and limitations. In practical applications, the appropriate algorithm or algorithm combination can be selected according to specific needs and scenarios.
[0088] Step S204 , respectively perform blur detection on each face position to obtain the blur corresponding to each face position;
[0089] In order to avoid indiscriminate restoration of faces in images, which may cause sudden changes in the face part of the restored image and fail to meet the expectations of the original image or video scene, in this embodiment, a blur detection process is added to the traditional face restoration process so that corresponding face restoration can be performed according to the blur of the face in the subsequent process.
[0090] Specifically, after detecting one or more face positions in the image to be processed, blur detection can be performed on each face position based on a blur detection algorithm to obtain the blur corresponding to each face position. The blur detection algorithm can be a Laplace operator, which can be used to measure the second-order derivative of the image and highlight the image area containing rapid intensity changes. If the variance is low, it means that there are very few image edges. On the contrary, if the variance is high, it means that the image edges are obvious and the image quality is clearer.
[0091] Step S206 , determining a restoration weight value corresponding to each face position according to the blurriness corresponding to each face position;
[0092] In this embodiment, logical judgment can be performed based on the fuzziness corresponding to each face position to determine the repair weight value corresponding to each face position, wherein the repair weight value can indicate whether further face repair is needed and the degree of repair required. For example, a repair weight value of 0 indicates that no face repair is needed; a repair weight value of 1 indicates that face repair is needed, and the result uses the repaired face completely; a repair weight value between 0 and 1 indicates that face repair is needed, and the degree of face repair transitions between 0 and 100%.
[0093] Step S208 , face restoration is performed on the face position according to the restoration weight value corresponding to each face position.
[0094] In this embodiment, for each face position, face restoration is performed on the face position by using the restoration weight value corresponding to each face position determined according to the above steps. Specifically, the face position can be restored by using a preset face restoration algorithm to obtain a restored face, and a face mask Mask can be extracted from the face position, and finally the restored face can be fused into the face mask according to the restoration weight value to obtain the target face. Among them, when the restoration weight value is 0, face restoration is not required, and the face in the original image is retained, so that some scenes that are not suitable for face restoration can be screened out, avoiding the appearance of defective restoration video results, and enhancing the face restoration effect in the video.
[0095] In an optional embodiment of the present application, step S204 may include the following steps:
[0096] Through the Laplace operator, the blurriness of each face position is detected respectively to obtain the blurriness corresponding to each face position.
[0097] In this embodiment, blur detection can be performed on each face position based on a blur detection algorithm to obtain blur corresponding to each face position. The blur detection algorithm can be a Laplace operator, which can measure the second-order derivative of the image and highlight the image area containing rapid intensity changes. If the variance is low, it means that there are very few image edges. On the contrary, if the variance is high, it means that the image edge is obvious and the image quality is clearer.
[0098] In an optional embodiment of the present application, step S206 may include the following steps:
[0099] The restoration weight value corresponding to each face position is determined according to the position of the blurriness corresponding to each face position in the preset blurriness range; wherein the minimum value of the preset blurriness range is the first preset threshold value, and the maximum value is the second preset threshold value.
[0100] In this embodiment, after performing fuzziness detection on the face position to obtain the fuzziness corresponding to the face position, logical judgment can be performed based on the fuzziness to determine the need for face repair and the degree of repair of the face position. The specific logical judgment process includes: determining the repair weight value corresponding to each face position according to the position of the fuzziness corresponding to each face position in the preset fuzziness range.
[0101] The preset blur interval is a preset blur threshold range, which is used to determine whether face restoration is required and the restoration degree of the face position. The minimum value of the preset blur interval is the first preset threshold, and the maximum value is the second preset threshold. If it is less than the first preset threshold, it means that face restoration is not required, that is, the restoration degree is 0; if it is greater than the second preset threshold, it means that the face needs to be completely restored, and the result completely uses the restored face, that is, the restoration degree is 100%.
[0102] In a specific implementation, in order to obtain a suitable threshold range of the degree of face restoration fusion, a large number of faces in actual applications can be used to obtain blur values and sort them, and the actual restoration effects in these cases can be analyzed to determine a preset blur interval [a, b]. In addition, the preset blur interval can also be adjusted as required, and the embodiment of the present application does not impose specific restrictions on the preset blur interval.
[0103] In an optional embodiment of the present application, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness range includes:
[0104] When the blurriness corresponding to the face position is less than or equal to a first preset threshold, the restoration weight value corresponding to the face position is determined to be 0.
[0105] In this embodiment, by comparing the blurriness corresponding to the face position with the preset blurriness interval, when the blurriness corresponding to the face position is less than or equal to the first preset threshold, the repair weight value corresponding to the face position is determined to be 0. At this time, there is no need to perform face repair on the face position.
[0106] In an optional embodiment of the present application, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness range includes:
[0107] When the blurriness corresponding to the face position is greater than or equal to a second preset threshold, the restoration weight value corresponding to the face position is determined to be 1.
[0108] In this embodiment, the blurriness corresponding to the face position is compared with the preset blurriness interval. When the blurriness corresponding to the face position is greater than or equal to the second preset threshold, the repair weight value corresponding to the face position is determined to be 1. At this time, face repair is required for the face position, and the result completely uses the repaired face.
[0109] In an optional embodiment of the present application, determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in a preset blurriness range includes:
[0110] When the blurriness corresponding to the face position is greater than a first preset threshold and less than a second preset threshold, a restoration weight value corresponding to the face position is determined according to a preset linear relationship.
[0111] In this embodiment, by comparing the blurriness corresponding to the face position with the preset blurriness interval, when the blurriness corresponding to the face position is greater than the first preset threshold and less than the second preset threshold, the repair weight value corresponding to the face position is determined based on the preset linear relationship and the blurriness corresponding to the face position. The value range of the repair weight value is 0 to 1. At this time, face repair is required for the face position, and the degree of face repair transitions between 0 and 100%.
[0112] The preset linear relationship may be determined according to a first preset threshold and a second preset threshold in a preset ambiguity interval, and the preset linear relationship is expressed as follows:
[0113]
[0114] Among them, σ is a constant coefficient, which can be set according to the needs of face fusion effect, and the embodiment of the present application does not impose any specific limitation on this.
[0115] In an optional embodiment of the present application, step S208 may include the following steps:
[0116] The face position is repaired by a preset face repair algorithm to obtain a repaired face; a face mask is extracted from the face position; and according to the repair weight value, the repaired face is fused into the face mask to obtain a target face.
[0117] Among them, the preset face restoration algorithm can be some face restoration algorithms commonly used in the prior art, such as, a method based on deep learning: such as GAN, VGGFace2, etc., or a method based on convolutional neural network: such as CNN, ResNet, Inception, etc.
[0118] In this embodiment, the face position is repaired by a preset face repair algorithm to obtain a repaired face, and then a face mask Mask is extracted from the face position, and the repaired face is fused into the face mask according to the repair weight value to obtain the target face. Among them, when the repair weight value is 0, face repair is not required; when the repair weight value is 1, the result completely uses the repaired face; when the repair weight value is between 0 and 1, the repaired face is fused into the face mask according to the repair degree between 0 and 100% to obtain the target face.
[0119] To further explain the face restoration method in an image of the present application, Figure 3 This is a system diagram of the traditional face restoration process, including face detection, face restoration, face mask extraction and restoration results back to the original Figure 4 For the input image, after being processed by the above four parts, the restored face image can be output. This solution is to perform indiscriminate restoration on the face in the image. Figure 4 This is a system block diagram of the face restoration process after optimization in this embodiment. Figure 4 exist Figure 3 Based on the framework structure in , a blur detection module is added. Specifically, blur detection is performed after face detection and a repair weight value is determined. The repair weight value is used to decide whether to repair the detected face and the degree of repair. Therefore, by adding the blur detection module, the occurrence of visual defects that may be caused by traditional face repair schemes can be avoided, and the effect of image repair can be enhanced.
[0120] In this embodiment, a blur detection module is added to the face restoration process, and the blur detection module determines the restoration weight value based on the blur, and the restoration weight value is used to determine whether restoration is needed and the degree of restoration. It is mainly divided into two technical points, one is the blur detection method; the other is the restoration weight value determination and the restoration face fusion method. The implementation methods of these two steps are described in detail below:
[0121] The first step is to calculate the blur value. The second-order derivative of the image is measured by the Laplace operator to highlight the image areas that contain rapid intensity changes. If its variance is low, it means that there are very few edges in the image. On the contrary, if the variance is high, it means that the image edges are obvious and the image quality is clearer.
[0122] The second step is to determine the restoration weight value and the fusion method of the restored face. The calculation in the first step can get the blur value of a single face. It is important to define whether restoration is needed and the threshold of the restoration fusion degree. The restoration weight value α (ranging from 0 to 1) is set here. Specifically, it can be understood that the percentage of fusion of the restored face and the original face is α and 1-α. The result achieved in this way neutralizes the restored face and the original face, and the performance is more natural. In special scenes, such as the change from blurred to clear face in the video, a natural transition can be achieved.
[0123] In the specific implementation, in order to obtain the appropriate threshold range of face restoration fusion degree, a large number of actual faces are used to obtain blur values and sort them, and a preset blur interval [a, b] is defined by analyzing the actual restoration effect. Figure 5 The figure shows a schematic diagram of the linear relationship between the repair weight value and the blur. The specific logic is as follows:
[0124] When the fuzziness is less than a( Figure 5 Ⅰ in the figure), α is set to 0, that is, no face restoration is performed; when the blur is between a and b ( Figure 5 Ⅱ in the figure), α is set to a linear value between 0 and 1, that is, the degree of face restoration transitions between 0 and 100%; when the blur is greater than b( Figure 5 Ⅲ in the figure), α is set to 1, that is, face restoration is performed and the result completely uses the face restoration part.
[0125] In this embodiment, through the implementation of the above two steps, by calculating the face blur value and the corresponding restoration weight value, the repaired face is integrated into the original image to varying degrees, avoiding the enhancement problem of blurred faces, thereby achieving the best effect of face quality restoration while avoiding flawed results.
[0126] Embodiment 2
[0127] Figure 6 The block diagram of the face restoration device in the image according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Figure 6 As shown, the face restoration device 600 in the image may include: a face position determination module 610, a blur detection module 620, a restoration weight value determination module 630 and a face restoration module 640, wherein:
[0128] The face position determination module 610 is used to obtain an image to be processed and perform face detection on the image to be processed to obtain one or more face positions;
[0129] A blur detection module 620 is used to perform blur detection on each face position to obtain blur corresponding to each face position;
[0130] A restoration weight value determination module 630, configured to determine a restoration weight value corresponding to each face position according to the blurriness corresponding to each face position;
[0131] The face restoration module 640 is used to perform face restoration on the face position according to the restoration weight value corresponding to each face position.
[0132] In an optional embodiment of the present application, the blur detection module 620 includes:
[0133] The blur detection submodule is used to perform blur detection on each face position respectively through the Laplace operator to obtain the blur corresponding to each face position.
[0134] In an optional embodiment of the present application, the repair weight value determination module 630 includes:
[0135] The restoration weight value determination submodule is used to determine the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in the preset blurriness interval; wherein the minimum value of the preset blurriness interval is the first preset threshold value, and the maximum value is the second preset threshold value.
[0136] In an optional embodiment of the present application, the repair weight value determination submodule includes:
[0137] The first weight value determining unit is used to determine that the restoration weight value corresponding to the face position is 0 when the blurriness corresponding to the face position is less than or equal to a first preset threshold.
[0138] In an optional embodiment of the present application, the repair weight value determination submodule includes:
[0139] The second weight value determining unit is used to determine that the restoration weight value corresponding to the face position is 1 when the blurriness corresponding to the face position is greater than or equal to a second preset threshold.
[0140] In an optional embodiment of the present application, the repair weight value determination submodule includes:
[0141] The third weight value determining unit is used to determine the restoration weight value corresponding to the face position according to a preset linear relationship when the blurriness corresponding to the face position is greater than a first preset threshold and less than a second preset threshold.
[0142] In an optional embodiment of the present application, the face restoration module 640 includes:
[0143] A face repair submodule, used to repair the face position by a preset face repair algorithm to obtain a repaired face;
[0144] A face mask extraction submodule, used to extract a face mask from the face position;
[0145] The repaired face fusion submodule is used to fuse the repaired face into the face mask to obtain the target face according to the repair weight value.
[0146] Embodiment 3
[0147] Figure 7 The schematic diagram of the hardware architecture of a computer device 10000 suitable for implementing the method for face restoration in an image according to the third embodiment of the present application is shown schematically. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle-mounted terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Figure 7 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them:
[0148] The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as a hard disk or a memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 10010 may also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed in the computer device 10000, such as program code of the face restoration method in the image, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or will be output.
[0149] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.
[0150] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0151] It should be pointed out that Figure 7 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0152] In this embodiment, the face repair method in the image stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of the present application.
[0153] Embodiment 4
[0154] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for repairing a face in an image in the embodiment are implemented.
[0155] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the computer-readable storage medium may also include both an internal storage unit of a computer device and an external storage device thereof. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on the computer device, such as the program code of the face restoration method in the image in the embodiment, etc. In addition, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.
[0156] Embodiment 5
[0157] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.
[0158] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by general-purpose computer devices, they can be concentrated on a single computer device, or distributed on a network composed of multiple computer devices, optionally, they can be implemented by executable program codes of computer devices, so that they can be stored in a storage device and executed by the computer device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0159] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for restoring a face in an image, characterized in that: The method comprises: Acquire an image to be processed, and perform face detection on the image to be processed to obtain one or more face positions; Perform blur detection on each face position respectively to obtain the blur corresponding to each face position; Determine a restoration weight value corresponding to each face position according to the blurriness corresponding to each face position; Face restoration is performed on the face position according to the restoration weight value corresponding to each face position.
2. The method for face restoration in an image according to claim 1, characterized in that: The fuzziness detection is performed on each face position respectively to obtain the fuzziness corresponding to each face position, including: Through the Laplace operator, the blurriness of each face position is detected respectively to obtain the blurriness corresponding to each face position.
3. The method for face restoration in an image according to claim 1, characterized in that: The determining the restoration weight value corresponding to each face position according to the blurriness corresponding to each face position includes: The restoration weight value corresponding to each face position is determined according to the position of the blurriness corresponding to each face position in the preset blurriness range; wherein the minimum value of the preset blurriness range is the first preset threshold value, and the maximum value is the second preset threshold value.
4. The method for face restoration in an image according to claim 3, characterized in that: The step of determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in the preset blurriness range includes: When the blurriness corresponding to the face position is less than or equal to a first preset threshold, the restoration weight value corresponding to the face position is determined to be 0.
5. The method for face restoration in an image according to claim 3, characterized in that: The step of determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in the preset blurriness range includes: When the blurriness corresponding to the face position is greater than or equal to a second preset threshold, the restoration weight value corresponding to the face position is determined to be 1.
6. The method for face restoration in an image according to claim 3, characterized in that: The step of determining the restoration weight value corresponding to each face position according to the position of the blurriness corresponding to each face position in the preset blurriness range includes: When the blurriness corresponding to the face position is greater than a first preset threshold and less than a second preset threshold, a restoration weight value corresponding to the face position is determined according to a preset linear relationship.
7. The method for face restoration in an image according to claim 1, characterized in that: The performing face restoration on the face position according to the restoration weight value corresponding to each face position includes: Repairing the face position by a preset face repair algorithm to obtain a repaired face; Extracting a face mask from the face position; According to the restoration weight value, the restored face is fused into the face mask to obtain a target face.
8. A device for restoring a face in an image, characterized in that: The device comprises: A face position determination module is used to obtain an image to be processed and perform face detection on the image to be processed to obtain one or more face positions; A blur detection module is used to perform blur detection on each face position to obtain blur corresponding to each face position; A restoration weight value determination module, used to determine the restoration weight value corresponding to each face position according to the blurriness corresponding to each face position; The face restoration module is used to perform face restoration on the face position according to the restoration weight value corresponding to each face position.
9. A computer device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein: The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the method for repairing a face in an image according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method for repairing a face in an image according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for repairing a face in an image according to claims 1 to 7 are implemented.
Citation Information
Patent Citations
Training method of image quality enhancement model, image quality enhancement method and related device
CN116452456A
Face restoration method and device and electronic equipment
CN117726554A
Face blur detection method and apparatus, computer device and storage medium
WO2021179471A1
