Method and device for generating identification photo on resource-constrained equipment, equipment and storage medium
By employing a collaborative architecture of lightweight convolutional neural networks and image segmentation models, the efficiency and standardization issues of ID photo generation on resource-constrained devices are addressed, enabling efficient and automated ID photo generation on mobile devices and embedded terminals.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING THUNDERSTONE TECH CO LTD
- Filing Date
- 2025-12-12
- Publication Date
- 2026-04-17
AI Technical Summary
Existing ID photo generation systems suffer from problems such as resource consumption and device compatibility conflicts, low processing efficiency, and lack of standardization and automation on resource-constrained devices, making it difficult to achieve efficient and standardized ID photo generation on mobile devices or embedded terminals.
Employing a collaborative architecture of a lightweight convolutional neural network model and a lightweight image segmentation model, and through parallel processing, we achieve face detection, resizing, background segmentation, and image quality enhancement to generate images that meet ID photo standards.
It enables efficient, real-time generation of standardized ID photos on resource-constrained devices, meeting national/industry standards, avoiding efficiency bottlenecks caused by manual verification, and possessing automated compliance processing capabilities.
Smart Images

Figure CN121883643A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus, device and storage medium for generating ID photos on resource-constrained devices. Background Technology
[0002] With the popularization of digital identity authentication, ID photo generation technology is widely used in government affairs, finance, education and other fields. Traditional ID photos need to meet strict standardization requirements (such as face size ratio, background color and image clarity, etc.), and users often take photos on-site and generate ID photos instantly through mobile devices or embedded terminals. Such devices generally have limited computing resources, are power-sensitive, and have high real-time response requirements, so there is an urgent need for lightweight and efficient automatic processing solutions.
[0003] Current mainstream ID photo generation systems mainly rely on two types of existing technologies: large-scale deep learning model solutions and alternative solutions with some optimized models. However, these existing technologies suffer from major drawbacks, including conflicts between resource consumption and device compatibility, low processing efficiency, and a lack of standardization and automation. Summary of the Invention
[0004] This application provides a method, apparatus, device, and storage medium for generating ID photos on resource-constrained devices. Through lightweight model collaborative parallel processing, standardized ID photos can be generated efficiently on resource-constrained devices.
[0005] On the one hand, this application provides a method for generating ID photos on resource-constrained devices, the method comprising the following steps: S1: Obtain input image data; S2: Use a lightweight convolutional neural network model to detect the face region in the input image data to obtain the face location information; S3: Based on the preset ID photo standard specifications and the position information of the face, adjust the size and position of the face in the image to generate an image with standardized position and size; S4: Use a lightweight image segmentation model to perform background segmentation on the image after the location size is normalized, and generate a background mask image; S5: Based on the background mask image and the standard specifications for ID photos, replace the segmented background area with the specified background color or pattern to generate an image with the background replaced; S6: Perform image quality enhancement processing on the image after background replacement to generate an enhanced image; S7: The enhanced image is encoded and compressed in accordance with the ID photo output specifications to generate the final ID photo image.
[0006] On the other hand, this application provides a device for generating ID photos on a resource-constrained device, the device comprising: The acquisition module is used to acquire input image data; The detection module is used to detect the face region in the input image data using a lightweight convolutional neural network model in order to obtain the position information of the face; The first generation module is used to adjust the size and position of the face in the image based on the preset ID photo standard specifications and the position information of the face, and generate an image with standardized position and size; The segmentation module is used to perform background segmentation processing on the image after the location size is normalized using a lightweight image segmentation model, and generate a background mask image; The second generation module is used to replace the segmented background area with a specified background color or pattern based on the background mask image and the ID photo standard specifications, and generate an image with background replacement. The enhancement module is used to perform image quality enhancement processing on the image after background replacement to generate an enhanced image; The third generation module is used to encode and compress the enhanced image in accordance with the ID photo output specifications to generate the final ID photo image.
[0007] Thirdly, this application provides an electronic device, the device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the technical solution of the ID photo generation method on a resource-constrained device as described above.
[0008] Fourthly, this application provides a storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described method for generating ID photos on resource-constrained devices.
[0009] As can be seen from the technical solution provided in this application, on the one hand, the collaborative architecture based on a lightweight convolutional neural network model and a lightweight image segmentation model solves the problem that traditional large models cannot be deployed on low-configuration devices; on the other hand, the lightweight model, through structured and simplified design, maintains the accuracy of key tasks without relying on high-performance hardware, enabling resource-constrained devices such as embedded terminals and older mobile phones to have real-time generation capabilities; thirdly, the processing chain is dynamically driven by the standard specifications for ID photos, namely adjusting size and position, replacing background, and combining encoding and compression processing to meet output specifications, ensuring that the generated images strictly comply with national / industry standards, achieving automated compliance processing under unattended conditions, and avoiding efficiency bottlenecks caused by manual verification. In summary, the technical solution of this application, through the collaborative parallel processing of a lightweight model, can efficiently generate standardized ID photos on resource-constrained devices. Attached Figure Description
[0010] 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 these drawings without creative effort.
[0011] Figure 1 This is a flowchart of the method for generating virtual characters with multiple identities provided in the embodiments of this application; Figure 2 This is a schematic diagram of the structure of the virtual character generation device with multiple identities provided in the embodiments of this application; Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0012] 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 some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0013] In this specification, adjectives such as "first" and "second" are used only to distinguish one element or action from another, without necessarily requiring or implying any actual such relationship or order. Where circumstances permit, reference to an element or component or step (etc.) should not be construed as being limited to only one of the elements, components, or steps, but may be one or more of the elements, components, or steps, etc.
[0014] For ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn to actual scale.
[0015] Traditional ID photos must meet strict standardization requirements (e.g., face size ratio, background color, and image clarity, etc.), while users often take photos on-site via mobile devices or embedded terminals and generate ID photos instantly. These devices generally suffer from limited computing resources, power sensitivity, and high real-time response requirements, necessitating lightweight and efficient automated processing solutions. Current mainstream ID photo generation systems primarily rely on two types of technologies: 1) Large-scale deep learning model solutions, specifically using deep convolutional neural networks (CNNs) for face detection and segmentation, combined with complex post-processing algorithms to adjust size and background. While this approach offers high accuracy, the model has a large number of parameters, and the inference process consumes significant GPU / CPU resources, making it difficult to run in real-time on mobile devices; 2) Alternative solutions using partially optimized models, specifically reducing computational load by cropping model layers or quantizing and compressing, but sacrificing key performance aspects (e.g., low edge segmentation accuracy, large size adjustment deviations), resulting in generated ID photos that often do not comply with existing national standards (e.g., GB / T 22651-2008). However, the existing technologies mentioned above have the following limitations: 1) Conflict between resource consumption and device compatibility: Large models are difficult to deploy and run on devices with limited computing resources (such as smartphones and embedded terminals), while lightweight models cannot guarantee the compliance of ID photos due to performance degradation; 2) Inefficient processing flow: The hardware parallel capabilities are not effectively utilized when performing detection, adjustment, and segmentation steps in sequence, resulting in excessively long generation time per cycle, which cannot meet the real-time requirements of users; 3) Lack of standardization and automation: Existing solutions lack the ability to automatically adapt to ID photo specifications (such as dynamic scaling and seamless background replacement), requiring manual intervention for proofreading, which deviates from the core requirement of "end-to-end automation".
[0016] To address the aforementioned problems in the prior art, this application proposes a method for generating ID photos on resource-constrained devices, the flowchart of which is attached. Figure 1 As shown, the main steps include S101 to S107, which are detailed below: Step S101: Obtain input image data.
[0017] In this embodiment, the input image data can be raw image data containing a complete human face captured by a mobile device, embedded terminal camera, or any other imaging device, and the image contains a detectable human face. In principle, the resolution of the input image data should not be lower than the minimum standard for ID photos.
[0018] Step S102: Use a lightweight convolutional neural network model to detect the face region in the input image data to obtain the face location information.
[0019] Traditional cascaded classifiers like Haar have high recall rates in complex scenes but cannot meet the localization requirements of ID photos. Standard convolutional neural network models (such as YOLOv3) require significantly more memory per frame for inference than resource-constrained devices like embedded terminals. Therefore, after acquiring input image data, a lightweight convolutional neural network model can be used to detect face regions within the input image data to obtain face location information. The essence of a lightweight convolutional neural network model lies in its structured model pruning through depth compression and channel reduction, and the use of depthwise separable convolutions instead of standard convolutions to create a dedicated detector that can run in real-time on mobile devices. This reduces the model size to a very small amount (e.g., less than 5MB), allowing for storage on low-capacity embedded devices. Inference latency can be controlled within milliseconds, providing crucial time margins for subsequent steps. Furthermore, it can maintain a recall rate greater than 99% in critical scenarios, ensuring that face location coordinates can be obtained under any legal shooting conditions.
[0020] To maintain critical task accuracy under mobile resource constraints, avoid missed face detections or location drift caused by model simplification, and ensure model stability to prevent system crashes due to memory overflow, lightweight convolutional neural network (CNN) models can be optimized for high efficiency by reducing both the depth and number of trainable parameters of the original CNN model by a certain percentage, while utilizing knowledge transfer techniques to maintain the original CNN model's key feature extraction and segmentation capabilities. It's important to note that the reduction percentage for both the original CNN model's depth and the number of trainable parameters should be neither too large nor too small. For example, reducing the depth of the original CNN model to below 20% may fail to meet computational resource constraints, while reducing it to over 40% could lead to the loss of key layers and a collapse in accuracy. Therefore, reducing the depth of the original CNN model to 20%–40% and the number of trainable parameters to 30%–70% can result in a lightweight CNN model.
[0021] The location information of the face detected by the lightweight convolutional neural network model mainly includes the coordinates of the center point of the face bounding box, as well as the width and height information of the face bounding box. The process of detecting face location information by the lightweight convolutional neural network model includes: the input is input image data, the model extracts feature maps through convolutional layers, and then outputs the center point coordinates, width and height information of the face bounding box through regression layers. Specifically, the model uses an anchor point mechanism to predefine multiple bounding box sizes, filters the most likely face region through non-maximum suppression, and finally outputs the face location information.
[0022] Step S103: Adjust the size and position of the face in the image based on the preset ID photo standard specifications and the position information of the face, and generate an image with standardized position and size.
[0023] Because ID photo standards (e.g., GA / T146-2019) mandate a certain proportion and centered position of the face. Without this step, directly segmenting the background would lead to an imbalance in the face's proportions; for example, in passport photos, the face must occupy 70% of the image, and positional misalignment would result in an unacceptable photo. After obtaining the face's position information, the size and position of the face in the image can be adjusted based on preset ID photo standards and the face's position information to generate an image with standardized position and size. Specifically, as an embodiment of this application, adjusting the size and position of the face in the image based on preset ID photo standards and the face's position information to generate an image with standardized position and size can be achieved through steps S1031 to S1033, as detailed below: Step S1031: Calculate the offset between the center point coordinates of the face bounding box and the center coordinates of the standard ID photo frame based on the face's location information.
[0024] Specifically, the above calculation of the offset between the center point coordinates of the face bounding box and the center coordinates of the standard ID photo frame based on the face's location information can be achieved by: obtaining the center point coordinates of the face bounding box. Coordinates of the center point of the standard ID photo frame Calculate the offset and .
[0025] Step S1032: Based on the proportion requirements of the face in the image after the position and size are standardized as specified in the ID photo standard, calculate the scaling factor of the width or height of the face bounding box relative to the standard size.
[0026] Specifically, the width of the face bounding box is denoted as... The height of the face bounding box is The standard specifications for ID photos require that the proportion of the face in the image be [percentage missing]. R If the standard for ID photos requires that the reference edge be determined based on the height ratio, then the standard face height... If the standard for ID photos requires that the reference edge be determined according to the width ratio, then the standard face width is... ;in, H The height of a standard ID photo. W This refers to the width of a standard ID photo. After obtaining the standard face height and width, if height is the primary factor, then the scaling factor is... If width is the primary factor, then the scaling factor... It should be noted that if the scaling factor... If the value is greater than the preset value, for example, a scaling factor greater than 1.2, it means that subsequent scaling will be based on this scaling factor. Adjusting the zoom level may cause excessive magnification, resulting in blurriness; conversely, adjusting the zoom level may reduce blurriness. Less than a preset value, such as the scaling factor A value less than 0.8 indicates that subsequent calculations will be based on this scaling factor. Adjusting the settings may result in excessive scaling and loss of detail.
[0027] Step S1033: Perform image geometric transformation operation, using offset and scaling factor to translate and scale the image region containing the face to obtain an image with normalized position and size.
[0028] If we denote the offset of the center point coordinates of the face bounding box from the center coordinates of the standard ID photo frame as... Images containing human faces are Then, using an offset to translate the image region containing the face can be... The image after translation In practice, the center point of the face is moved to the center of the standard ID photo frame. The direction of translation is automatically adjusted according to the sign of the offset to ensure that the center of the face moves towards the center of the frame. Scaling the translated image using a scaling factor can be done as follows: After scaling, the face size can be adjusted to a standard ratio. Alternatively, translation and scaling can be achieved in one step using an affine transformation, i.e.:
[0029] It should be noted that relying solely on facial bounding boxes to calculate the scaling factor can lead to the compression or stretching of key biometric features such as the eyes and mouth. Furthermore, conventional bilinear interpolation can blur high-frequency features in ID photos, such as pupil texture and hair edges. Therefore, to achieve zero loss of biometric features in ID photos while reducing computational load, the scaling factor calculation in the above embodiments can also be evaluated in conjunction with the distribution characteristics of facial keypoint detection results. Additionally, the geometric transformation operation is performed using an interpolation algorithm that preserves high-frequency image details. Specifically, this can involve detecting facial keypoints (e.g., eye and nose positions), adjusting the scaling factor based on the keypoint spacing to avoid feature distortion, and performing the geometric transformation operation using an interpolation algorithm that preserves high-frequency image details, such as using Lanczos interpolation instead of bilinear interpolation to maintain pupil texture clarity.
[0030] As can be seen from the above embodiments, by using offset and scaling factors to translate and scale the image area containing the face, the non-linear error between the face center and the frame center (such as head tilt) is eliminated, while avoiding ear cropping or excessive white space caused by preset ratio, thereby ensuring the biometric integrity of the output image (e.g., both ears are visible) and meeting the stringent standards of ID photos.
[0031] Step S104: Use a lightweight image segmentation model to perform background segmentation on the image after position and size normalization to generate a background mask image.
[0032] On the one hand, resource-constrained equipment cannot handle the computational load of conventional segmentation models; in other words, using conventional segmentation models may result in significant computational overhead and latency. On the other hand, hair-level edge segmentation is a basic requirement for ID photos in various countries (especially civil aviation, customs, and other departments), otherwise obvious white edges or residues will appear. Therefore, after generating a positionally and size-normalized image, a lightweight image segmentation model can be used to perform background segmentation on the positionally and size-normalized image to generate a background mask. By sacrificing the segmentation capabilities of irrelevant scenes (such as complex landscapes) and focusing on optimizing the preservation of details at the portrait boundaries, the contradiction between semantic segmentation accuracy and efficiency in dynamic scenes can be effectively resolved.
[0033] Specifically, a lightweight image segmentation model is used to perform background segmentation on the image after its position and size are normalized. The background mask image can be generated by: using a U-Net structure based on a lightweight image segmentation model, the probability value of each pixel in the image after its position and size are normalized is output through encoding and decoding; the probability value of each pixel belonging to the background is binarized using a set probability threshold to generate a background mask image. Here, the probability value of each pixel belonging to the background is binarized using a set probability threshold to generate a background mask image by: setting a probability threshold T (e.g., T=0.5), if the pixel probability value is greater than T, it is marked as background (value 1), otherwise it is marked as foreground (value 0), thus generating a binary mask image.
[0034] S105: Based on the background mask image and ID photo standard specifications, the segmented background area is replaced with the specified background color or pattern to generate an image with background replacement.
[0035] Since various countries have specific requirements for background colors in ID photos, the process of performing background segmentation on the image after it has been standardized using a lightweight image segmentation model also includes replacing the segmented background area with a specified background color or pattern based on the background mask and ID photo standards, generating a background-replaced image. As mentioned earlier, although hair-level edge segmentation is a basic requirement for ID photos in various countries, lightweight segmentation models are prone to producing jagged edges at hair edges (the essence of jagged edges is the loss of high-frequency information). However, by filling the gaps and breaks in the hair, i.e., repairing holes using morphological closing operations, and by mixing the foreground edge and background color at the pixel level, the problem of white or black borders in ID photos can be effectively solved. Therefore, as an embodiment of this application, replacing the segmented background area with a specified background color or pattern based on the background mask and ID photo standards, generating a background-replaced image, can be achieved through steps S1051 to S1054, detailed below: Step S1051: Perform morphological post-processing on the edges of the background mask to smooth jagged edges. Specifically, morphological closing operations, such as dilation followed by erosion, can be used to fill the gaps in the hair, and Gaussian filtering can be used to smooth the edges, thereby smoothing the jagged edges of the background mask.
[0036] Step S1052: Determine the specified background color or pattern according to the standard specifications for ID photos or user input.
[0037] Specifically, step S1052 can be implemented as follows: if the ID photo standard specifies a background color, such as white or red, then the background color specified by the ID photo standard is directly adopted; if user input is allowed, then the color value selected by the user or the uploaded pattern data is received through the device interface.
[0038] Step S1053: Based on the smoothed background mask, replace the background pixels at the corresponding positions in the original image with the specified background color or pattern.
[0039] Specifically, step S1053 can be implemented by traversing the pixel positions marked as background in the mask image and replacing the RGB values of the corresponding pixels in the image after the position size is standardized with the pixel values of the specified color or pattern.
[0040] Step S1054: Perform anti-aliasing fusion on the foreground edges to generate an image with background replacement. The anti-aliasing fusion can be achieved by calculating the average color transition between the foreground edge pixels and the background.
[0041] Specifically, step S1054 can be implemented by: detecting foreground edge pixels, calculating the average color of the pixels and their adjacent background pixels, and using the average color as a transition color to fill the edge area to reduce jaggedness.
[0042] Practice has shown that if computational tasks are executed purely serially, not only will the cumulative latency of sequential waiting at each step be greatly increased, but the GPU utilization will also be low during non-inference periods, resulting in wasted computing resources. Furthermore, CPU-intensive tasks will block event loops, causing the user interface to freeze, and the rapid increase in peak power consumption will easily trigger system throttling. To address resource deadlock issues such as fragmented computing power, complex task dependencies, and latency sensitivity limits in serial pipelines on mobile devices, during the execution of steps S102 to S104 in the above embodiment, the computationally demanding processing steps can be decomposed into tasks, and independent or low-dependency task sub-items can be executed in parallel using the multi-threading or hardware acceleration resources of resource-constrained devices. Specifically, for computationally demanding processing steps, tasks are decomposed and independent or low-dependency sub-tasks are executed in parallel using the device's multi-threading or hardware acceleration resources. This can be achieved by identifying at least one of the following as computationally demanding steps: forward inference computation of a lightweight convolutional neural network model, forward inference computation of a lightweight image segmentation model, and affine transformation computation. These steps are then executed in parallel on GPUs or multi-core CPUs by scheduling multiple computation threads. During execution, the device resource status is monitored in real time, and the number of parallel threads or task granularity is dynamically adjusted based on the monitoring results to optimize overall execution speed and avoid resource overload. By scheduling tasks in real time according to task type and device status—for example, GPUs excel at model inference and CPUs at geometric transformations—not only can hardware resource utilization be maximized, enabling smooth operation on low-to-mid-range devices, but the real-time responsiveness of the processing flow can also be guaranteed, avoiding process interruptions caused by user timeouts.
[0043] It should be noted that in the above embodiments, independent or low-dependency task sub-items refer to sub-tasks that can be executed in parallel without waiting for the results of other tasks. For example, face detection model inference and image segmentation model inference can run simultaneously. High computational demand steps refer to steps with high computational complexity, long execution time, or large resource consumption, such as model forward inference or large-scale geometric transformations. As for dynamically adjusting the number of threads or task granularity for parallel execution based on monitoring results, this can specifically involve: real-time monitoring of device CPU / GPU utilization and memory usage; increasing the number of threads if the utilization is below a threshold, and decreasing the number of threads or splitting the task into finer-grained tasks if it is close to overload.
[0044] Step S106: Perform image quality enhancement processing on the image after background replacement to generate an enhanced image.
[0045] Background replacement is a basic requirement for ID photos in various countries. However, this replacement may introduce some physical contradictions. Specifically, if the replaced background (e.g., red) does not match the lighting environment of the face, false color differences may appear at the facial edges, which does not meet the skin tone tolerance requirements of ISO / IEC 19794-5. Furthermore, mandatory ID photo specifications (e.g., China GA / T 461-2019) require a vertical pupil spacing of ≥120 pixels; interpolation scaling can lead to blurred pupils. Similarly, ICAO Doc 9303 requires clear iris texture; background replacement may erase iris details, and so on. Therefore, to meet various international standards for ID photos and to combat the distortion amplification caused by subsequent encoding compression (step S107), this embodiment of the application can perform image quality enhancement processing on the background-replaced image to generate a quality-enhanced image. This can involve one or more of the following operations: performing adaptive histogram equalization to improve image contrast, using an unsharpened mask algorithm to enhance image detail clarity, and performing color balance adjustments to meet standard skin tone requirements, etc. The above quality enhancement process reduces high-frequency noise caused by background replacement and suppresses high-frequency components before quantization to counteract defects such as blockiness and chroma subsampling caused by subsequent compression operations.
[0046] Step S107: Encode and compress the enhanced image to conform to the ID photo output specifications to generate the final ID photo image.
[0047] If uncompressed images are stored directly, it may exceed the transmission bandwidth of resource-constrained devices. A fixed compression ratio or the use of general compression will result in blurry high-resolution photos that do not meet the clarity standards for ID photos. Therefore, in the embodiments of this application, the enhanced images can be encoded and compressed in accordance with the output specifications for ID photos. For example, lossless compression or low compression ratio can be used to preserve micro-features in key facial regions (triangular eye-nose-lip area), while high compression ratio can be used for background regions, and so on.
[0048] To identify compliance flaws that are difficult to detect manually and to enable the system to have self-inspection capabilities, forming a complete automated chain, after generating the final ID photo image, a pre-trained classification and verification model can be used to analyze the final ID photo image to calculate the degree of conformity score between the final ID photo image and the ID photo standard specifications on key items. If the degree of conformity score is lower than a predetermined threshold, a verification error message is output or a reprocessing process is triggered. Key items can include face proportion, background color consistency, etc. Specifically, the analysis of the final ID photo image using the pre-trained classification and verification model to calculate the degree of conformity score between the final ID photo image and the ID photo standard specifications on key items can be performed as follows: The final ID photo image is input into a multi-task classification model, and the model outputs scores for key attributes (e.g., face centering, background color purity); weights are set according to the ID photo standard specifications, and the scores of each key attribute are weighted and summed to obtain a total score as the degree of conformity score. The above processing can eliminate invalid ID photo output, prevent users from repeatedly retaking photos due to non-compliance, and ensure the recognizability of biometric features, meeting the core requirements of facial recognition systems such as pupil clarity.
[0049] From the above appendix Figure 1 The example of ID photo generation on resource-constrained devices demonstrates three key advantages: First, the collaborative architecture of a lightweight convolutional neural network model and a lightweight image segmentation model solves the problem of traditional large-scale models being unable to be deployed on low-configuration devices. Second, the lightweight model, through structured and simplified design, maintains critical task accuracy without relying on high-performance hardware, enabling resource-constrained devices such as embedded terminals and older mobile phones to generate photos in real time. Third, the processing chain is dynamically driven by ID photo standards, including adjusting size and position, background replacement, and combining encoding and compression to meet output specifications, ensuring that the generated images strictly comply with national / industry standards. This achieves automated compliance processing without human intervention, avoiding efficiency bottlenecks caused by manual verification. In summary, the technical solution of this application, through lightweight model collaborative parallel processing, can efficiently generate standardized ID photos on resource-constrained devices.
[0050] Please see the appendix Figure 2 This application provides a device for generating ID photos on a resource-constrained device. The device may include an acquisition module 201, a detection module 202, a first generation module 203, a segmentation module 204, a second generation module 205, an enhancement module 206, and a third generation module 207, as detailed below: The acquisition module 201 is used to acquire input image data; Detection module 202 is used to detect face regions in input image data using a lightweight convolutional neural network model in order to obtain face location information; The first generation module 203 is used to adjust the size and position of the face in the image based on the preset ID photo standard specifications and the position information of the face, and generate an image with standardized position and size; The segmentation module 204 is used to perform background segmentation on the position-size-normalized image using a lightweight image segmentation model to generate a background mask image; The second generation module 205 is used to replace the segmented background area with a specified background color or pattern based on the background mask image and the standard specifications for ID photos, and generate an image after background replacement. Enhancement module 206 is used to perform image quality enhancement processing on the image after background replacement to generate an enhanced image; The third generation module 207 is used to encode and compress the enhanced image in accordance with the ID photo output specifications to generate the final ID photo image.
[0051] From the above appendix Figure 2 As illustrated by the example of an ID photo generation device on a resource-constrained device, on the one hand, the collaborative architecture based on a lightweight convolutional neural network model and a lightweight image segmentation model solves the problem that traditional large models cannot be deployed on low-configuration devices. On the other hand, the lightweight model, through a structured and simplified design, maintains the accuracy of critical tasks without relying on high-performance hardware, enabling resource-constrained devices such as embedded terminals and older mobile phones to generate photos in real time. Thirdly, the processing chain is dynamically driven by ID photo standards and specifications, including adjusting size and position, and replacing the background. Combined with encoding and compression processing to meet output specifications, this ensures that the generated images strictly comply with national / industry standards, achieving automated compliance processing without human intervention and avoiding efficiency bottlenecks caused by manual verification. In summary, the technical solution of this application, through the collaborative parallel processing of a lightweight model, can efficiently generate standardized ID photos on resource-constrained devices.
[0052] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 3 As shown, the electronic device 3 in this embodiment mainly includes: a processor 30, a memory 31, and a computer program 32 stored in the memory 31 and executable on the processor 30, such as a program for generating ID photos on a resource-constrained device. When the processor 30 executes the computer program 32, it implements the steps in the above-described embodiment of the method for generating ID photos on a resource-constrained device, for example... Figure 1 The steps S101 to S107 are shown. Alternatively, when the processor 30 executes the computer program 32, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 2 The functions of the acquisition module 201, detection module 202, first generation module 203, segmentation module 204, second generation module 205, enhancement module 206, and third generation module 207 are shown.
[0053] For example, the computer program 32 for generating ID photos on a resource-constrained device mainly includes: acquiring input image data; using a lightweight convolutional neural network model to detect face regions in the input image data to obtain face location information; adjusting the size and position of the face in the image based on preset ID photo standards and face location information to generate a position-size standardized image; using a lightweight image segmentation model to perform background segmentation processing on the position-size standardized image to generate a background mask image; replacing the segmented background regions with a specified background color or pattern based on the background mask image and ID photo standards to generate a background-replaced image; performing image quality enhancement processing on the background-replaced image to generate a quality-enhanced image; and performing encoding and compression processing on the quality-enhanced image in accordance with ID photo output specifications to generate the final ID photo image. The computer program 32 can be divided into one or more modules / units, one or more of which are stored in memory 31 and executed by processor 30 to complete this application. One or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 32 in the electronic device 3. For example, computer program 32 can be divided into the functions of an acquisition module 201, a detection module 202, a first generation module 203, a segmentation module 204, a second generation module 205, an enhancement module 206, and a third generation module 207 (a module in the virtual device). The specific functions of each module are as follows: the acquisition module 201 is used to acquire input image data; the detection module 202 is used to detect the face region in the input image data using a lightweight convolutional neural network model to obtain the position information of the face; the first generation module 203 is used to adjust the size and position of the face in the image based on the preset ID photo standard and the position information of the face, and generate... The image is generated by: a position-size normalized image; a segmentation module 204, which uses a lightweight image segmentation model to perform background segmentation on the position-size normalized image and generate a background mask; a second generation module 205, which replaces the segmented background area with a specified background color or pattern based on the background mask and the ID photo standard specifications, and generates a background-replaced image; an enhancement module 206, which performs image quality enhancement processing on the background-replaced image and generates a quality-enhanced image; and a third generation module 207, which performs encoding and compression processing on the quality-enhanced image in accordance with the ID photo output specifications, and generates the final ID photo image.
[0054] Electronic device 3 may include, but is not limited to, processor 30 and memory 31. Those skilled in the art will understand that... Figure 3This is merely an example of electronic device 3 and does not constitute a limitation on electronic device 3. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic devices may also include input / output devices, network access devices, buses, etc.
[0055] The processor 30 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0056] The memory 31 can be an internal storage unit of the electronic device 3, such as a hard disk or RAM. The memory 31 can also be an external storage device of the electronic device 3, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 31 can include both internal and external storage units of the electronic device 3. The memory 31 is used to store computer programs and other programs and data required by the electronic device. The memory 31 can also be used to temporarily store data that has been output or will be output.
[0057] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed. That is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above-described device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0058] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0059] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0060] In the embodiments provided in this application, it should be understood that the disclosed apparatus / device and method can be implemented in other ways. For example, the apparatus / device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0061] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0062] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0063] If an integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, all or part of the processes in the above-described embodiments of this application can also be implemented by a computer program instructing related hardware. On resource-constrained devices, the computer program for the ID photo generation method can be stored in a storage medium. When executed by a processor, this computer program can implement the steps of the various method embodiments described above, namely: acquiring input image data; using a lightweight convolutional neural network model to detect the face region in the input image data to obtain the face's position information; adjusting the size and position of the face in the image based on preset ID photo standards and the face's position information to generate a position-size standardized image; using a lightweight image segmentation model to perform background segmentation processing on the position-size standardized image to generate a background mask; based on the background mask and ID photo standards, replacing the segmented background region with a specified background color or pattern to generate a background-replaced image; performing image quality enhancement processing on the background-replaced image to generate a quality-enhanced image; and performing encoding and compression processing on the quality-enhanced image in accordance with ID photo output specifications to generate the final ID photo image. Computer programs include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Storage media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the contents of storage media can be appropriately added or removed according to the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, storage media do not include electrical carrier signals and telecommunication signals.
[0064] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application. The specific embodiments described above further illustrate the purpose, technical solutions, and beneficial effects of this application. It should be understood that the above descriptions are merely specific embodiments of this application and are not intended to limit the protection scope of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this invention.
Claims
1. A method for generating ID photos on a resource-constrained device, characterized in that, The method includes the following steps: S1: Acquire input image data; S2: Use a lightweight convolutional neural network model to detect the face region in the input image data to obtain the face location information; S3: Based on the preset ID photo standard specifications and the position information of the face, adjust the size and position of the face in the image to generate an image with standardized position and size; S4: Use a lightweight image segmentation model to perform background segmentation on the image after the location size is normalized, and generate a background mask image; S5: Based on the background mask image and the standard specifications for ID photos, replace the segmented background area with the specified background color or pattern to generate an image with the background replaced; S6: Perform image quality enhancement processing on the image after background replacement to generate an enhanced image; S7: The enhanced image is encoded and compressed in accordance with the ID photo output specifications to generate the final ID photo image.
2. The method for generating ID photos on resource-constrained devices according to claim 1, characterized in that, The process of adjusting the size and position of the face in the image based on preset ID photo standards and facial position information to generate a position- and size-standardized image includes: Calculate the offset between the center point coordinates of the face bounding box and the center coordinates of the standard ID photo frame based on the face's location information; Based on the proportion requirement of the face in the image after the location size is standardized, as specified in the ID photo standard, calculate the scaling factor of the width or height of the face bounding box relative to the standard size. Perform an image geometric transformation operation, using the offset and scaling factor to translate and scale the image region containing the face, to obtain an image with the position size normalized.
3. The method for generating ID photos on resource-constrained devices according to claim 1, characterized in that, The background segmentation process of the location-size-normalized image using a lightweight image segmentation model includes: Based on the aforementioned lightweight image segmentation model, a U-Net structure is used to encode and decode the probability value of each pixel in the image after the location size is normalized to belong to the background. The probability value of each pixel belonging to the background is binarized using a set probability threshold to generate a background mask image.
4. The method for generating ID photos on resource-constrained devices according to claim 3, characterized in that, The process of replacing the segmented background area with a specified background color or pattern based on the background mask image and ID photo standard specifications to generate a background-replaced image includes: Morphological post-processing is performed on the edges of the background mask to smooth jagged edges; The specified background color or pattern is determined based on the standard specifications for ID photos or user input. Based on the background mask image after the anti-aliasing process, the background pixels at the corresponding positions in the image after the position size is normalized are replaced with the specified background color or pattern; Anti-aliasing fusion is performed on the foreground edges to generate the background-replaced image.
5. The method for generating ID photos on resource-constrained devices according to claim 1, characterized in that, The method further includes: during the execution of steps S2 to S4, decomposing the computationally demanding processing steps into tasks, and using the multi-threading or hardware acceleration resources of resource-constrained devices to execute independent or low-dependency task sub-items in parallel.
6. The method for generating ID photos on resource-constrained devices according to claim 5, characterized in that, The process of decomposing computationally demanding processing steps into tasks and utilizing the device's multi-threading or hardware acceleration resources to execute independent or low-dependency task sub-items in parallel includes: At least one of the forward inference computation of the lightweight convolutional neural network model, the forward inference computation of the lightweight image segmentation model, and the affine transformation computation is identified as a computationally demanding step, and the parallel execution is achieved on a GPU or CPU multi-core by scheduling multiple computing threads. During execution, the device resource status is monitored in real time, and the number of threads or task granularity executed in parallel is dynamically adjusted based on the monitoring results.
7. The method for generating ID photos on resource-constrained devices according to claim 1, characterized in that, After generating the final ID photo image, the process also includes: The final ID photo image is analyzed using a pre-trained classification and verification model to calculate the degree of conformity between the final ID photo image and the ID photo standard specification on key items. If the score is lower than a predetermined threshold, a verification error message will be output or a reprocessing process will be triggered.
8. A device for generating ID photos on resource-constrained equipment, characterized in that, The device includes: The acquisition module is used to acquire input image data; The detection module is used to detect the face region in the input image data using a lightweight convolutional neural network model in order to obtain the position information of the face; The first generation module is used to adjust the size and position of the face in the image based on the preset ID photo standard specifications and the position information of the face, and generate an image with standardized position and size; The segmentation module is used to perform background segmentation processing on the image after the location size is normalized using a lightweight image segmentation model, and generate a background mask image; The second generation module is used to replace the segmented background area with a specified background color or pattern based on the background mask image and the ID photo standard specifications, and generate an image with background replacement. The enhancement module is used to perform image quality enhancement processing on the image after background replacement to generate an enhanced image; The third generation module is used to encode and compress the enhanced image in accordance with the ID photo output specifications to generate the final ID photo image.
9. An electronic device, the device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 7.
10. A storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.