ID photo production method, system, medium and equipment based on face detection
The target area is obtained through face detection and affine transformation, and combined with portrait closure and background synthesis, the existing document photo production method has solved the problem of high requirements for the original image, and achieved a more convenient and intelligent document photo production process.
Patent Information
- Application Number
- CN202111105854.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-22
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2041-09-22
AI Technical Summary
The existing method of document photo production has high requirements for the original image, which leads to inconvenience in use and is less intelligent, requiring manual participation and cooperation of multiple software.
Face information is obtained through face detection, the target face is determined by the face area center method, and the target area is obtained through affine transformation. Then use portrait buckle to generate a mask, and finally combine the target area with the background to generate a document photo.
The requirements for the original image are reduced, and the intelligence of document photo production is improved, making the document photo production more convenient and fast.
Smart Images

Figure CN113887352B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method, system, medium and device for producing an ID photo based on face detection. Background Art
[0002] In today's society, various types of certificates have become indispensable proof of identity and rights in people's lives and work; and with the demand for various certificates, the need to make certificate photos has also become an indispensable step in people's certificate processing; and in order to replace the cumbersome and time-consuming physical photography method, various image processing software have launched corresponding certificate photo production functions.
[0003] Existing ID photo processing tools still require manual participation, and post-production needs to rely on Photoshop technology, etc., and due to the single function, multiple software are required to meet different needs, resulting in the problem of low intelligence in ID photo production. Although the prior art, such as the Chinese patent with application number CN202010357639.0 and publication date of July 31, 2020, discloses a method for making ID photos, which generates ID photos by obtaining the portrait area and the face area and adjusting them to meet the target area, which improves the intelligence of ID photo production to a certain extent, but only a simple rectangular interception is performed with the center of the face, and face correction is not considered. However, there are still problems with intelligence in the existing ID photo production methods, such as high requirements for early photos, and the need for other software tools to assist.
[0004] In summary, the ID photo production method in the prior art has high requirements for the original image, which causes inconvenience in use. Summary of the invention
[0005] In order to solve the above problems in the prior art, the present invention provides a method for making a ID photo based on face detection, comprising the following steps:
[0006] S10, obtaining facial information in the original image, wherein the facial information includes at least one face and a group of feature points located on each face;
[0007] S20, determining a target face by using a face area center method according to the face information;
[0008] S30, acquiring a target region A including the target face through affine transformation according to the feature point group on the target face, wherein the target face angle in the target region A matches the template face angle in the standard photo;
[0009] S40, performing portrait cutout on the target area A to generate a mask M;
[0010] S50 , establishing a background B, and synthesizing the target area A and the background B through a mask M to generate an ID photo P.
[0011] In one embodiment, the following steps are further included before step S10:
[0012] Receive user data, the user data including the original image, background color and ID photo size.
[0013] In one embodiment, the face information in step S10 is obtained by a face detector, and the face detector includes a deep model face detector implemented in mobilenet based on the retinaface principle.
[0014] In one embodiment, determining the target face by using the face area center method in step S20 includes the following steps:
[0015] S21: Obtaining area information of each face in the face information;
[0016] S22: Calculating the offset information of the center of each face from the center of the original image according to the face information;
[0017] S23: Calculate the area center information of each face, where the area center information is equal to the area information minus the offset information, and take the face with the maximum value of the area center information as the target face.
[0018] In one embodiment, the step S30 includes the following steps:
[0019] S31: providing template feature point group information in the standard document, wherein the template feature point group information includes the positional relationship of each template feature point;
[0020] S32: performing an affine transformation on the original image according to the feature point group of the target face and the information of the template feature point group, so that the positional relationship of each feature point in the feature point group matches the positional relationship of each template feature point;
[0021] S33: performing a rectangular interception on the image after affine transformation to obtain the target area A.
[0022] In one embodiment, the step S30 further includes the following steps for removing black edges from the target area A:
[0023] S34: Binarizing the target area A to generate a binary image, in which the pixel value of the black edge area is 0, and the pixel value of the non-black edge area is 255;
[0024] S35: traversing pixels from the starting edge where the black edge of the binary image is located toward the center, and recording the farthest distance from a point with a pixel value of 0 to the starting edge as the cropping amount;
[0025] S36: Crop the target area A with the aspect ratio maintained according to the cropping amount to remove the black border.
[0026] In one embodiment, the synthesis step in step S50 includes:
[0027] S51: preprocessing the mask M so that the format of the mask M matches the format of the target area A;
[0028] S52: Establish background B according to the background color;
[0029] S53: Array operation synthesis: ID photo P = target area A*mask M+background B*(1-mask M).
[0030] The present invention also provides a system for making ID photos based on face detection, comprising:
[0031] A face detection module, used to obtain face information in the original image, wherein the face information includes at least one face and a set of feature points located on each face;
[0032] A target determination module, which determines a target face by using a face area center method according to the face information;
[0033] A transformation module, configured to obtain a target region A including the target face through affine transformation according to the feature point group on the target face, wherein the target face angle in the target region A matches the template face angle in the standard photo;
[0034] A mask generation module, used for performing a portrait cutout on the target area to generate a mask M;
[0035] The synthesis module is used to establish a background B, synthesize the target area and the background through a mask, and generate an ID photo P.
[0036] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer is executed by a processor, the method for producing an ID photo based on face detection as described in any of the above items is implemented.
[0037] The present invention also provides a computer device, comprising at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor so that the processor executes the ID photo production method based on face detection as described in any of the above items.
[0038] The method for making ID photos based on face detection provided by the present invention first obtains the face information in the original image and determines the target face therefrom, which can avoid the interference of other faces that may be contained in the original image and reduce the requirements for the original image; the target area is intercepted after matching the feature point group in the face information and the standard photo through affine transformation, so the requirements for the face angle in the original image are relatively low; then a mask is generated by portrait clipping, and finally the mask is used to synthesize the target area and the established background to generate the ID photo. Through intelligent screening and image transformation, various requirements for the original image in making ID photos are reduced, making the production of ID photos more convenient and fast.
[0039] Other features and beneficial effects of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other beneficial effects of the present invention can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. The positional relationships described in the drawings in the following description are based on the directions in which the components are drawn in the diagrams, unless otherwise specified.
[0041] Figure 1 A flow chart of a method for making ID photos based on face detection provided by the present invention;
[0042] Figure 2 This is an example of the original image of the embodiment;
[0043] Figure 3 This is a schematic diagram of the target face and related face information of the embodiment;
[0044] Figure 4 This is a flow chart of face detection picture enhancement in the embodiment;
[0045] Figure 5 This is a schematic diagram of the target area after the black border is removed in the embodiment;
[0046] Figure 6 Schematic diagram of a mask according to an embodiment. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments; the technical features designed in different implementation modes of the present invention described below can be combined with each other as long as they do not conflict with each other; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0048] In the description of the present invention, it should be noted that all terms used in the present invention (including technical terms and scientific terms) have the same meanings as those generally understood by ordinary technicians in the field to which the present invention belongs, and cannot be understood as limiting the present invention; it should be further understood that the terms used in the present invention should be understood to have the same meanings as these terms in the context of this specification and in the relevant fields, and should not be understood in an idealized or overly formal sense, unless explicitly defined in the present invention.
[0049] Currently, the production of ID photos often requires a single person photo with a correct posture and a single background color, etc., and then needs to use professional PS technology to cut out the image and change the background. Although it saves costs for the photo studio, it still causes inconvenience to the user due to the photo requirements.
[0050] In this regard, the present invention provides a method for producing a certificate photo based on face detection, such as Figure 1 As shown, the following steps are included:
[0051] S10, obtaining facial information in the original image, wherein the facial information includes at least one face and a group of feature points located on each face;
[0052] S20, determining a target face by using a face area center method according to the face information;
[0053] S30, acquiring a target region A including the target face through affine transformation according to the feature point group on the target face, wherein the target face angle in the target region A matches the template face angle in the standard photo;
[0054] S40, performing portrait cutout on the target area A to generate a mask M;
[0055] S50 , establishing a background B, and synthesizing the target area A and the background B through a mask M to generate an ID photo P.
[0056] Specifically, before step S10, the method further includes: receiving user data. The user data includes but is not limited to the original image, the final background color of the target ID photo, and the size of the target ID photo. In an embodiment, the above method steps can be implemented by a ID photo production tool. For example, the tool accepts the original image used to produce the ID photo. The original image does not need to be limited to a single person photo, a single background color, a photo with a correct posture, and other restrictions. The input original image, for example, Figure 2 As shown; and set commonly used background colors such as white, blue, red, etc., preferably, a custom color palette can be set for users to choose colors to achieve diversified background color selection; and set a variety of standard ID photo sizes for selection, and you can also set a custom size (image width and height pixels). Then the original image can be converted to a format such as base64 format, and all user data can be input to the server / terminal in a format other than json.
[0057] Next, step S10 is executed to obtain the face information in the original image, wherein the face information includes all faces and a feature point group on each face, such as Figure 3 As shown, the feature point group includes but is not limited to the left eye, right eye, nose tip, left corner of mouth and right corner of mouth; specifically, the original image information is transmitted to the face detector, and the face information is obtained by the face detector. For example, the face detector adopts a deep model face detector implemented in mobilenet based on the retinaface principle. The face detector will automatically detect all faces in the photo. Due to the addition of image enhancement technology, such as moiré and clarity processing, the specific process is as follows Figure 4 As shown in the figure, the face detection capability is greatly improved through this process. The image resolution is improved by image scaling. At the same size, it contains more pixels, that is, the pixels are denser and the image is clearer, so that the portrait information of the image is more concentrated; smooth filtering is achieved through Gaussian filtering. The single lobe of the Fourier transform of the Gaussian function prevents the smooth image from being polluted by unnecessary high-frequency signals, while retaining most of the required signals, that is, face information. The image after Gaussian filtering is passed to the face detection model; by changing the image contrast, the higher the image contrast, the better, but it should be evaluated according to the original image information, so the image contrast is increased by 2 times and reduced to 0.5 in parallel, and the face with higher confidence is extracted as the detection result; by sharpening the image by 2.0, the sharpening process improves the facial contour features.
[0058] Then, step S20 is executed to determine the target face according to the face information; specifically, the target face is determined by the face area center method, that is, the weighted average of the face area and the face offset image center is calculated, which specifically includes the following steps:
[0059] S21: obtaining area information of each face in the face information, that is, face area areas, which can be calculated through the data in the face information;
[0060] S22: Calculate the offset information of each face center from the center of the original image according to the face information. In some embodiments, the offset information is represented and calculated by the square sum of the offsets of each face center from the center of the image in the X-axis and Y-axis directions, offsets_squared.
[0061] S23: Calculate the area center information of each face, the area center information is equal to the area information minus the offset information, and take the face with the maximum area center information as the target face. For example, in some embodiments, take the face with the largest value of (areas-offsets_squared*2) as the target face. Specifically, the weights of the offset and the face area can be adjusted according to the actual situation to find the best solution, which is not limited to the above embodiments.
[0062] In this embodiment, the face area center method is used to realize the function of intelligently screening the target face for the original image that may contain faces of other persons except the target person, so that the requirements of the process for the original image are reduced and there is no need to use a single person photo.
[0063] Next, step S30 is executed to perform affine transformation according to the feature point group on the target face and the standard photo, and intercept the target area A. Specifically, the following steps are included:
[0064] S31: providing template feature point group information in the standard photo, the template feature point information including the positional relationship of each template feature point, the template feature point group information is the coordinate information of the template feature points in the standard ID photo that is previously calculated based on a large number of standard ID photos, and corresponds to the face information, the template feature points include the left eye, right eye, nose tip, left corner of the mouth and right corner of the mouth of the face in the standard photo, and the coordinate information is shown in the following table. The template feature point group information in the standard photo can be selected according to actual needs but is not limited to the following;
[0065] Template feature points Standard 1 inch Standard 2 inches Left Eye (113.6,160.2) (158.3,254.6) Right eye (181.4,160.2) (254.7,254.6) tip of the nose (147.5,201.5) (206.5,310.3) Left corner of mouth (121.7,231.5) (167.4,354.6) Right corner of mouth (173.3,231.5) (245.6,354.6)
[0066] S32: Perform an affine rotation transformation on the original image based on the target face feature point group and the template feature point group information, so that the positional relationship of each feature point in the feature point group matches the positional relationship of each template feature point; for example, in some embodiments, the first coordinate system is determined based on the positional relationship of each feature point in the face information, the origin of the coordinate system is the upper left corner of the image, the horizontal right is the positive x-axis, and the vertical downward is the positive y-axis. The second coordinate system is established based on the positional relationship of each template feature point in the standard photo using the same rules as the first coordinate system, and then the original image is affinely transformed (rotated and / or scaled) so that the positional relationship of each feature point in the face information after the first coordinate system transformation matches the positional relationship of each template feature point. For example, after the transformation, the line connecting the left eye and the right eye is horizontal, and the Y-axis coordinates of the two match the left eye and the right eye in the template feature point.
[0067] S33: performing a rectangular interception on the radially rotated image to obtain a target area A. The size of the intercepted rectangle may be, but is not limited to, the size of the target ID photo.
[0068] In the process of obtaining the target area A, rotation may occur. When the face is large or close to the edge, the target area A generated will lack part of the image. In some embodiments, the missing area is filled with black pixels, that is, a black edge is generated. Figure 3 To solve the impact of the black border, step S30 also includes the following steps of removing the black border in the target area A.
[0069] S34: Binarize the target area A to generate a binary image, in which the pixel value of the black edge area is 0, and the pixel value of the non-black edge area is 255;
[0070] S35: Perform pixel traversal from the starting edge where the black edge is located to the center of the binary image, and record the farthest distance from the point with a pixel value of 0 to the starting edge as the cropping amount. Specifically, for example, when the black edge is on the right side of the target area, traverse from the right edge to the left to determine whether the current straight line X=a (the initial value of a is the horizontal coordinate value of the right edge) has a black pixel. If so, the straight line X=a is moved one pixel to the left and continues to be judged until it is determined for the first time that the straight line X=a has no black pixels, and record the traversed distance as the cropping amount. When the black edge is on the edge on other sides, the above judgment method is used except that the traversal direction is different.
[0071] S36: The target area A is cropped with the same cropping amount while maintaining the aspect ratio to remove the black edges, and the surrounding areas of the target area A are cropped with the same cropping amount. Figure 5 Shown Figure 3 The target area after removing the black borders.
[0072] After the target area A is captured, step S40 is executed to perform a portrait cutout on the target area to generate a mask M. In some embodiments, step S40 passes the target area A into the Cernet deep model network of the cutout technology to perform a portrait cutout to obtain the mask M of the image, such as Figure 6 shown.
[0073] Preferably, the method of generating the mask M can also be implemented by but not limited to PS technology (manual cutout) or other deep learning networks such as paddle_humanseg, remvebg, indexnet_matting or PortraitNet.
[0074] Then, step S50 is executed to establish a background B, and the target area A and the background B are synthesized by using a mask M to generate an ID photo P. The steps of synthesizing the ID photo P include:
[0075] S51: Preprocess the mask M so that the format of the mask M matches the format of the target area A. The mask M is a single-channel grayscale image, which is enlarged 255 times and expanded by 3 channels. ;
[0076] S52: Background B established according to the background color;
[0077] S53: Array operation synthesis, the equation is:
[0078] ID photo P = target area A*mask M+background B*(1-mask M).
[0079] It should be understood that there is no specific order between step S51 and step S52, and the step numbers are merely used to distinguish them.
[0080] Finally, if the size of the generated ID photo P does not match the input target ID photo size, it is scaled according to the ratio to obtain the final required ID photo.
[0081] The method for making ID photos based on face detection provided by the present invention first obtains the face information in the original image and determines the target face therefrom, which can avoid the interference of other faces that may be contained in the original image and reduce the requirements for the original image; the target area is intercepted after matching the feature point group in the face information and the standard photo through affine transformation, so the requirements for the face angle in the original image are relatively low; then a mask is generated by portrait clipping, and finally the mask is used to synthesize the target area and the established background to generate the ID photo. Through intelligent screening and image transformation, various requirements for the original image in making ID photos are reduced, making the production of ID photos more convenient and fast.
[0082] The present invention also provides a system for making ID photos based on face detection, comprising:
[0083] A face detection module is used to obtain face information in the original image, wherein the face information includes all faces and a feature point group on each face;
[0084] A target determination module, used to determine a target face according to the face information;
[0085] A transformation module, used to perform affine transformation according to the feature point group on the target face and the standard photo, and intercept the target area A;
[0086] A mask generation module, used for performing a portrait cutout on the target area to generate a mask M;
[0087] The synthesis module is used to establish a background B, synthesize the target area and the background through a mask, and generate an ID photo P.
[0088] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer is executed by a processor, the method for producing an ID photo based on face detection as described in any of the above items is implemented.
[0089] In a specific implementation, the computer-readable storage medium is a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (HDD) or a solid-state drive (SSD), etc.; the computer-readable storage medium may also include a combination of the above-mentioned types of memory.
[0090] The present invention also provides an electronic device, comprising at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the processor executes the ID photo production method based on face detection as described in any of the above items.
[0091] In specific implementation, the number of processors may be one or more, and the processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components and other chips, or a combination of the above-mentioned chips. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0092] The memory and the processor can be communicatively connected via a bus or other means. The memory stores instructions that can be executed by at least one processor. The instructions are executed by at least one processor so that the processor executes the multi-round dialogue intelligent inquiry processing method as described in any of the above items.
[0093] In addition, those skilled in the art should understand that, although there are many problems in the prior art, each embodiment or technical solution of the present invention can be improved in only one or several aspects, without having to solve all the technical problems listed in the prior art or background technology at the same time. Those skilled in the art should understand that the content not mentioned in a claim should not be used as a limitation on the claim.
[0094] The terms "first", "second", etc. (if any) in the description and claims of the embodiments of the present invention and the above drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0095] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 invention.
Claims
1. A method for making ID photos based on face detection, characterized in that: The following steps are involved: S10, obtaining facial information in the original image, wherein the facial information includes at least one face and a group of feature points located on each face; S20, determining a target face by using a face area center method according to the face information; determining the target face by using a face area center method in step S20 comprises the following steps: S21: Obtaining area information of each face in the face information; S22: Calculating the offset information of the center of each face from the center of the original image according to the face information; S23: calculating the area center information of each face, the area center information being equal to the area information minus the offset information, and taking the face with the maximum area center information as the target face; S30, acquiring a target region A including the target face through affine transformation according to the feature point group on the target face, wherein the target face angle in the target region A matches the template face angle in the standard photo; S40, performing portrait cutout on the target area A to generate a mask M; S50 , establishing a background B, and synthesizing the target area A and the background B through a mask M to generate an ID photo P.
2. The method for making a ID photo based on face detection according to claim 1, characterized in that: Also included are steps before step S10: Receive user data, the user data including the original image, background color and ID photo size.
3. The method for making a ID photo based on face detection according to claim 2, characterized in that: The face information in step S10 is obtained through a face detector, and the face detector includes a deep model face detector implemented in mobilenet based on the retinaface principle.
4. The method for making a ID photo based on face detection according to claim 1, characterized in that: The step S30 comprises the following steps: S31: providing template feature point group information in the standard photo, wherein the template feature point group information includes a positional relationship between each of the template feature points; S32: performing an affine transformation on the original image according to the feature point group of the target face and the information of the template feature point group, so that the positional relationship of each feature point in the feature point group matches the positional relationship of each template feature point; S33: performing a rectangular interception on the image after affine transformation to obtain the target area A.
5. The method for making a ID photo based on face detection according to claim 4, characterized in that: The step S30 further includes the following steps for removing the black edges from the target area A: S34: Binarizing the target area A to generate a binary image, in which the pixel value of the black edge area is 0, and the pixel value of the non-black edge area is 255; S35: traversing pixels from the starting edge where the black edge of the binary image is located toward the center, and recording the farthest distance from a point with a pixel value of 0 to the starting edge as the cropping amount; S36: Crop the target area A with the aspect ratio maintained according to the cropping amount to remove the black border.
6. The method for making a ID photo based on face detection according to claim 2, characterized in that: The synthesis step in step S50 includes: S51: preprocessing the mask M so that the format of the mask M matches the format of the target area A; S52: Establish background B according to the background color; S53: Array operation synthesis: ID photo P = target area A*mask M+background B*(1-mask M).
7. A system for making ID photos based on face detection, characterized in that: include: A face detection module, used to obtain face information in the original image, wherein the face information includes at least one face and a set of feature points located on each face; A target determination module is configured to determine a target face by using a face area center method according to the face information; determining the target face by using the face area center method includes: obtaining area information of each face in the face information; calculating offset information of the center of each face from the center of the original image according to the face information; calculating the area center information of each face, the area center information being equal to the area information minus the offset information, and taking the face with the maximum area center information as the target face; A transformation module, configured to obtain a target region A including the target face through affine transformation according to the feature point group on the target face, wherein the target face angle in the target region A matches the template face angle in the standard photo; A mask generation module, used for performing a portrait cutout on the target area to generate a mask M; The synthesis module is used to establish a background B, synthesize the target area and the background through a mask, and generate an ID photo P.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer is executed by a processor, the method for producing an ID photo based on face detection as described in any one of claims 1 to 6 is implemented.
9. A computer device, characterized in that: It includes at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor so that the processor executes the ID photo production method based on face detection as described in any one of claims 1-6.
Citation Information
Patent Citations
Identification photo manufacturing method, terminal and storage medium
CN111476201A
Image processing method and electronic device
CN108053366A
Certificate photo generation method and device, electronic equipment and storage medium
CN110827371A