Face swapping method, device, equipment and computer storage medium
By identifying and extracting key points and expression gestures in facial images, and using GAN model fusion to generate natural face-changing images, it solves the problem of unnatural facial expressions in the existing technology and significantly improves the face-changing effect.
Patent Information
- Application Number
- CN201910344573.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-26
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-04-14
AI Technical Summary
In the existing face-changing technology, the facial expression is unnatural, which affects the face-changing effect.
By identifying the key points in the second face image, extracting the block diagram of the area circled by the key points, the first expression gesture map is obtained, and inputs it with the first face image into the generative adversarial network GAN model, and fuses it to generate a natural representation. face image.
The natural expressions and postures of the characters after face replacement are improved, and the effect of face replacement is improved.
Smart Images

Figure CN111860044B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing technology, and in particular relates to a face swapping method, device, equipment and computer storage medium. Background Art
[0002] With the development of the Internet, social software for mass entertainment is increasing. In many social software with functions such as live broadcast, video shooting and image editing, face swapping has gradually become a new hot spot for mass entertainment and has an increasingly wide range of application scenarios. Face swapping or face-changing technology refers to replacing one person's face with another person's face in an image or video.
[0003] However, in the current face-swapping technology, the images or videos obtained after exchanging faces have unnatural facial expressions, which affects the effect of face-swapping. Summary of the invention
[0004] The embodiments of the present invention provide a face swapping method, device, equipment and computer storage medium, which can perform face swapping operations by stripping off the expressions on the target person's face, thereby improving the naturalness of face swapping.
[0005] On the one hand, an embodiment of the present invention provides a face swapping method, the method comprising:
[0006] Obtain a first face image and a second face image;
[0007] Identify key points in the second face image, extract a frame diagram of an area encircled by the key points, and obtain a first expression posture diagram;
[0008] The first expression posture graph and the first face image are input into a generative adversarial network (GAN) model to obtain a face-changing image that is a fusion of the first expression posture graph and the first face image.
[0009] On the other hand, an embodiment of the present invention provides a face swapping device, the device comprising:
[0010] An image acquisition module, used to obtain a first face image and a second face image;
[0011] An expression extraction module, used for identifying key points in the second face image, extracting a frame diagram of an area delineated by the key points, and obtaining a first expression posture diagram;
[0012] The expression fusion module is used to input the first expression posture graph and the first face image into the generative adversarial network (GAN) model to obtain a face-changing image after the first expression posture graph and the first face image are fused.
[0013] On the other hand, an embodiment of the present invention provides a face swapping device, the device comprising:
[0014] a processor and a memory storing computer program instructions;
[0015] When the processor executes the computer program instructions, a face-swapping method as described in any one of the above is implemented.
[0016] On the other hand, an embodiment of the present invention provides a computer storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, a face-changing method as described above is implemented.
[0017] The face-changing method, device, equipment and computer storage medium of the embodiment of the present invention can extract the frame diagram of the area circled by the key points in the second face image to be replaced, and obtain the first expression posture diagram, so that the first expression posture diagram only contains the expression information of the key parts in the second face image; then the first expression posture diagram and the first face image are input into the trained GAN network for fusion, and the face-changing image after the first expression posture diagram and the first face image are fused can be obtained. At this time, the face-changing image is the result image after the second face image is replaced with the first face image. Since in the present invention, the expression information in the second face image is extracted separately, and the expression information can reflect the face expression and the face posture angle in addition to the face expression, the first face image is directly adjusted according to the extracted first expression posture diagram, and a natural face-changing image with the expression and posture of the second face image can be obtained, which improves the naturalness of the expression and posture of the character after the face-changing as much as possible, and the face-changing effect is better. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following is a brief introduction to the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0019] Figure 1 is a flowchart of a face swapping method provided by an embodiment of the present invention;
[0020] Figure 2 It is a flowchart of a GAN model training process provided by an embodiment of the present invention;
[0021] Figure 3 This is a schematic diagram of the working process of the GAN network;
[0022] Figure 4 is a schematic diagram of a first expression posture diagram;
[0023] Figure 5 is a structural schematic diagram of a face swapping device provided by an embodiment of the present invention;
[0024] Figure 6 It is a structural schematic diagram of a face swapping device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0026] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0027] In order to solve the problems in the prior art, the embodiments of the present invention provide a face swapping method, device, equipment and computer storage medium. The face swapping method provided by the embodiments of the present invention is first introduced below.
[0028] Figure 1 The following is a flow chart of a face swapping method provided by an embodiment of the present invention. The method comprises:
[0029] Step s11: obtaining a first face image and a second face image;
[0030] The face-changing operation refers to replacing the face of person B in an image or video with the face of person A, so that the face of person A in the face-changing image or video can show the expression of the original face of person B and be as natural as possible. The first face image refers to the image of the face of person A, and the second face image refers to the image of the face of person B; and the first face image and the second face image mentioned in the present invention refer only to the image of the face part, and are not limited to the hair and background part of the person.
[0031] Step s12: identifying key points in the second face image, extracting a frame diagram of an area encircled by the key points, and obtaining a first expression posture diagram;
[0032] Figure 4 It is a schematic diagram of the first expression and posture diagram; the key points in the face image refer to the feature points of the part that can characterize the features of the face, which are used to distinguish the differences between different faces. The purpose of obtaining the key points is to determine the shape of each part of the face, and then the expression and posture of the face image can be characterized accordingly. The expression here refers to features such as laughing, smiling, and sadness, and the posture refers to the face angle features such as turning the head left and right, turning the head up and down, tilting the head in a plane, and facing the front. The frame diagram of the area encircled by the key points on the face, the frame diagram here is only used to show the outline of the area encircled by the key points on the face, and the frame diagram is only an image formed by connecting the feature points, and does not contain face attributes, such as skin, lighting, etc., because the present invention only wants to determine the expression and posture information on the second face image according to the outline encircled by the frame diagram, because the shape of the frame diagram encircled by the key points can reflect the expression and posture of the person. Therefore, by extracting the above frame diagram, the expression information on the second face image can be extracted.
[0033] Step s13: inputting the first expression posture graph and the first face image into a generative adversarial network (GAN) model to obtain a face-changing image that is a fusion of the first expression posture graph and the first face image.
[0034] The face-changing method of the embodiment of the present invention can extract the frame diagram of the area circled by the key points in the second face image to be replaced, and obtain the first expression posture diagram, so that the first expression posture diagram only contains the expression information of the key parts in the second face image; then the first expression posture diagram and the first face image are input into the trained GAN network for fusion, and the face-changing image after the first expression posture diagram and the first face image are fused can be obtained, and at this time, the face-changing image is the result image after the second face image is replaced with the first face image. Since in the present invention, the expression information in the second face image is extracted separately, and the expression and posture of the face (face angle, etc.) can be characterized by the expression information of the face, the expression and posture of the first face image are directly adjusted according to the extracted expression information, and the face-changing image with the expression and posture of the second face image can be obtained, and the naturalness of the expression and posture of the character after the face-changing can be guaranteed as much as possible, and the face-changing effect is better.
[0035] in, Figure 3It is a schematic diagram of the working process of the GAN network; the GAN network includes a G network and a D network, G is a generator, which is used to generate data; D is a discriminator, which is responsible for judging whether the data is a true number. During the training process of the GAN network, the process is: G generates data and then inputs it into D, D compares the data generated by G with the true value data, and adjusts its own parameters and the parameters of G according to the comparison error. Among them, the parameters of G and D can be adjusted by the gradient ascent method or the gradient descent method. Of course, the present invention does not limit the adjustment algorithm of the internal parameters of the GAN network.
[0036] In the present invention, the first expression posture graph is input as a conditional factor of the GAN model, so that the output of the GAN model is controllable, thereby ensuring that the entire face-changing process can achieve the expected effect.
[0037] In a preferred embodiment, in step s12, the process of extracting a frame diagram of the area delimited by key points includes: extracting and connecting each key point to obtain a plurality of closed figures composed of the key points; and filling the closed figures with a preset color to obtain a first expression posture diagram.
[0038] Specifically, as mentioned in the above embodiments of the present invention, in order to enable the key points to determine the position and shape of the facial parts, the key points at each part should be combined and connected to form a closed figure that can surround the corresponding part (such as eyes). Afterwards, since the expression posture graph that the present invention wants to obtain is a frame diagram, that is, only an outline diagram, it is necessary to use a preset color to fill each closed figure, and then extract each closed figure after the color filling is completed, so as to obtain the first expression posture graph.
[0039] It can be further known that if the positions of two closed figures are symmetrical, different colors are used to fill the two closed figures respectively.
[0040] Since there are symmetrical parts on the face, such as eyebrows, eyes, etc., if these symmetrical parts are not distinguished, the subsequent GAN network may not be able to distinguish between left and right. If the left and right are mistaken, for example, if the shape of the left eyebrow is merged with the right eyebrow of the first face image, the expression in the final face-changing image is obviously different from that in the second face image, which leads to an unnatural face-changing image. Therefore, in order to avoid the problem of left and right inversion, this embodiment fills the symmetrical closed images with different colors, thereby facilitating the recognition of the subsequent GAN network. It should be noted that in the present invention, the filling colors corresponding to the closed figures at each part are already set. For example, the closed figure at the right eyebrow is filled with green, and the closed figure at the left eyebrow is filled with red. The subsequent GAN model can determine the part corresponding to the closed figure by identifying the color and overall position of each closed figure, and then merge it with the first face image. Of course, the present invention does not limit what kind of filling color is set for each part.
[0041] In a preferred embodiment, the areas defined by the key points include an eyebrow area, an eye area, a nose area, and a lip area.
[0042] Specifically, in the above embodiment, the area circled by the key points is limited to the area of the facial features, because the facial features are the parts that can best reflect the facial expressions, and when the face is in different angles and postures, the shapes of the facial features are obviously different, so the posture of the face can also be reflected based on the shapes of the facial features. Among them, the purpose of circled eyebrow areas by the key points is that for many people, when making different expressions and postures, in addition to the eyes, nose, and lips, the eyebrows will also move accordingly, so the information of the eyebrows can also reflect the expression information.
[0043] In addition, in a preferred embodiment, the area defined by the key points may also include the facial contour.
[0044] This is because the facial contours of different people are different. Therefore, if the facial contours are not replaced during the face-changing process, there will be an inconsistency between the replaced face and the body, resulting in an unnatural face-changing result. In addition, the shape of the facial contour can also intuitively reflect the angle and posture of the face.
[0045] The above are only two specific embodiments, which are mainly used in the scene where the whole face is replaced. In some scenes, such as the beauty scene, the user may only need to replace the eyes, for example, want to replace his eyes with the eyes of a star. In this case, the area circled by the key points can only include the eye area. Of course, the area circled by the key points depends on the needs of the application scene in which it is located, and the present invention does not limit this.
[0046] In addition, the number of key points in the present invention can be set to 68, 87 or 137. Of course, it can also be set to other values. The present invention does not limit the number of key points.
[0047] Figure 2 : is a flowchart of a GAN model training process provided by an embodiment of the present invention; the training process of the GAN network includes:
[0048] Step s21: selecting two face images belonging to the same person as the third face image and the fourth face image respectively;
[0049] Step s22: identifying key points in the fourth face image, extracting a frame diagram of the area encircled by the key points, and obtaining a second expression posture diagram;
[0050] Step s23: inputting the second expression posture graph and the third face image into the GAN network to be trained to obtain a face-changing image to be tested;
[0051] Step s24: comparing the face-swapped image to be tested with the fourth face image, and adjusting the internal parameters of the GAN network according to the comparison error;
[0052] Step s25: Determine whether the current comparison error meets the preset error requirement. If so, a GAN model is obtained. If not, a different face image is selected and the process returns to step s21. In this step, different face images are selected to repeat the above training operation until the comparison error meets the preset error requirement. The current GAN network is the trained GAN model.
[0053] Among them, this embodiment selects the same two face images at each training. The purpose of doing so is that in the GAN network training process, it is necessary to set a true value, that is, the target image that the final output can achieve in theory. However, since the purpose of the present invention is to improve the current face-changing method that is not natural enough, if two face images that do not belong to the same person are selected, it is difficult to obtain the corresponding true value, and if the face images of two people with the same expression are selected, the acquisition of training samples is more complicated. Therefore, this embodiment directly uses two face images of the same person with different expressions. In this way, after the face in face image 1 is fused with the expression in face image 2, the theoretical true value is face image 2, that is, the fourth face image mentioned above. This training method simplifies the process of obtaining training samples and true values, and facilitates the training of the GAN model.
[0054] In addition, when obtaining training samples, multiple groups of face images of the same person may be included, such as 10 groups of face images of Ms. Zhang, each group of face images including two face images with different expressions; or, the training samples may also include multiple groups of face images of different persons, such as 1 group of face images of Ms. Zhang, a group of face images of Ms. Wang, etc. Of course, the above are only several specific implementations, and the present invention does not limit the composition of the above training samples.
[0055] In other embodiments, during the training of the GAN model, the expression information in the face-changing image to be tested output by the GAN network can also be extracted to obtain the expression posture graph to be tested, and then the second expression posture graph is used as the true value to be compared with the expression posture graph to be tested to determine the comparison error. In this case, the training samples do not have to be limited to two face images of the same person, but any two face images can be used. This method further simplifies the process of obtaining training samples. Of course, the above are only a few specific implementation methods, and the present invention does not limit the specific training process of the GAN model.
[0056] Based on the analysis of the above training process, due to the current point-to-point face-changing method, the model used can only change the faces of two specific people or can only change the face of a fixed person. In the present invention, by training the GAN network, after the face image and the expression posture map are input later, the two can be fused in a suitable manner to obtain a face-changing image with a natural expression. Since the present invention only trains this fusion operation and is not limited to whose face image it is, the present invention is not limited to face-changing two fixed people, but can change the face of any two people, with small limitations, and can achieve many-to-many face-changing situations, with a wider range of applications. In addition, compared with the face-changing method of replacing pixels one by one, the embodiment of the present invention has a simple process and a higher speed and efficiency of face-changing.
[0057] In one embodiment, in step s13, after obtaining the face-changing image, it also includes: replacing the face part of the original image corresponding to the second face image with the face-changing image to obtain a face-changing completed image.
[0058] Specifically, after obtaining the face-changed image, since the face-changed image only contains the face part, it is also necessary to replace the face part in the original image corresponding to the second face image with the face-changed image to obtain the face-changed completed image.
[0059] The original image corresponding to the second face image is a video frame in the video to be replaced. Of course, whether the original image corresponding to the second face image is an independent image or a video frame in the video depends on the actual needs of the user, and the present invention does not limit this.
[0060] The embodiment of the present invention provides a face replacement device, Figure 3 : is a schematic diagram of the structure of a face swapping device provided by an embodiment of the present invention; the device comprises:
[0061] Image acquisition module 1, used to obtain a first face image and a second face image;
[0062] Expression extraction module 2, used for identifying key points in the second face image, extracting a frame diagram of the area delineated by the key points, and obtaining a first expression posture diagram;
[0063] The expression fusion module 3 is used to input the first expression posture graph and the first face image into the generative adversarial network GAN model to obtain a face-changing image after the first expression posture graph and the first face image are fused.
[0064] Figure 6 A schematic diagram of the hardware structure of a face swapping device provided in an embodiment of the present invention is shown.
[0065] The face swapping device may include a processor 301 and a memory 302 storing computer program instructions. The processor 301 reads and executes the computer program instructions stored in the memory 302 to implement any one of the face swapping methods in the above embodiments.
[0066] Specifically, the processor 301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiment of the present invention.
[0067] The memory 302 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 302 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 302 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 302 is a non-volatile solid-state memory. In a specific embodiment, the memory 302 includes a read-only memory (ROM). In appropriate cases, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM) or a flash memory or a combination of two or more of these.
[0068] In one example, the face swapping device may further include a communication interface 303 and a bus 310. Figure 6 As shown, the processor 301, the memory 302, and the communication interface 303 are connected via a bus 310 and communicate with each other.
[0069] The communication interface 303 is mainly used to implement the communication between the modules, devices, units and / or equipment in the embodiment of the present invention.
[0070] Bus 310 includes hardware, software or both, and the components of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 310 may include one or more buses. Although the embodiment of the present invention describes and shows a specific bus, the present invention considers any suitable bus or interconnection.
[0071] In addition, in combination with the face swapping method in the above embodiment, the embodiment of the present invention can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the face swapping methods in the above embodiment is implemented.
[0072] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.
[0073] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0074] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.
[0075] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system, module and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.
Claims
1. A face swapping method, characterized in that: include: Obtain a first face image and a second face image; Identify key points in the second facial image, extract a frame diagram of an area encircled by the key points, and obtain a first facial expression and posture diagram; Inputting the first expression posture graph and the first face image into a generative adversarial network (GAN) model to obtain a face-changing image after the first expression posture graph and the first face image are fused; The process of extracting the frame diagram of the area delineated by the key points includes: Extracting and connecting each of the key points to obtain a plurality of closed graphs composed of the key points; Fill the closed figure with a preset color to obtain the first facial expression posture figure; If the positions of the two closed figures are symmetrical, different colors are used to fill the two closed figures respectively.
2. The face replacement method according to claim 1, characterized in that: The training process of the generative adversarial network GAN model includes: Select two face images belonging to the same person as the third face image and the fourth face image respectively; Identify key points in the fourth facial image, extract a frame diagram of an area encircled by the key points, and obtain a second facial expression posture diagram; Inputting the second expression posture graph and the third face image into a generative adversarial network (GAN) model to be trained to obtain a face-swapped image to be tested; Comparing the face-swapped image to be tested with the fourth face image, and adjusting internal parameters of the generative adversarial network (GAN) model according to the comparison error; Select different face images and repeat the above operation until the comparison error meets the preset error requirement, thereby obtaining the generative adversarial network GAN model.
3. The face replacement method according to claim 1, characterized in that: After obtaining the face-changing image obtained by fusing the first expression posture graph with the first face image, the method further includes: The face-changing image is used to replace the face part in the original image corresponding to the second face image to obtain a face-changing completed image.
4. The face replacement method according to claim 3, characterized in that: The original image corresponding to the second facial image is a video frame in the video to be replaced with a face.
5. The face replacement method according to claim 1, characterized in that: The areas defined by the key points include an eyebrow area, an eye area, a nose area, and a lip area.
6. A face replacement device, characterized in that: The device comprises: An image acquisition module, used to obtain a first face image and a second face image; An expression extraction module, used for identifying key points in the second facial image, extracting a frame diagram of an area delineated by the key points, and obtaining a first expression posture diagram; An expression fusion module, used for inputting the first expression posture graph and the first face image into a generative adversarial network (GAN) model to obtain a face-changing image after the first expression posture graph and the first face image are fused; The process of extracting the frame diagram of the area delineated by the key points includes: Extracting and connecting each of the key points to obtain a plurality of closed graphs composed of the key points; Fill the closed figure with a preset color to obtain the first facial expression posture figure; If the positions of the two closed figures are symmetrical, different colors are used to fill the two closed figures respectively.
7. A face-swapping device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the face swapping method as described in any one of claims 1-5 is implemented.
8. A computer storage medium, characterized in that: The computer storage medium stores computer program instructions, and when the computer program instructions are executed by the processor, the face swapping method as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Face reconstruction method, apparatus and device based on reconstruction network, medium and product
CN108776983A
Video processing method and apparatus, and electronic device
CN109151340A
