Image generation method and device, electronic equipment and computer readable storage medium
Through background cutout and feature extraction technology, combined with the image generation model of multiple characters, real-person images that conform to a specific style are generated, which solves the problem of high cost of obtaining real-person Cosplay images in the existing technology and achieves efficient and low-cost image generation. .
Patent Information
- Application Number
- CN202410850391.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-09-27
AI Technical Summary
In the existing technology, obtaining a specific style of real-person Cosplay image requires labor and time, and the economic cost is high.
By obtaining real-person images for background cutout processing, character feature text information is extracted, and the target image generation model is used to generate images that conform to a specific style. The model is integrated with image generation models of multiple different characters and the image generation model of the target character to generate The image area outside the facial contour area.
It achieves the batch generation of images of specified real people playing target roles without labor and time, at low economic cost, and reduces the cost of obtaining real-person images of specific styles.
Smart Images

Figure CN118710753A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an image generation method, device, electronic device and computer-readable storage medium. Background Art
[0002] As a cultural activity, Cosplay (Costume Play, Cosplay) has many positive effects on game operations, including increasing game visibility, enhancing the cohesion of the player community, improving player participation, and providing feedback for game design. For example, when carrying out Cosplay activities for a certain game, users can choose their favorite game characters and use props, costumes, and makeup to imitate and play the game characters to perform or restore a certain plot in reality.
[0003] In the related art, making a set of real-life images of a specific style, such as Cosplay photos, usually requires a combination of photography techniques, post-processing, creative ideas, and the participation of photographers, models, image post-production personnel, etc. In order to reasonably use the real-life Cosplay images that meet the specific style, it is also necessary to obtain the right to use the image, and negotiate and sign an authorization agreement with the owner of the real-life images of the specific style.
[0004] However, the above-mentioned related technologies require labor and time to obtain real-person images of a specific style, and the economic cost is high. Summary of the invention
[0005] The present application provides an image generation method, device, electronic device and computer-readable storage medium to solve the problem of high cost in obtaining real-person images of a specific style in the prior art.
[0006] In a first aspect, an embodiment of the present application provides an image generation method, the method comprising:
[0007] Acquire a first real-person image and perform background subtraction processing on the first real-person image to obtain a second real-person image;
[0008] Obtaining character feature text information for the image to be generated;
[0009] Performing facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, wherein the facial mask image is used to indicate the shape and position of a facial contour area in the second real person image;
[0010] The second real-person image, the character feature text information, and the face mask image are input into a target image generation model to obtain a first generated image output by the target image generation model; wherein the first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real-person image, and the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is trained based on multiple images of different characters, and the second image generation model is trained based on multiple images of the target character.
[0011] In a second aspect, an embodiment of the present application provides an image generating device, the device comprising:
[0012] A first acquisition module, used for acquiring a first real-person image and performing background subtraction processing on the first real-person image to obtain a second real-person image;
[0013] A second acquisition module is used to acquire character feature text information for the image to be generated;
[0014] a processing module, configured to perform facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, wherein the facial mask image is used to indicate the shape and position of a facial contour area in the second real person image;
[0015] A control module is used to input the second real-person image, the character feature text information, and the face mask image into a target image generation model to obtain a first generated image output by the target image generation model; wherein the first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real-person image, the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is trained based on multiple images of different characters, and the second image generation model is trained based on multiple images of the target character.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising:
[0017] A memory and a processor, wherein the memory and the processor are coupled;
[0018] The memory is used to store one or more computer instructions;
[0019] The processor is used to execute the one or more computer instructions to implement the image generation method described in any one of the first aspects above.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having one or more computer instructions stored thereon, characterized in that the instruction is executed by a processor to implement the image generation method described in any one of the first aspects above.
[0021] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the image generation method described in any one of the first aspects above.
[0022] Compared with the prior art, this application has the following advantages:
[0023] The image generation method provided by the present application obtains a first real-person image and performs background removal processing on the first real-person image to obtain a second real-person image. Obtain character feature text information for the image to be generated. Perform facial recognition processing on the second real-person image to obtain a face mask image corresponding to the second real-person image, and the face mask image is used to indicate the shape and position of the facial contour area in the second real-person image. The second real-person image, the character feature text information, and the face mask image are input into the target image generation model to obtain the first generated image output by the target image generation model. Among them, the first generated image is an image obtained by drawing the image area other than the facial contour area in the second real-person image by the target image generation model, and the target image generation model is obtained by integrating the first image generation model with the second image generation model. The first image generation model is obtained by training based on multiple images of different roles, and the second image generation model is obtained by training based on multiple images of the target role. The present application can batch generate images of the specified real person playing the target role by specifying a real-person image (i.e., the first real-person image), with extremely high image generation efficiency. The present application completely eliminates the need for the labor, time, and economic costs required to produce a set of real-person Cosplay images in a specific style, thereby greatly reducing the labor, time, and economic costs required to obtain real-person images in a specific style. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0025] Figure 1 A schematic diagram of a flow chart of an image generation method provided in one embodiment of the present application;
[0026] Figure 2 A schematic diagram of a first real person image before and after background removal provided in one embodiment of the present application;
[0027] Figure 3A schematic diagram of a second real person image and a corresponding face mask image provided in one embodiment of the present application;
[0028] Figure 4 A schematic diagram of a training sample image provided in one embodiment of the present application;
[0029] Figure 5 A schematic diagram of multiple images with different resolutions provided in one embodiment of the present application;
[0030] Figure 6 A schematic diagram of a training image and its corresponding training label provided in one embodiment of the present application;
[0031] Figure 7 A schematic diagram of a flow chart of an image generation method provided by another embodiment of the present application;
[0032] Figure 8 A schematic diagram of the effect of generating a second real-life image from a first real-life image provided in one embodiment of the present application;
[0033] Fig. 9 A schematic diagram of the effect of generating a second generated image from a first generated image according to one embodiment of the present application;
[0034] Fig.10 A schematic diagram of the structure of an image generating device provided in one embodiment of the present application;
[0035] Fig.11 A schematic diagram of the hardware structure of an electronic device provided in one embodiment of the present application.
[0036] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0037] In order to make the purpose, advantages and features of the present application clearer, the present application is described clearly and completely below in conjunction with the accompanying drawings and specific embodiments. In the following description, many specific details are set forth to facilitate a full understanding of the present application. However, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments, and all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0038] It should be noted that, in the description of the present application, the terms "first", "second", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance, and a specific order or sequence. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood in specific circumstances. In addition, in the description of the present application, unless otherwise specified, the term "multiple" refers to two or more. The term "and / or" describes the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are an "or" relationship. The terms "include" and "have" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0039] In order to facilitate understanding of the technical solution of the present application, the relevant concepts involved in the present application are first introduced.
[0040] Cosplay: Generally refers to the activity of realistically recreating a character or a plot in animation, comics, or games through clothing, props, makeup, styling, etc., with the help of photography, stage plays, and videography. It is generally called role-playing.
[0041] Coser: A person who plays a role. For example, in the pan-entertainment ecosystem of game products, Coser has always been an important part. In Cosplay activities, they restore and interpret different game characters, playing an important role in promoting the dissemination of game products and bringing more attention to them.
[0042] Stable Diffusion: An open source AI model that generates images directly from text, which aims to generate high-quality images. The core idea is to use the diffusion process to generate images. During the diffusion process, the model gradually increases the noise level of the image, thereby gradually blurring the image until a noisy image is finally generated. Then, through the reverse process, the model gradually reduces the noise level of the image and reconstructs the original image from the noisy image. In this way, Stable Diffusion can gradually add image details during the generation process, thereby generating more realistic and high-quality images.
[0043] WebUI: Based on Stable Diffusion, it is the most popular graphical program in the open source community. It provides functions such as text-generated images, images-generated images, AI zooming, text inversion, etc., and has a large number of various functional plug-ins. WebUI is one of the most important AI drawing creation tools used by individuals.
[0044] InstantID: An open source AI technology that can generate a full set of portraits in different styles using a single face photo in just a few seconds while maintaining the facial features of the person. The core advantages of InstantID are: 1. High-fidelity personalized image generation: InstantID can use a single reference image to generate high-quality, personal-featured images for a variety of styles. 2. Simplified operation process: Compared with the need for multiple reference images and complex fine-tuning, InstantID only needs one image and can quickly generate images without complex training or fine-tuning. 3. Strong compatibility: InstantID can seamlessly integrate currently popular pre-trained text-to-image models (such as SD1.5 and SDXL) as a highly versatile plug-in.
[0045] Based on the above problems, in order to solve the problem of high cost of obtaining real-life images of a specific style, the present application provides an image generation method, an image generation device corresponding to the method, an electronic device that can implement the image generation method, and a computer-readable storage medium. The following provides embodiments to describe the above method, device, electronic device, and computer-readable storage medium in detail.
[0046] In order to make the purpose and technical solution of the present application clearer and more intuitive, the method provided by the embodiment of the present application will be 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. It is understood that the following embodiments may exist separately, and the following embodiments and features in the embodiments may be combined with each other when there is no conflict between the embodiments provided in the present application, and the same or similar content will not be repeated in different embodiments. In addition, the step sequence in the following method embodiments is only an example, not a strict limitation, and in some cases, the steps shown or described may be performed in a different order from this.
[0047] The present application provides an image generation method, device, electronic device and computer-readable storage medium. Specifically, the image generation method of one embodiment of the present application can be executed by a computer device, wherein the computer device can be a terminal or a server. The terminal can be a terminal device such as a smart phone, a tablet computer, a laptop computer, a touch screen, etc. The terminal can also include a client, which can be a game application client, a browser client carrying a game program, or an instant messaging client. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0048] Next, combine Figure 1 , an image generation method provided in one embodiment of the present application is described, Figure 1 A flowchart of an image generation method provided in one embodiment of the present application.
[0049] like Figure 1 As shown, the image generation method includes steps S10-S40:
[0050] S10: Acquire a first real-person image and perform background subtraction processing on the first real-person image to obtain a second real-person image.
[0051] In the embodiment of the present application, the first real person image is a real person image containing any single real person. Taking Cosplay activities as an example, the real person can be a Coser in the Cosplay activity, that is, a person who plays a role. The first real person image includes the face of the real person and may also include the body part of the real person, which is only an example and is not limited in any way in the embodiment of the present application.
[0052] A method for obtaining a first real person image is to generate the first real person image using an artificial intelligence drawing tool such as Midjourney. Specifically, at least one photo of the same real person is input into the artificial intelligence drawing tool, and keywords (including the characteristics of the person such as smile, clothing style, background) are input, and instructions can also be set to specify the resolution size, color saturation, etc. of the output image. The artificial intelligence drawing tool uses the at least one photo of the same real person as a reference image, and based on the input keywords and instructions, generates a new image containing the real person, that is, the first real person image is obtained.
[0053] In the embodiment of the present application, the background of the first real person image is removed to obtain a second real person image after the background is removed. The purpose of this is to prevent background information other than the person in the first real person image from interfering with image generation.
[0054] Below, two optional implementations of the step of “performing background subtraction processing on the first real-person image” are exemplarily described.
[0055] In an optional implementation, a first real-person image is input into a preset background removal model to obtain a second real-person image output by the preset background removal model, where the preset background removal model is used to remove the background in the image.
[0056] As mentioned above, the preset background removal model is a neural network model for removing image background information. Among them, the preset background removal model can be BRIA-RMBG, or it can be a semantic segmentation model of the DeepLab series, which is only an example, and the embodiments of the present application do not limit this. Among them, BRIA AI RMBG is a background removal neural network model trained with more than 12,000 high-quality, high-resolution, manually annotated (pixel-level accuracy), and fully authorized images, which performs well in accuracy, efficiency, and applicability. Figure 2 This is a schematic diagram of a first real person image before and after background removal provided by one embodiment of the present application. Figure 2 As shown, it includes Figure (a) and Figure (b). Figure (a) is a first real person image, and Figure (b) is a second real person image obtained by removing the background of the first real person image.
[0057] An optional implementation method uses a background removal service such as Remove.bg. By simply uploading the first real-person image to the background removal service such as Remove.bg, the background removal service system can automatically identify and remove the background content in the first real-person image, and output a second real-person image after the background content is removed.
[0058] S20: Obtaining character feature text information for the image to be generated.
[0059] In the embodiment of the present application, the user can specify the feature information of the person in the image to be generated according to business requirements, so as to accurately guide the image generation process and ensure that the expected character image is drawn.
[0060] In an optional implementation manner, a possible implementation manner of S20 “obtaining character feature text information for the image to be generated” may include step S201:
[0061] S201: Input a second real-person image into a preset image-to-text model to obtain character feature text information output by the preset image-to-text model, where the character feature text information is used to describe character features in the second real-person image.
[0062] As mentioned above, the preset image-to-text model is a model that takes a real-life image as input and outputs text information that describes the features of the person and the background features of the image in the real-life image. The preset image-to-text model may be GPT4-Vision (GPT-4withVision), Stable Diffusion, etc., which are only examples and are not limited in any way in the embodiments of the present application.
[0063] Among them, GPT4-Vision is an improved image-to-text model based on the advanced language model GPT-4 (Generative Pre-trained Transformer 4). It can not only process and generate text, but also incorporate the ability to understand and interpret visual content.
[0064] In the embodiment of the present application, the second real person image is input into the preset image-to-text model, and the preset image-to-text model outputs text information for describing the characteristics of the person in the second real person image. The character characteristic text information obtained by this scheme is used as the character characteristic text information of the image to be generated, which helps the subsequently generated image to have the character characteristics of the person in the second real person image.
[0065] S30: Perform facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, where the facial mask image is used to indicate the shape and position of the facial contour area in the second real person image.
[0066] In an optional implementation, during the facial recognition process of the second real person image, the key facial points such as eyes, nose, and mouth are identified, and the position coordinates of each key facial point in the second real person image are obtained. According to the position coordinates of each key facial point, on a blank image of the same size as the second real person image, the shape of the face contour in the second real person image is drawn at the corresponding position on the blank image according to the position coordinates of each key facial point obtained above, that is, the face mask image corresponding to the second real person image is obtained, and the face mask image is used to indicate the shape and position of the face contour in the second real person image. The image size of the face mask image is the same as that of the second real person image. Figure 3 Schematic diagram of a second real person image and a corresponding face mask image provided in one embodiment of the present application. Figure 3As shown, it includes Figure (a) and Figure (b). Figure (a) is the second real person image, and Figure (b) is the face mask image corresponding to the second real person image. The white area in Figure (b) is the shape and position of the face contour area in the second real person image.
[0067] In another optional implementation manner, a possible implementation manner of step S30 “performing facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image” includes steps S301-S304:
[0068] S301, obtaining a blank mask image having the same size as the second real-person image.
[0069] S302: extract facial key points from the second real person image to obtain facial key point coordinates.
[0070] S303: construct a face contour according to the coordinates of the key points of the face.
[0071] S304: Draw a face outline on the blank mask image to obtain a face mask image corresponding to the second real person image.
[0072] In the embodiment of the present application, the open source Anime Face Detector model can be used to extract facial key points and facial key point coordinates for the second real person image, such as the key points of the eyes, nose, mouth, etc., which are only examples and are not limited in the embodiment of the present application.
[0073] In an optional implementation manner, after step 304, the second real person image may be subjected to the following step S305:
[0074] S305 , performing Gaussian blur smoothing processing on the face mask image corresponding to the second real person image to obtain the face mask image after Gaussian blur smoothing processing.
[0075] In the embodiment of the present application, the Gaussian smooth blur is used to smooth the edge of the mask, so as to improve the error tolerance of the mask coverage when generating subsequent images, and make the generated image effect more natural.
[0076] The above steps S301-S305 are described below in conjunction with a specific example. According to the following steps A1-A4, the face mask image corresponding to the second real person image can be obtained according to the coordinates of the face key points:
[0077] A1. First, create a blank image of the same size as the second real-life image.
[0078] A2. Then, create a face contour based on the coordinates of the face key points. You can use OpenCV's `convexHull` function to create a convex hull (convex hull) from the key point coordinates as the face contour.
[0079] A3. Draw the face contour on the mask image generated in step A1. Use the `fillConvexPoly` function of OpenCV to draw the face contour on the mask image.
[0080] A4. Perform Gaussian blur smoothing processing on the mask image, and output a face mask image corresponding to the second real person image.
[0081] An optional implementation manner is to scale the face mask image proportionally, the purpose of which is to adjust the image size of the face mask image to the resolution of the best output of the image generation model. For example, when the image generation model includes an SD1.5 model (i.e., a character lora model), the width of the face mask image is scaled (enlarged) to 512, and the height is scaled (enlarged) proportionally. For another example, when the image generation model includes a character lora model as SDXL (i.e., another character lora model), the width of the face mask image is scaled (enlarged) to 1024, and the height is scaled (enlarged) proportionally.
[0082] S40, inputting the second real person image, the character feature text information, and the face mask image into the target image generation model to obtain a first generated image output by the target image generation model. The first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real person image, the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is obtained by training based on multiple images of different characters, and the second image generation model is obtained by training based on multiple images of the target character.
[0083] As mentioned above, the target image generation model is obtained by integrating the first image generation model with the second image generation model. The first image generation model is trained based on multiple images of different characters, and can generate high-quality image content based on the prompts of this article. The second image generation model is trained based on multiple images of the target character, and can generate character images consistent with the image style of the target character. By integrating the second image generation model into the first image generation model, the first image generation model can be fine-tuned based on the second image generation model. In this way, a small number of additional low-rank parameters are introduced to adapt to the image generation task that conforms to a specific character style, thereby eliminating the need to fully fine-tune the first image generation model, which saves computing resources and speeds up training.
[0084] As mentioned above, the first image generation model can be Stable Diffusion. The second image generation model can be a character lora model (Low-Rank Adaptation of Large Language Models) trained based on multiple target character images. The character lora model is specially designed and trained to generate images with a specific character style. These models can be adjusted to capture specific game art styles, character features or cultural elements, such as two-dimensional, European and American realism, Chinese style and other different styles of game characters. Among them, the target character can be a character in the game, or a character in anime, etc., which is only an example, and the embodiments of the present application do not make any limitation to this.
[0085] Below, the training process of the character lora model is explained with a specific example.
[0086] Step 1: Set up the training environment: Install the Python environment, select an SD Checkpoint, and use the open source kohya-scripts training script to prepare for training, or you can choose a training script from other communities. kohya-scripts is a tool set for performing common tasks and scripts in a project.
[0087] In the embodiment of the present application, DreamMaker can be used as a training platform to train the first image generation model such as the Stable Diffusion model. Among them, DreamMaker is an AI drawing cloud platform based on the Stable Diffusion model, and its underlying layer is also the kohya-scripts script.
[0088] Step 2: Collect training materials: Collect a large number of images of the target character. It is best to collect background-free materials from multiple angles such as the front view, side view, and back view. This will greatly improve the generalization of the model. Figure 4 A schematic diagram of a training sample image provided in one embodiment of the present application. Figure 4 As shown, Figure 4 The image includes multiple images containing the same target character (ie, a target cartoon character).
[0089] Step 3: Image preprocessing: Crop the images collected in step 2 to a fixed resolution, usually a multiple of 64, preferably between 512 and 1024. Figure 5 A schematic diagram of multiple images with different resolutions provided in one embodiment of the present application. Figure 5 As shown, there are three image sizes with different resolutions, namely 512*1024, 1024*512, and 512*512.
[0090] Step 4: Labeling: Use a preset graph-to-text model to automatically label the training image. The preset graph-to-text model can be WDTagger1.4, DeepDanbooru, GPT4-Vison, etc., which are examples only and are not limited in this embodiment of the present application. For example, after labeling the training image, it can be saved as a txt document with the same name as the training image. Figure 6 A schematic diagram of a training image and its corresponding training label provided in one embodiment of the present application. Figure 6 As shown, for each training image, a txt document with the same name as the training image is generated.
[0091] Step 5: Use the above training images to train the basic model to be trained. The basic model after training is the lora model of the target character. If the target character is an anime character, the basic model can be the Counterfei V2.5 model, which is an AI model for generating high-quality anime-style images.
[0092] In an embodiment of the present application, a second real person image, character feature text information, and a face mask image are input into a target image generation model to obtain a first generated image output by the target image generation model. The first generated image is an image obtained by drawing the image area other than the facial contour area in the second real person image by the target image generation model, so that the image content of the facial contour area of the character in the second real person image is retained in the first generated image that is finally output, and the image area other than the facial contour area in the second real person image is drawn using the target image generation model based on the character feature text information. The image style of the character in the first generated image is consistent with the image style of the target character.
[0093] In the embodiment of the present application, the first image generation model is Stable Diffusion, and the second image generation model is the character lora model of the target character. First, a stable Stable Diffusion model operating environment is obtained, which usually involves installing the necessary software libraries and model weights. Secondly, the character lora model is obtained. Next, within the framework of Stable Diffusion, the character lora model is integrated, so that the subsequent Stable Diffusion model combines the model weights of the character lora model in the image generation process to generate an image that conforms to the style of the target character. For example, the character lora model is trained based on multiple images of anime character 1. Next, the second real person image (for example, the real person in the second real person image is Xiao Ming), the character feature text information, and the face mask image are used as input data, and are input into the Stable Diffusion model of the integrated character lora model to output the first generated image. Then, the first generated image output by the Stable Diffusion model of the integrated character lora model includes the character image of Xiao Ming dressed as anime character 1, and the facial features and contours of the character are consistent with the facial features and contours of the character in the second real person image. In this way, the Stable Diffusion model of the integrated character lora model is guided based on the character feature text information describing the character features in the second real-person image. The character image content except the character facial contour area in the first generated image output by the Stable Diffusion model of the integrated character lora model meets the character feature requirements guided by the character feature text information.
[0094] In the image generation method provided in the embodiment of the present application, a first real person image is obtained and the background of the first real person image is removed to obtain a second real person image. Character feature text information for the image to be generated is obtained. Face recognition is performed on the second real person image to obtain a face mask image corresponding to the second real person image, and the face mask image is used to indicate the shape and position of the face contour area in the second real person image. The second real person image, the character feature text information, and the face mask image are input into the target image generation model to obtain the first generated image output by the target image generation model. Among them, the first generated image is an image obtained by drawing the image area other than the face contour area in the second real person image by the target image generation model, and the target image generation model is obtained by integrating the first image generation model with the second image generation model. The first image generation model is obtained by training based on multiple images of different roles, and the second image generation model is obtained by training based on multiple images of the target role. The present application can batch generate images of the specified real person playing the target role by specifying the real person image (i.e., the first real person image), with extremely high image generation efficiency. The present application completely eliminates the need for the labor, time, and economic costs required to produce a set of real-person Cosplay images in a specific style, thereby greatly reducing the labor, time, and economic costs required to obtain real-person images in a specific style.
[0095] Based on the above embodiments, the image generation method provided in the embodiments of the present application is further described.
[0096] In an optional implementation manner, the image generation method provided in the embodiment of the present application further includes steps S501-S502:
[0097] S501: extract facial features from a second real person image to obtain facial features of the person.
[0098] In the above-mentioned process of performing facial recognition processing on the second real-person image, the key facial points such as eyes, nose, and mouth are identified, and the position coordinates of each key facial point in the second real-person image are obtained. According to the position coordinates of each key facial point, on a blank image of the same image size as the second real-person image, according to the position coordinates of each key facial point obtained above, the shape of the face contour in the second real-person image is drawn at the corresponding position on the blank image, that is, the face mask image corresponding to the second real-person image is obtained, and the face mask image is used to indicate the shape and position of the face contour area in the second real-person image. The image size of the face mask image is the same as that of the second real-person image.
[0099] In an optional implementation, a preset facial feature extraction model such as InstantID is used to extract facial features from the second real person image to obtain facial features of the person.
[0100] S502: Input the facial features of the person and the first generated image into a target image generation model to obtain a second generated image output by the target image generation model.
[0101] Considering that the first generated image is an image obtained by drawing the image area other than the facial contour area in the second real person image by the target image generation model, this results in an unnatural transition between the edge of the facial contour area in the first generated image and the rest of the drawn image, with obvious edge traces. In an embodiment of the present application, after extracting facial features from the second real person image, the facial features of the person and the first generated image are input into the target image generation model, and the target image generation model outputs the second generated image. By using the facial feature extraction corresponding to the second real person image to perform image content enhancement drawing on the entire facial contour area of the first generated image, this helps to eliminate the edge traces between the edge of the facial contour area and the rest of the drawn image (i.e., the image of the image area other than the facial contour area), so that the transition between the edge of the facial contour area in the second generated image and the rest of the drawn image is more natural.
[0102] In an optional implementation manner, a possible implementation manner of step S40 "inputting the second real person image, the character feature text information, and the face mask image into the target image generation model to obtain the first generated image output by the target image generation model" includes S4011-S4012:
[0103] S4011. Perform character posture extraction on the second real person image to obtain target posture information.
[0104] In the embodiment of the present application, compared with extracting the human pose from the first real person image, extracting the human pose from the second real person image can obtain more accurate target pose information because the background information originally present in the first real person image has been removed from the second real person image.
[0105] As mentioned above, the character posture information includes but is not limited to: depth information, skeletal posture information, lines, key point coordinates, joint angles, body direction, action recognition, posture scoring, and posture description. Among them, key point coordinates refer to the detected key point coordinates of the human body, such as the position coordinates of the head, shoulders, elbows, knees, etc. in the real person image. Joint angles refer to the joint angles of the human body calculated by key point coordinates, such as elbow bending angle, knee bending angle, etc. Body direction: Determine the overall direction of the human body, including orientation and turning. Action recognition refers to determining the ongoing actions of the human body based on posture information, such as walking, running, raising hands, etc. Posture scoring refers to scoring the posture based on the accuracy and standardization of the posture, which is used to evaluate the standardization and correctness of the action. Posture description refers to describing the body posture of the character, such as "standing, hands hanging down, head slightly raised", etc.
[0106] In an optional implementation, the second real person image is input into a preset posture extraction model to obtain target posture information output by the preset posture extraction model, and the preset posture extraction model is used to extract the posture of the person in the image.
[0107] As mentioned above, the preset posture extraction model is used to extract the posture of the person in the image. The preset posture extraction model can be the OpenPose model in ControlNet, just as an example. Among them, ControlNet is an "auxiliary" neural network model structure, which introduces "extra conditions" to control the generation process of AI painting by adding auxiliary modules to the Stable Diffusion model. The OpenPose model in ControlNet can be used to detect the key points of people in images or videos, such as head, shoulders, elbows, wrists, hips, knees and ankles. Connecting these key points can form a skeleton structure that reflects the posture of the human body.
[0108] Exemplarily, the OpenPose model in ControlNet is used to detect the human posture in the second real-life image. Suppose there is a dance photo, which is a snapshot of a dancer's dance performance. First, import the above dance photo into an image processing software or AI painting tool that supports the ControlNet plug-in, such as the WebUI version of Stable Diffusion. Secondly, in the settings of the software or tool, select the ControlNet plug-in and select the OpenPose model from the list of models provided. Next, after starting the detection process, the OpenPose model will analyze the image and identify the key points of the character through a deep learning algorithm. Finally, you can see that a layer of skeleton structure diagram composed of connecting lines and dots is covered on the original image. Each line segment connects two key points, representing the connection of the limbs, and the dots mark the position of each key point. In this way, even in the most complex and changeable dance movements, the posture of the character can be clearly identified.
[0109] S4012: Input the second real person image, character feature text information, face mask image and target posture information into a target image generation model to obtain a first generated image output by the target image generation model.
[0110] In an embodiment of the present application, the second real person image, the character feature text information, the face mask image and the target posture information are input into the target image generation model to obtain the first generated image output by the target image generation model. The first generated image is an image obtained by drawing the image area other than the facial contour area in the second real person image by the target image generation model, so that the image content of the facial contour area of the character in the second real person image is retained in the first generated image that is finally output, and the image area other than the facial contour area in the second real person image is drawn using the target image generation model based on the character feature text information and the target posture information, and the character image content other than the facial contour area in the generated first generated image meets the character feature requirements guided by the character feature text information, and the character posture of the character in the first generated image output by the target image generation model is consistent with the character posture in the second real person image.
[0111] In an optional implementation manner, a possible implementation manner of step S40 "inputting the second real person image, the character feature text information, and the face mask image into the target image generation model to obtain the first generated image output by the target image generation model" further includes steps S4021-S4023:
[0112] S4021. Obtain background text information for the image to be generated.
[0113] As mentioned above, the background text information of the image to be generated is used to describe the background information such as the theme, scene, element, color, and lighting of the background of the image to be generated. For example, the background picture of the image to be generated is an endless sand dune in the desert at sunset, and there is an ancient city ruins in the distance. Then, the background text information of the image to be generated may include background elements such as desert, sunset, sand dune, and ancient city ruins, which are just examples.
[0114] S4022: Merge the background text information and the character feature text information to obtain target text information.
[0115] In the embodiment of the present application, the background guidance information of the image to be generated and the character feature text information of the first real person image are merged to obtain the target guidance information. The merging method may include at least one of the following: series connection, interlaced connection, parallel connection, etc., which are only examples and are not limited in any way in the embodiment of the present application.
[0116] S4023. Input the second real person image, the face mask image and the target text information into the target image generation model to obtain a first generated image output by the target image generation model.
[0117] In an embodiment of the present application, background content that meets the user's needs can be added to the image generated by the image generation method in the present application according to the user's needs.
[0118] In an embodiment of the present application, the second real person image, the face mask image and the target text information are input into the target image generation model to obtain a first generated image output by the target image generation model. The first generated image is an image obtained by drawing the image area other than the facial contour area in the second real person image by the target image generation model, so that the image content of the facial contour area of the person in the second real person image is retained in the first generated image that is finally output, and the image area other than the facial contour area in the second real person image is drawn using the target image generation model based on the character feature text information, and the character image content other than the facial contour area in the generated first generated image meets the character feature requirements guided by the character feature text information, and the background content in the first generated image meets the background content requirements corresponding to the background text information.
[0119] In an optional implementation manner, a possible implementation manner of step S40 "inputting the second real person image, the character feature text information, and the face mask image into the target image generation model to obtain the first generated image output by the target image generation model" further includes step S4031:
[0120] S4031. Input the second real person image, target text information, target posture information, and face mask image into a target image generation model, and output a first generated image.
[0121] In an embodiment of the present application, the second real person image, target text information, target posture information, and face mask image are input into the target image generation model to obtain a first generated image output by the target image generation model. The first generated image is an image obtained by drawing the image area other than the facial contour area in the second real person image by the target image generation model, so that the image content of the facial contour area of the person in the second real person image is retained in the first generated image that is finally output, and the image area other than the facial contour area in the second real person image is drawn using the target image generation model based on the character feature text information and the target posture information, and the character image content other than the facial contour area in the generated first generated image meets the character feature requirements guided by the character feature text information, while the character posture of the person in the first generated image output by the target image generation model is consistent with the character posture in the second real person image, and the background content in the first generated image meets the background content requirements corresponding to the background text information.
[0122] Next, combine Figure 7 , Figure 8 , Fig. 9, taking the first image generation model being Stable Diffusion and the second image generation model being the character lora model of the target character as an example (i.e., the target image generation model is a Stable Diffusion model integrated with the character lora model), an image generation method provided in one embodiment of the present application is exemplarily described, Figure 7 This is a flow chart of an image generation method provided by another embodiment of the present application. Figure 8 A schematic diagram of the effect of generating a second real-person image from a first real-person image according to one embodiment of the present application is provided. Fig. 9 A schematic diagram of the effect of generating a second generated image from a first generated image provided in one embodiment of the present application.
[0123] like Figure 7 As shown, a first real-person image is obtained; the background of the first real-person image is removed and the size is adjusted to obtain a second real-person image. The character posture is extracted from the second real-person image to obtain target posture information. Character feature text information for the image to be generated is obtained. Face recognition is performed on the second real-person image to obtain a face mask image corresponding to the second real-person image. Background text information for the image to be generated is obtained. The background text information and the character feature text information are merged to obtain target text information. The second real-person image, the face mask image target text information, and the target posture information are input into the target image generation model to obtain the first generated image output by the target image generation model. As shown Figure 8 As shown, the first real person image is the left image, and the first generated image is the right image. The second real person image (for example, the real person in the second real person image is Xiao Ming), the target posture information, the target text information, and the face mask image are used as input data, and are input into the target image generation model (for example, the second image generation model is obtained by training based on the game character 1), and the first generated image is output. Then, if the first generated image includes the character image of Xiao Ming dressed as the game character 1, and the character posture of the character image is consistent with the character posture in the second real person image, and the facial features and contours of the character are consistent with the facial features and contours of the character in the second real person image. The background content in the first generated image other than the character image meets the background requirements guided by the background text information in the target text information. Among them, since the target text information includes two parts, one part is the background text information describing the background that the user expects the image to be generated to have, and the other part is the character feature text information used to describe the character features in the second real person image. In this way, the background content in the first generated image meets the background content requirements corresponding to the background text information, and the character image in the first generated image can also contain more character features of the character in the second real person image.
[0124] Next, facial features are extracted from the second real person image to obtain facial features of the person. The facial features of the person and the first generated image are input into the target image generation model to obtain a second generated image output by the target image generation model. Fig. 9 As shown, the first generated image is the left image and the second generated image is the right image. After extracting facial features from the second real person image, the facial features of the person and the first generated image are input into the target image generation model, and the target image generation model outputs the second generated image. By using the facial feature extraction corresponding to the second real person image, the entire facial contour area of the first generated image is subjected to image content enhancement drawing, which helps to eliminate the edge traces between the edge of the facial contour area and the rest of the drawn image (i.e., the image of the image area outside the facial contour area), so that the transition between the edge of the facial contour area in the second generated image and the rest of the drawn image is more natural.
[0125] In an optional implementation manner, before step 201 of “inputting the second real person image into the preset image-to-text model”, the image generation method provided in the embodiment of the present application further includes step S2011:
[0126] S2011: inputting character feature guide words into the preset image-to-text model, wherein the character feature guide words are used to guide the preset image-to-text model to output character feature text information for describing the character features in the input image according to the input image.
[0127] As mentioned above, the preset graph-to-text model may be GPT4-Vison, which is only an example and the embodiments of the present application do not impose any limitation on this.
[0128] For example, taking the preset graph-to-text model as GPT4-Vison as an example, input the training prompt word (i.e., the character feature guide word) into GPT4-Vison:
[0129] "Stable Diffusion is a deep learning, text-to-image model released in 2022. It is primarily designed to generate detailed images conditioned on text descriptions, although it can also be applied to other tasks such as drawing, painting, and generating image-to-image translations guided by text prompts. I would like you to serve as a prompt generator for the AI program "Stable Diffusion". Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI. Remember that the AI understands a variety of languages and can interpret abstract concepts, so you are free to be imaginative and descriptive. For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures. The more detailed and imaginative your description, the more interesting the final image will be. You will describe the content of the picture based on the picture I input, and give a complete prompt that conforms to the above prompt format. They include various details such as the appearance of the characters, the background, the colors and lighting effects, and the theme and style of the image. These prompt formats often include numeric brackets with weights to specify the importance or emphasis of certain details. For example, "(Masterpiece: 1.4)" means that the quality of the work is very important.Here are some examples: (8k, RAW photo, best quality, masterpiece: 1.2), (realistic, photo-realism: 1.37), ultra-detailed, 1 girl, cute, solo, beautiful detail sky, detail cafe, night, sitting, date, (nose blush), (smile: 1.1), (closed mouth), beautiful detail eyes, (collared shirt: 1.1), bow tie, pleated skirt, (short hair: 1.2), flowing hair, ((masterpiece)), ((best quality)), (masterpiece, detailed beautiful eyes): 1.2), Ultra Detail, Illustration, 1 Girl, Blue Hair Black Hair, Japanese Clothes, Sakura, Street Full of Sakura, Detailed Background, Realistic, Volumetric Light, Sunlight, Rays, Sky, Clouds, High Magnification, Highest Quality, Illustration, Film Light, Ultra Detail, Detailed Face, (Detailed Eyes, Best Quality, Ultra Detail, Masterpiece, (Detailed Face), Blue Hair, White Hair, Purple Eyes, Highest Detail, Glowing Eyes, Black Aura, White Clothes, Backlight, (Belly: 1.4), Rays, (High Contrast), (Color) 1 Girl, Separate Sleeves, shoulders, pink hair, long hair, best quality, (painting: 1.5), (hair decoration: 1.35), jewelry, purple eyes, earrings, cherry blossoms, lantern light, depth of field, detail face, face focus, ribbon decoration, (looking at viewer: 1.25), shiny skin, long sleeves, smiling, thick lips, hand on lips, architectural style, (blurred background: 1.2), sitting, upper body ultra-realistic textures, dramatic lighting, Unreal Engine, award-winning photo, XXRAW photo, 8k, XX Film XT3, masterpiece, the best Quality, Realistic, Ultra Detail, Extremely Detailed Face, Solo Dance, Girl, Standing, Fashion and Trendy Vibe, Walk-in Wardrobe, Designer Clothing and Accessories, High-end Makeup Products, Fashionable Expression on Her Face, Smooth, Soft, Masterpiece, Best Quality, (Aerial View: 1.2), (Massive: 1.2) Environment, Vast Landscape, Gorgeous Castle, (Flags: 1.2), Tiny Houses, Leaves, Detailed Concept Art, Digital Painting, Gorgeous Night Sky, Unreal Engine 5, Maximum Detail, Intricacy. Answer Yes if you understand the above rules! ".
[0130] If GPT4-Vison outputs "OK", it means that GPT4-Vison has understood the above instructions, which means that GPT4-Vison has been trained. Then, a second real person image is input to GPT4-Vison, and the image content description text for the second real person image output by GPT4-Vison, that is, the character feature text information, can be obtained.
[0131] In an optional implementation manner, in step 4021, an implementation manner of "obtaining background text information for the image to be generated" includes step S40211:
[0132] S40211. Obtain background guide words, and input the background guide words into a preset language model to obtain background text information output by the preset language model.
[0133] Among them, the background guide words describe the background style of the image to be generated and / or the background elements contained in the background. The background guide words are used to guide the preset language model to output background text information that meets the background style requirements of the background guide words and / or includes the background elements in the background guide words based on the input background guide words.
[0134] As mentioned above, the preset language model may be GPT4-Vison, which is only an example and the embodiments of the present application do not impose any limitation on this.
[0135] For example, taking the preset language model as GPT4-Vison as an example, input the training prompt word to GPT4-Vison:
[0136] "Stable Diffusion is a deep learning, text-to-image model released in 2022. It is primarily designed to generate detailed images conditioned on text descriptions, although it can also be applied to other tasks such as drawing, painting, and generating image-to-image translations guided by a text prompt. I would like you to serve as a prompt generator for the AI program "Stable Diffusion". Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI. Remember that the AI understands a variety of languages and can interpret abstract concepts, so you are free to be imaginative and descriptive. For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures. The more detailed and imaginative your description, the more interesting the final image will be. You generate complete prompts that conform to the prompt format based on the keywords I enter. They include various details such as the appearance of the characters, the background, the colors and lighting effects, and the theme and style of the image. These prompt formats often include weighted numeric brackets to specify the importance or emphasis of certain details. For example, "(Masterpiece: 1.4)" means that the quality of the work is very important.Here are some examples: (8k, RAW photo, best quality, masterpiece: 1.2), (realistic, photo-realism: 1.37), ultra-detailed, 1 girl, cute, solo, beautiful detail sky, detail cafe, night, sitting, date, (nose blush), (smile: 1.1), (closed mouth), beautiful detail eyes, (collared shirt: 1.1), bow tie, pleated skirt, (short hair: 1.2), flowing hair, ((masterpiece)), ((best quality)), (masterpiece, detailed beautiful eyes): 1.2), Ultra Detail, Illustration, 1 Girl, Blue Hair Black Hair, Japanese Clothes, Sakura, Street Full of Sakura, Detailed Background, Realistic, Volumetric Light, Sunlight, Rays, Sky, Clouds, High Magnification, Highest Quality, Illustration, Film Light, Ultra Detail, Detailed Face, (Detailed Eyes, Best Quality, Ultra Detail, Masterpiece, (Detailed Face), Blue Hair, White Hair, Purple Eyes, Highest Detail, Glowing Eyes, Black Aura, White Clothes, Backlight, (Belly: 1.4), Rays, (High Contrast), (Color) 1 Girl, Separate Sleeves, shoulders, pink hair, long hair, best quality, (painting: 1.5), (hair decoration: 1.35), jewelry, purple eyes, earrings, cherry blossoms, lantern light, depth of field, detail face, face focus, ribbon decoration, (looking at viewer: 1.25), shiny skin, long sleeves, smiling, thick lips, hand on lips, architectural style, (blurred background: 1.2), sitting, upper body ultra-realistic textures, dramatic lighting, Unreal Engine, award-winning photo, XXRAW photo, 8k, XX Film XT3, masterpiece, the best Quality, Realistic, Ultra Detail, Extremely Detailed Face, Solo Dance, Girl, Standing, Fashion and Trendy Vibe, Walk-in Wardrobe, Designer Clothing and Accessories, High-end Makeup Products, Fashionable Expression on Her Face, Smooth, Soft, Masterpiece, Best Quality, (Aerial View: 1.2), (Massive: 1.2) Environment, Vast Landscape, Gorgeous Castle, (Flags: 1.2), Tiny Houses, Leaves, Detailed Concept Art, Digital Painting, Gorgeous Night Sky, Unreal Engine 5, Maximum Detail, Intricacy. Answer Yes if you understand the above rules! ".
[0137] If GPT4-Vison outputs "OK" or the like, it means that GPT4-Vison has understood the above instructions. Then, by inputting background guide words such as "forest" into GPT4-Vison, you can get the background text information output by GPT4-Vison.
[0138] The image generating device provided by the present application is described below. The image generating device described below and the image generating method described above can be referenced to each other.
[0139] Fig.10 This is a schematic diagram of the structure of an image generating device provided in one embodiment of the present application. Fig.10As shown, the image generating device 1000 includes: a first acquiring module 1001 , a second acquiring module 1002 , a processing module 1003 , and a control processing module 1004 .
[0140] A first acquisition module, used for acquiring a first real-person image and performing background subtraction processing on the first real-person image to obtain a second real-person image;
[0141] A second acquisition module is used to acquire character feature text information for the image to be generated;
[0142] a processing module, configured to perform facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, wherein the facial mask image is used to indicate the shape and position of a facial contour area in the second real person image;
[0143] A control module is used to input the second real-person image, the character feature text information, and the face mask image into a target image generation model to obtain a first generated image output by the target image generation model; wherein the first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real-person image, the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is trained based on multiple images of different characters, and the second image generation model is trained based on multiple images of the target character.
[0144] Optionally, the control module is further used for:
[0145] Extracting facial features from the second real person image to obtain facial features of the person;
[0146] The facial features of the person and the first generated image are input into the target image generation model to obtain a second generated image output by the target image generation model.
[0147] Optionally, the control module is specifically used for:
[0148] Performing character posture extraction on the second real person image to obtain target posture information;
[0149] The second real person image, the character feature text information, the face mask image and the target posture information are input into a target image generation model to obtain a first generated image output by the target image generation model.
[0150] Optionally, the second acquisition module is further used for:
[0151] The second real-person image is input into a preset image-to-text model to obtain character feature text information output by the preset image-to-text model, where the character feature text information is used to describe the character features in the second real-person image.
[0152] Optionally, the control module is further used for:
[0153] Acquire background text information for the image to be generated;
[0154] Merging the background text information and the character feature text information to obtain target text information;
[0155] The second real person image, the face mask image and the target text information are input into a target image generation model to obtain a first generated image output by the target image generation model.
[0156] Optionally, the first acquisition module is further used for:
[0157] The first real-person image is input into a preset background removal model to obtain a second real-person image output by the preset background removal model, where the preset background removal model is used to remove the background in the image.
[0158] Optionally, the control module is specifically used for:
[0159] The second real person image is input into a preset posture extraction model to obtain target posture information output by the preset posture extraction model, where the preset posture extraction model is used to extract the posture of the person in the image.
[0160] Optionally, the second acquisition module is further used for:
[0161] Input character feature guide words into the preset image-generated text model; wherein the character feature guide words are used to guide the preset image-generated text model to output character feature text information for describing the character features in the input image according to the input image.
[0162] Optionally, the control module is further used for:
[0163] Obtaining background guide words, and inputting the background guide words into a preset language model to obtain background text information output by the preset language model;
[0164] Among them, the background guide words describe the background style of the image to be generated and / or the background elements contained in the background, and the background guide words are used to guide the preset language model to output background text information that meets the background style requirements of the background guide words and / or includes the background elements in the background guide words based on the input background guide words.
[0165] Optionally, the processing module is specifically used for:
[0166] Acquire a blank mask image having the same size as the second real person image;
[0167] Extracting facial key points from the second real person image to obtain facial key point coordinates;
[0168] Constructing a facial contour according to the coordinates of the facial key points;
[0169] The face contour is drawn on the blank mask image to obtain a face mask image corresponding to the second real person image.
[0170] Optionally, the processing module is further used for:
[0171] Perform Gaussian blur smoothing processing on the face mask image corresponding to the second real person image to obtain the face mask image after Gaussian blur smoothing processing.
[0172] The image generating device provided in this embodiment can be used to execute the technical solution of the above-mentioned image generating method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0173] Fig.11 A schematic diagram of the hardware structure of an electronic device provided in one embodiment of the present application is shown in FIG. Fig.11 As shown, the electronic device 1100 of this embodiment includes: a processor 1101 and a memory 1102;
[0174] Memory 1102, used to store computer-executable instructions;
[0175] The processor 1101 is used to execute the computer-executable instructions stored in the memory to implement the various steps performed by the image generation method in the above embodiment. For details, please refer to the relevant description in the above method embodiment.
[0176] Optionally, the memory 1102 may be independent or integrated with the processor 1101 .
[0177] When the memory 1102 is independently provided, the electronic device further includes a bus 1103 for connecting the memory 1102 and the processor 1101 .
[0178] One embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, a technical solution corresponding to the image generation method in any of the above embodiments executed by the electronic device is implemented.
[0179] One embodiment of the present application also provides a computer program product, which includes: a computer program, which is stored in a readable storage medium. At least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program so that the electronic device executes the technical solution corresponding to the image generation method in any of the above embodiments.
[0180] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
[0181] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0182] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application.
[0183] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0184] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0185] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0186] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0187] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0188] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. An image generation method, characterized in that: The method comprises: Acquire a first real-person image and perform background subtraction processing on the first real-person image to obtain a second real-person image; Obtaining character feature text information for the image to be generated; Performing facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, wherein the facial mask image is used to indicate the shape and position of a facial contour area in the second real person image; The second real-person image, the character feature text information, and the face mask image are input into a target image generation model to obtain a first generated image output by the target image generation model; wherein the first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real-person image, and the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is trained based on multiple images of different characters, and the second image generation model is trained based on multiple images of the target character.
2. The method according to claim 1, characterized in that The method further comprises: Extracting facial features from the second real person image to obtain facial features of the person; The facial features of the person and the first generated image are input into the target image generation model to obtain a second generated image output by the target image generation model.
3. The method according to claim 1, characterized in that The step of inputting the second real person image, the character feature text information, and the face mask image into a target image generation model to obtain a first generated image output by the target image generation model includes: Performing character posture extraction on the second real person image to obtain target posture information; The second real person image, the character feature text information, the face mask image and the target posture information are input into a target image generation model to obtain a first generated image output by the target image generation model.
4. The method according to claim 1, characterized in that: The step of obtaining character feature text information for the image to be generated includes: The second real-person image is input into a preset image-to-text model to obtain character feature text information output by the preset image-to-text model, where the character feature text information is used to describe character features in the second real-person image.
5. The method according to claim 1, characterized in that The method of inputting the second real person image, the character feature text information, and the face mask image into a target image generation model to obtain a first generated image output by the target image generation model further includes: Acquire background text information for the image to be generated; Merging the background text information and the character feature text information to obtain target text information; The second real person image, the face mask image and the target text information are input into a target image generation model to obtain a first generated image output by the target image generation model.
6. The method according to claim 1, characterized in that The performing background subtraction processing on the first real person image to obtain a second real person image includes: The first real-person image is input into a preset background removal model to obtain a second real-person image output by the preset background removal model, where the preset background removal model is used to remove the background in the image.
7. The method according to claim 3, characterized in that The step of extracting the pose of a person from the second real person image to obtain target pose information includes: The second real person image is input into a preset posture extraction model to obtain target posture information output by the preset posture extraction model, where the preset posture extraction model is used to extract the posture of the person in the image.
8. The method according to claim 4, characterized in that Before inputting the second real person image into the preset image-to-text model, the method further includes: Input character feature guide words into the preset image-generated text model; wherein the character feature guide words are used to guide the preset image-generated text model to output character feature text information for describing the character features in the input image according to the input image.
9. The method according to claim 1, characterized in that: The obtaining of background text information for the image to be generated includes: Obtaining background guide words, and inputting the background guide words into a preset language model to obtain background text information output by the preset language model; Among them, the background guide words describe the background style of the image to be generated and / or the background elements contained in the background, and the background guide words are used to guide the preset language model to output background text information that meets the background style requirements of the background guide words and / or includes the background elements in the background guide words based on the input background guide words.
10. The method according to claim 1, characterized in that The performing facial recognition processing on the second real person image to obtain a face mask image corresponding to the second real person image includes: Acquire a blank mask image having the same size as the second real person image; Extracting facial key points from the second real person image to obtain facial key point coordinates; Constructing a facial contour according to the coordinates of the facial key points; The face contour is drawn on the blank mask image to obtain a face mask image corresponding to the second real person image.
11. The method according to claim 10, characterized in that The method further comprises: Perform Gaussian blur smoothing processing on the face mask image corresponding to the second real person image to obtain the face mask image after Gaussian blur smoothing processing.
12. An image generating device, characterized in that: The device comprises: A first acquisition module, used for acquiring a first real-person image and performing background subtraction processing on the first real-person image to obtain a second real-person image; A second acquisition module is used to acquire character feature text information for the image to be generated; a processing module, configured to perform facial recognition processing on the second real person image to obtain a facial mask image corresponding to the second real person image, wherein the facial mask image is used to indicate the shape and position of a facial contour area in the second real person image; A control module is used to input the second real-person image, the character feature text information, and the face mask image into a target image generation model to obtain a first generated image output by the target image generation model; wherein the first generated image is an image obtained by the target image generation model drawing the image area other than the facial contour area in the second real-person image, the target image generation model is obtained by integrating the first image generation model with the second image generation model, the first image generation model is trained based on multiple images of different characters, and the second image generation model is trained based on multiple images of the target character.
13. An electronic device, characterized in that: The electronic device comprises: Processor; and The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the image generation method according to any one of claims 1 to 11 is executed.
14. A computer-readable storage medium, characterized in that: A data processing program is stored, and the program is run by a processor to execute the image generation method according to any one of claims 1 to 11.
Citation Information
Cited By
Method, device, equipment and medium for performing commodity material fission on commodity image
CN120070662A
Image generation method and apparatus, and electronic device
WO2026144662A1
