Certificate photo generation method and device, and electronic equipment
By aligning and overlaying facial images and background images, and using a diffusion model to generate ID photos, the problem of time-consuming and labor-intensive ID photo shooting in the past has been solved, and efficient and convenient high-quality ID photo generation has been achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WONDERSHARE TECH (HUNAN) CO LTD
- Filing Date
- 2024-12-27
- Publication Date
- 2026-07-03
AI Technical Summary
Existing methods for taking ID photos are time-consuming and labor-intensive, and cannot meet the needs of special circumstances, thus failing to efficiently generate high-quality ID photos.
By acquiring facial images and background images, aligning and overlaying them, and using a diffusion model to perform face swapping, an ID photo in a specified scenario can be generated, and identity information can be embedded.
It enables efficient generation of high-quality ID photos, meeting the shooting needs of different ID documents, especially convenient shooting in special circumstances.
Smart Images

Figure CN119963692B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and more specifically, to a method, apparatus, and electronic device for generating ID photos. Background Technology
[0002] Currently, the demand for ID photos is widespread across various fields, such as applying for ID cards, passports, driver's licenses, and various professional qualification certificates. Different documents may have different photo requirements, but all must accurately reflect the holder's identity.
[0003] Current methods for taking ID photos typically require going to a photo studio or self-service photo booth, which is not only time-consuming and energy-intensive, but may also require multiple attempts due to unsatisfactory results, increasing costs. Furthermore, existing methods may not meet the needs of certain special circumstances, such as physical limitations or time constraints. Summary of the Invention
[0004] To address the problems existing in the prior art, embodiments of this application provide a method, apparatus, and electronic device for generating ID photos. By matching the face of a user-provided facial image with a background image and performing a face-swapping operation on the background image, high-quality ID photos can be generated efficiently.
[0005] In a first aspect, embodiments of this application provide a method for generating ID photos, comprising the following steps:
[0006] Obtain the face image and background image;
[0007] Align the face in the face image with the face in the base image;
[0008] The faces in the aligned face image are overlaid with the faces in the base image to adapt the faces in the face image to the base image; and
[0009] The faces adapted to the base image are subjected to a face-swapping operation on the base image to generate the ID photo in the specified scene.
[0010] Further, aligning the face in the face image with the face in the base image includes:
[0011] Align the face boundary of the base image with the face in the face image using deformation; and
[0012] The face in the face image is corrected to align with the face pose in the base image.
[0013] Furthermore, after performing a face-swapping operation on the face adapted to the base image to generate the ID photo for the specified scene, the method further includes:
[0014] Identity information is embedded into the ID photo.
[0015] Furthermore, the step of performing a face-swapping operation on the base image to generate the ID photo in the specified scene includes:
[0016] The diffusion model is used to perform face swapping on the faces adapted to the base image to generate the ID photo in the specified scene.
[0017] Furthermore, before performing image-to-image face swapping on the face adapted to the base image using a diffusion model to generate the ID photo for the specified scene, the method further includes:
[0018] The diffusion model is trained.
[0019] Furthermore, the acquisition of the face image and background image includes:
[0020] Acquire a face image and generate the base image based on the text prompts.
[0021] Furthermore, after acquiring the face image and the background image, the process also includes:
[0022] The face image is detected and segmented, and the background of the face image is removed.
[0023] Secondly, embodiments of this application also provide an ID photo generation device, comprising:
[0024] The image acquisition module is used to acquire face images and background images;
[0025] A face alignment module is used to align the face in the face image with the face in the base image;
[0026] A base image adaptation module is used to overlay the face of the aligned face image with the face of the base image to adapt the face of the face image to the base image; and
[0027] The ID photo generation module is used to perform face swapping on the base image to generate the ID photo in a specified scene.
[0028] Thirdly, embodiments of this application also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the ID photo generation method according to the first aspect described above.
[0029] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, the computer program being used to implement the ID photo generation method according to the first aspect described above.
[0030] The embodiments of this application bring the following beneficial effects:
[0031] The ID photo generation method provided in this application first acquires a face image and a background image. Then, the face in the face image is aligned with the face in the background image, and the aligned face in the face image is superimposed on the face in the background image to adapt the face in the face image to the background image. Finally, a face-swapping operation is performed on the adapted face on the background image to generate the ID photo for a specified scene. The ID photo generation method provided in this application efficiently generates high-quality ID photos by matching the face in a user-provided face image with the background image and performing a face-swapping operation on the background image. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.
[0033] Figure 1 A flowchart illustrating the ID photo generation method provided in this application embodiment;
[0034] Figure 2 A structural block diagram of the ID photo generation device provided in the embodiments of this application;
[0035] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0036] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0037] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of this application.
[0038] In the specification, claims, and accompanying drawings of this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0039] Figure 1 This is a flowchart of a method for generating ID photos according to an embodiment of this application. Figure 1 As shown, the method for generating ID photos according to an embodiment of this application includes the following steps:
[0040] S101: Obtain face image and background image;
[0041] The facial image mentioned here usually refers to a portrait image provided by the user, while the background image is an image with the style and background desired by the user, thus providing an image template for generating ID photos.
[0042] S102: Align the face in the face image with the face in the base image;
[0043] In other words, the face boundary in the base image and the face in the face image are deformed and aligned to ensure that the length of the face in the base image and the user's face are consistent, thereby ensuring the authenticity of the generated ID photo.
[0044] S103: Overlay the face of the aligned face image with the face of the base image to adapt the face of the face image to the base image; and
[0045] After aligning the face in the face image with the face in the background image, the aligned face in the face image is superimposed on the face in the background image to adapt the face in the face image to the background image, thereby further ensuring the realistic effect of the generated ID photo.
[0046] S104: Perform a face-swapping operation on the base image to generate the ID photo in the specified scene.
[0047] As described above, the face in the face image is aligned with the face in the base image, and the aligned face in the face image is superimposed on the face in the base image. Then, through a face-swapping operation, the face adapted to the base image is transferred to the base image to generate the ID photo in the specified scene.
[0048] Therefore, in the ID photo generation method provided in this application embodiment, a face image and a background image are first obtained. Then, the face in the face image is aligned with the face in the background image, and the aligned face in the face image is superimposed on the face in the background image to adapt the face in the face image to the background image. Finally, a face-swapping operation is performed on the adapted face on the background image to generate the ID photo in the specified scene. The ID photo generation method provided in this application embodiment matches the face in the user-provided face image with the background image and performs a face-swapping operation on the background image, thereby efficiently generating high-quality ID photos.
[0049] Furthermore, in some embodiments of this application, aligning the face in the face image with the face in the background image includes:
[0050] Align the face boundary of the base image with the face in the face image using deformation; and
[0051] The face in the face image is corrected to align with the face pose in the base image.
[0052] As mentioned above, by aligning the face boundary of the base image with the face of the face image through deformation and correcting the face of the face image to align with the face pose of the base image, the authenticity of the generated ID photo can be ensured, that is, a high-quality ID photo can be generated.
[0053] Furthermore, in some embodiments of this application, after performing a face-swapping operation on the face adapted to the base image to generate the ID photo for a specified scene, the method further includes:
[0054] Identity information is embedded into the ID photo.
[0055] Specifically, embedding identity information into the ID photo enables the photo to be matched with the user's identity information, thus facilitating the identification of the user's information from the generated ID photo. The preferred method for identity embedding here is a variant model based on PULID.
[0056] Furthermore, in some embodiments of this application, the step of performing a face-swapping operation on the base image to generate the ID photo in a specified scene includes:
[0057] The diffusion model is used to perform face swapping on the faces adapted to the base image to generate the ID photo in the specified scene.
[0058] Specifically, by using a diffusion model to perform image-to-image face swapping on the faces adapted to the base image, high-quality ID photos in a specified scenario can be generated, ensuring the authenticity of the generated ID photos.
[0059] Furthermore, in some embodiments of this application, before performing image-to-image face swapping on the face adapted to the base image using a diffusion model to generate the ID photo for a specified scene, the method further includes:
[0060] The diffusion model is trained.
[0061] Specifically, the diffusion model needs to be trained in advance to improve the quality of the ID photos generated by the diffusion model. The training process is as follows: a training dataset is constructed, including acquiring a preset number of face images and background images to form image pairs as the training dataset. The training dataset is then input into the diffusion model for training, and the diffusion model is optimized using a preset loss function to obtain the trained face image generation model.
[0062] Furthermore, in some embodiments of this application, acquiring the face image and background image includes:
[0063] Acquire a face image and generate the base image based on the text prompts.
[0064] Specifically, the text prompts mentioned here are image editing instructions output by the user to the model to obtain a background image of the desired style, thereby providing a template for subsequent ID photos.
[0065] Furthermore, in some embodiments of this application, after acquiring the face image and the background image, the method further includes:
[0066] The face image is detected and segmented, and the background of the face image is removed.
[0067] Specifically, the system detects and segments the facial images provided by the user, eliminating background and other factors that may interfere with identity verification, thereby further ensuring the authenticity of the generated ID photos.
[0068] Figure 2 This is a structural block diagram of the ID photo generation device 200 provided in the embodiments of this application. Figure 2 As shown, the ID photo generation device 200 of this application embodiment includes: an image acquisition module 210, a face alignment module 220, a background image adaptation module 230, and an ID photo generation module 240, wherein:
[0069] Image acquisition module 210 is used to acquire face images and background images;
[0070] The face alignment module 220 is used to align the face in the face image with the face in the base image;
[0071] The base image adaptation module 230 is used to overlay the face of the aligned face image with the face of the base image to adapt the face of the face image to the base image; and
[0072] The ID photo generation module 240 is used to perform a face swapping operation on the base image to generate the ID photo in a specified scene.
[0073] In the ID photo generation apparatus provided in this application embodiment, a face image and a background image are first acquired. Then, the face in the face image is aligned with the face in the background image, and the aligned face in the face image is superimposed on the face in the background image to adapt the face in the face image to the background image. Finally, a face-swapping operation is performed on the adapted face on the background image to generate the ID photo in a specified scene. The ID photo generation method provided in this application embodiment matches the face in a user-provided face image with a background image and performs a face-swapping operation on the background image, thereby efficiently generating high-quality ID photos.
[0074] It should be noted that the specific implementation of the ID photo generation device in this application embodiment is similar to the specific implementation of the ID photo generation method in this application embodiment. Please refer to the description in the method section for details, which will not be repeated here.
[0075] Figure 3 This is a schematic diagram of the structure of the electronic device 300 according to an embodiment of this application.
[0076] like Figure 3 As shown, the electronic device 300 includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from the storage section 302 into a random access memory (RAM) 303. The RAM 303 also stores various programs and data required for the operation of the electronic device 300. The CPU 301, ROM 302, and RAM 303 are interconnected via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0077] The following components are connected to I / O interface 305: an input section 306 including a keyboard, mouse, etc.; an output section 307 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN card, modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to I / O interface 305 as needed. A removable medium 311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 310 as needed so that computer programs read from it can be installed into storage section 308 as needed.
[0078] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a machine-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 309, and / or installed from removable medium 311. When the computer program is executed by central processing unit (CPU) 301, it performs the functions defined in the electronic device of this application.
[0079] It should be noted that the computer-readable medium shown in this application may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electronic device, apparatus, or device that is electrical, magnetic, optical, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.
[0080] In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used or combined with an electronic device, apparatus, or device by instructions. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use or combined with an electronic device, apparatus, or device by instructions. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wireline, optical fiber, RF, etc., or any suitable combination thereof.
[0081] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of processing and receiving devices, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based electronic device that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0082] The units or modules described in the embodiments of this application can be implemented in software or hardware. The described units or modules can also be housed in a processor, which executes the program to implement the ID photo generation method.
[0083] Obtain the face image and background image;
[0084] Align the face in the face image with the face in the base image;
[0085] The faces in the aligned face image are overlaid with the faces in the base image to adapt the faces in the face image to the base image; and
[0086] The faces adapted to the base image are subjected to a face-swapping operation on the base image to generate the ID photo in the specified scene.
[0087] In another aspect, this application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable storage medium stores one or more programs, which, when used by one or more processors, execute the ID photo generation method described in this application:
[0088] Obtain the face image and background image;
[0089] Align the face in the face image with the face in the base image;
[0090] The faces in the aligned face image are overlaid with the faces in the base image to adapt the faces in the face image to the base image; and
[0091] The faces adapted to the base image are subjected to a face-swapping operation on the base image to generate the ID photo in the specified scene.
[0092] In another aspect, this application also provides a computer program product, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer program product stores one or more programs, which, when used by one or more processors, execute the ID photo generation method described in this application:
[0093] Obtain the face image and background image;
[0094] Align the face in the face image with the face in the base image;
[0095] The faces in the aligned face image are overlaid with the faces in the base image to adapt the faces in the face image to the base image; and
[0096] The faces adapted to the base image are subjected to a face-swapping operation on the base image to generate the ID photo in the specified scene.
[0097] The above description is merely a preferred embodiment of this application and does not limit the patent scope of this application. Any equivalent structural transformations made based on the content of this application's specification and drawings under the concept of this application, or direct / indirect applications in other related technical fields, are included within the patent protection scope of this application.
Claims
1. A method of generating an ID photo, characterized by, Includes the following steps: Acquire a face image, detect and segment the face image and remove the background, and generate a background image that matches the specified ID photo scene based on text prompts; The face boundary of the base image is deformed and aligned with the face of the face image after removing the background, and the face of the face image is corrected in pose so that the face of the face image and the face of the base image are aligned in geometric shape and pose angle. The faces in the aligned face image are superimposed on the faces in the base image to adapt the faces in the face image to the base image; and A diffusion model, specifically trained on a training dataset using image pairs of face images and ID photo backgrounds, is used to perform face-swapping operations on the backgrounds to generate initial ID photos for specified ID photo scenarios. A variant model based on PULID is then used to embed user identity information into the initial ID photo to generate a final ID photo that meets the requirements of the specified ID photo scenario.
2. An identification photograph generating apparatus characterized by comprising: include: The image acquisition module is used to acquire a face image, detect and segment the face image and remove the background, and generate a background image that conforms to the specified ID photo scene based on the text prompt words. The face alignment module is used to align the face boundary of the base image with the face of the face image after removing the background, and to perform pose correction on the face of the face image so that the face of the face image is aligned with the face of the base image in terms of geometric shape and pose angle. The base image adaptation module is used to overlay the face of the aligned face image with the face of the base image to adapt the face of the face image to the base image; and The ID photo generation module is used to construct a diffusion model specifically trained on a training dataset using image pairs of face images and ID photo background images. The model performs face swapping on the background image to generate an initial ID photo for a specified ID photo scenario. Then, it uses a variant model based on PULID to embed user identity information into the initial ID photo to generate a final ID photo that meets the requirements of the specified ID photo scenario.
3. An electronic device, comprising: It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the ID photo generation method according to any one of claims 1.
4. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program for implementing the ID photo generation method according to any one of claims 1.