Image recognition method and device, computer device and computer readable storage medium
By detecting target feature points in facial images and performing image matting, the problem of time-consuming and low-accuracy cropping of ID photos by self-service photo collection devices has been solved, achieving fast and accurate ID photo cropping.
Patent Information
- Application Number
- CN202310389191.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-12
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2043-04-12
AI Technical Summary
In existing image recognition technologies, self-service photo capture devices have a long processing time and low recognition accuracy when cropping ID photos.
By detecting target feature points in the initial face image, the target region is determined, the first target image is obtained by cutout, and preset processing is performed to remove stray hairs. Finally, the target boundary line is determined based on the second target image for cropping.
It enables rapid and accurate determination of the top of a person's head in a facial image, improving the accuracy of cropping ID photos using self-service photo capture devices.
Smart Images

Figure CN116469145B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image recognition, and in particular to an image recognition method and device, a computer device, and a computer readable storage medium. BACKGROUND
[0002] Image recognition technology is an important technology in the information age, and its purpose is to let computers replace humans to process a large amount of physical information. With the development of computer technology, human understanding of image recognition technology is becoming more and more profound, and image recognition technology is widely used in many fields of human life such as public security, biology, industry, agriculture, transportation, medical treatment and smart government service, and research on image recognition technology is of great significance.
[0003] For example, in the field of smart government service, users can complete the shooting of personal ID photos based on self-service photo collection devices such as self-service cameras, which greatly facilitates users and requires the self-service photo collection device to accurately crop standard ID photos. The existing processing method is to identify and crop according to the foreground and background of the photo, which is time-consuming and has low recognition accuracy. SUMMARY
[0004] Therefore, one of the purposes of the present application is to provide an image recognition method, device, computer device and computer readable storage medium, which can at least solve part of the above technical problems.
[0005] In a first aspect, an image recognition method is provided, and the method comprises:
[0006] detecting a target feature point of an initial face image, and determining a target region according to the target feature point, wherein the target region contains the top of the initial face image;
[0007] masking the initial face image according to the target region to obtain a first target image;
[0008] performing a preset processing on the first target image to obtain a second target image;
[0009] determining a target boundary line according to the second target image, wherein the position of the target boundary line is the position of the top of the initial face image, and the target boundary line is used to indicate the cropping of the initial face image.
[0010] In a possible implementation, the detecting a target feature point of an initial face image, and determining a target region according to the target feature point comprises:
[0011] detecting an initial feature point of the initial face image;
[0012] The target feature points are determined based on the initial feature points, and the target region is determined according to the target feature points, wherein the number of the initial feature points is greater than the number of the target feature points.
[0013] In a possible implementation, the target feature points are determined based on the initial feature points, and the target region is determined according to the target feature points, wherein the number of the initial feature points is greater than the number of the target feature points.
[0014] The initial face image is subjected to face pose estimation according to a first preset algorithm, to obtain angle information of a face orientation.
[0015] The target feature points are determined according to the angle information and the initial feature points.
[0016] In a possible implementation, the first target image is subjected to preset processing to obtain a second target image, including:
[0017] The first target image is subjected to clustering analysis according to a second preset algorithm, to obtain a first intermediate image, wherein the first intermediate image includes a skin region, a hair region and a background region.
[0018] The first intermediate image is subjected to edge detection according to a third preset algorithm, to determine an edge line of the hair region of the first intermediate image.
[0019] The edge line is subjected to inflation, corrosion and flood fill processing in sequence, to obtain a second intermediate image in which the broken hair at the edge line is eliminated.
[0020] The second intermediate image is subjected to binaryzation processing, to obtain the second target image.
[0021] In a possible implementation, the first target image includes a skin region, a hair region and a background region, and after the initial face image is cut out according to the target region to obtain the first target image, the method further includes:
[0022] The color value of a target skin color is calculated, and the color value of the background region of the first target image is modified to the color value of the target skin color, to obtain a third intermediate image, wherein the color value of the target skin color is the skin color value of the skin region of the first target image.
[0023] The third intermediate image is subjected to clustering analysis according to a fourth preset algorithm, to obtain a fourth intermediate image.
[0024] A first boundary line is determined according to the fourth intermediate image.
[0025] The target boundary line is determined according to the second target image, including:
[0026] determining a second boundary line according to the second target image;
[0027] calculating a median line of the first boundary line and the second boundary line, and taking the median line as the target boundary line.
[0028] In a possible implementation, the second target image and the fourth intermediate image both include a hair region and a background region, and the determining a first boundary line according to the fourth intermediate image includes:
[0029] traversing from the background region of the fourth intermediate image to the hair region of the fourth intermediate image, and calculating a target ratio of a first pixel point and a second pixel point in each row of pixel points, wherein the first pixel point is a pixel point in the background region of the fourth intermediate image, and the second pixel point is a pixel point in the hair region of the fourth intermediate image;
[0030] taking a row of pixel points corresponding to a target ratio that is first greater than or equal to a first preset ratio as the first boundary line;
[0031] The determining a second boundary line according to the second target image includes:
[0032] traversing from the background region of the second target image to the hair region of the second target image, and calculating a target ratio of a third pixel point and a fourth pixel point in each row of pixel points, wherein the third pixel point is a pixel point in the background region of the second target image, and the fourth pixel point is a pixel point in the hair region of the second target image;
[0033] taking a row of pixel points corresponding to a target ratio that is first greater than or equal to a second preset ratio as the second boundary line.
[0034] In a possible implementation, after the clustering analysis of the third intermediate image according to the fourth preset algorithm is performed to obtain the fourth intermediate image, the method further includes:
[0035] obtaining an HSV image corresponding to the third intermediate image;
[0036] calculating a color value of a target hair color according to the HSV image and the second target image, wherein the color value of the target hair color is a color value of the hair region of the first target image;
[0037] detecting whether a difference between the color value of the target hair color and the color value of the target skin color is within a preset numerical range;
[0038] In a case where a difference between the color value of the target hair color and the color value of the target skin color is within the preset numerical range, performing clustering analysis on the first target image according to the fourth preset algorithm to obtain a third target image;
[0039] Determining the first boundary line according to the third target image.
[0040] In a second aspect, an embodiment of the present application provides an image recognition device, and the device comprises:
[0041] A detection module is configured to detect a target feature point of an initial face image, and determine a target region according to the target feature point, wherein the target region contains a top of the initial face image.
[0042] A matting module is configured to perform matting on the initial face image according to the target region to obtain a first target image.
[0043] A first processing module is configured to perform preset processing on the first target image to obtain a second target image.
[0044] A second processing module is configured to determine a target boundary line according to the second target image, wherein a position of the target boundary line is a position of the top of the initial face image, and the target boundary line is used to indicate that the initial face image is cropped.
[0045] In a third aspect, an embodiment of the present application provides a computer device, and the computer device comprises a memory and a processor, the memory stores a computer program, and the computer program is executed by the processor to implement the image recognition method provided in the first aspect.
[0046] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, and the computer readable storage medium stores a computer program, and the computer program is executed by one or more processors to implement the image recognition method provided in the first aspect.
[0047] The image recognition method provided in the present application first detects a target feature point of an initial face image, and determines a target region according to the target feature point, wherein the target region contains a top of the initial face image, then performs matting on the initial face image according to the target region to obtain a first target image, performs preset processing on the first target image to obtain a second target image, and finally determines a target boundary line according to the second target image, wherein a position of the target boundary line is a position of the top of the initial face image, and the target boundary line is used to indicate that the initial face image is cropped, the whole process has a short processing time, and the top position of the face image can be accurately determined to further determine a cropping region, and the accuracy of a self-service photo collection device in cropping a certificate photo is obviously improved. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced below. It should be understood that the drawings described below are only some embodiments of the present application, and other drawings can also be obtained according to these drawings without creative labor for those skilled in the art.
[0049] Figure 1 The method flow chart of the image recognition method provided for the embodiments of the present application;
[0050] Figure 2 The initial face image involved in the image recognition method provided for the embodiments of the present application;
[0051] Figure 3 The target region schematic diagram involved in the image recognition method provided for the embodiments of the present application;
[0052] Figure 4 The first image processing process schematic diagram involved in the image recognition provided for the embodiments of the present application;
[0053] Figure 5 The target region determination schematic diagram involved in the image recognition provided for the embodiments of the present application;
[0054] Figure 6 The second image processing process schematic diagram involved in the image recognition provided for the present application;
[0055] Figure 7 The bridge of the nose region schematic diagram of the initial face image involved in the image recognition method provided for the embodiments of the present application;
[0056] Figure 8 The functional module schematic diagram of the image recognition device provided for the present application;
[0057] Figure 9 The internal structure diagram of the computer device provided for the embodiments of the present application.
[0058] Icon:
[0059] The image recognition device 800, the detection module 810, the cutout module 820, the first processing module 830, and the second processing module 840. DETAILED DESCRIPTION
[0060] With reference to the accompanying drawings, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative effort are within the protection scope of the present application.
[0061] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. The components of the embodiments of the present application described and shown in the accompanying drawings can be arranged and designed in various different configurations.
[0062] Therefore, the detailed description of the embodiments of the present application provided below in the accompanying drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative effort are within the protection scope of the present application.
[0063] It should be noted that: similar reference numbers and letters represent similar items in the following drawings, therefore, once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.
[0064] In various embodiments of the present application, the expression "or" or "at least one of A or / and B" includes any combination of the listed terms or all combinations thereof. For example, the expression "A or B" or "at least one of A or / and B" can include A, can include B, or can include both A and B.
[0065] In the description of the present application, it should be noted that if the terms "upper", "lower", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, or the orientation or positional relationship when the product of the present application is usually placed, and are only for the convenience of describing the present application and simplifying the description, and therefore cannot be understood as indicating or implying that the indicated device or element must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application.
[0066] In addition, if the terms "first", "second" and the like appear, they are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.
[0067] It should be noted that the features in the embodiments of the present application can be combined with each other without conflict.
[0068] Please refer to Figure 1, Figure 1 A method flowchart of an image recognition method provided in an embodiment of the present application is shown in FIG. 1. The steps of the method will be described in detail below.
[0069] In S110, a target feature point of an initial face image is detected, and a target region is determined according to the target feature point, wherein the target region contains the top of the initial face image.
[0070] In the embodiment, the initial face image can be acquired by an image recognition device in the following embodiment. The image recognition device or a computer device in the following embodiment can further process the acquired initial face image. The image recognition device can also be a common self-service photo acquisition device. The image recognition device can acquire one initial face image at a time, or can acquire at least two face images at a time through multiple cameras, so as to facilitate the image recognition device or the computer device to process one initial face image or at least two face images at the same time, thereby accelerating the processing speed of the initial face image.
[0071] Specifically, the target feature point can be a key face feature such as a mouth, a nose, an eye, or a brow, which is surrounded by multiple feature points. The target region can be used to determine the top position of the portrait in the initial face image. The target region can be determined by the recognized target feature point, and the accuracy of determining the target region based on the target feature point is high.
[0072] In order to clearly show the target region in the embodiment, please refer to FIG. 2. Figure 2 , Figure 2 An initial face image involved in an image recognition method provided in an embodiment of the present application, wherein (a) and (b) are initial face images. The target region determined based on (a) can be represented as a dashed box region S in (b), Figure 2 The two dashed boxes in (a) frame the initial feature points corresponding to the brows, and each initial feature point corresponds to a unique Arabic numeral. As can be seen from (b), the target region S contains the top of the portrait. Therefore, the embodiment of the present application is mainly used for recognizing and positioning the top of the face image. Since accurately obtaining the top position of the portrait in the photo is a prerequisite for cropping a standard ID photo from the original photo, the present application can improve the accuracy of the self-service photo acquisition device in cropping ID photos.
[0073] It can be understood that the target region can be larger or smaller than the region shown in (b), as long as it contains the top.
[0074] In which, it can be seen that the initial feature points identified in the cheek, nose area, mouth area, eye area and eyebrow area of the initial face image all correspond to the set non-repeating Arabic numerals. All initial feature points can be selected as target feature points, or part of the initial feature points with distinctive positions can be selected as target feature points. For example, if the initial feature points from one end of the left eyebrow of the initial face image to the other end correspond to 1, 2, 3, 4, and 5, the initial feature points at both ends can be selected as target feature points, i.e., the initial feature points corresponding to numbers 1 and 5 are selected as target feature points. Similarly, the initial feature points corresponding to numbers 6 and 10 can also be selected as target feature points.
[0075] Further, please refer to Figure 3 , Figure 3 The target region involved in the image recognition method provided by the embodiments of the present application is schematically shown in the figure, wherein if the target region is represented by the dashed box region S in the figure (b), the target region S includes the top of the head S2 of the initial face image, i.e., the top of the head region in the following embodiments, wherein S1 can be understood as the background region in the following embodiments, and S3 can be understood as the skin region in the following embodiments. Figure 2
[0076] In some embodiments, the extraction of the target feature points can be completed by the Local Binary Patterns (LBP) algorithm. The extraction of the target feature points can also be completed based on various computer vision algorithms in the Dilp tool kit in modern C++, such as a face key point detection algorithm based on a regression tree, or based on various face key point detection algorithms in the computer vision library OpenCV. The specific algorithm involved in the extraction of the target feature points can be selected according to actual conditions.
[0077] In S120, the initial face image is cut out according to the target region to obtain a first target image.
[0078] In the embodiments, the target region corresponding to the target region determined in the above embodiments can be cut out on the initial face image. Specifically, at least one of the Trimap-based algorithm, the Deep Image Matting algorithm, the Background Matting algorithm, and the Background Matting V2 algorithm can be used to complete the cutout operation of the initial face image. The first target image can be regarded as an image corresponding to the target region.
[0079] Please refer to Figure 4 , Figure 4 This is a schematic diagram of a first image processing procedure involved in image recognition provided in this application, wherein (a) is a first target image in this embodiment, and the first target image can be based on a determined target region. Figure 2 The image (b) in the image is obtained by cutting out the image.
[0080] S130, perform preset processing on the first target image to obtain the second target image.
[0081] In this embodiment, the preset processing may include at least one of cluster analysis, dilation, erosion, and flooding processes, which can process the stray hairs at the top of the head in the first target image and improve the accuracy of detecting the top of the head position.
[0082] In one possible implementation, the first target image is subjected to a preset processing to obtain a second target image, including:
[0083] The first target image is clustered according to the second preset algorithm to obtain the first intermediate image, wherein the first intermediate image includes the skin region, the hair region and the background region;
[0084] The first intermediate image is edge-detected according to the third preset algorithm to determine the edge line of the hair region in the first intermediate image;
[0085] The edge lines are sequentially subjected to dilation, erosion, and water immersion processes to obtain a second intermediate image after removing the stray hairs at the edge lines;
[0086] The second intermediate image is binarized to obtain the second target image.
[0087] This embodiment provides a detailed analysis of the pre-processing steps, primarily including clustering analysis, edge detection, dilation, erosion, and flooding processes. This process eliminates stray hairs in the first target image, improving the accuracy of head position detection. The first intermediate image is... Figure 4 Image (b) shows the images after edge detection, dilation, erosion, and flooding treatment, respectively. Figure 4 Images (c), (d), (e), and (f) in the diagram show the second target image. Figure 4 (g) diagram.
[0088] In this embodiment, the skin region, hair region, and background region of the first intermediate image can be referenced. Figure 3The second preset algorithm can implement clustering processing of the image, and can include at least one of a K-Means clustering algorithm, a hierarchical clustering algorithm, and a density clustering algorithm. Similarly, the third clustering algorithm can implement edge detection of the image, and mainly includes an edge detection model of a first order, such as a Roberts operator, a Prewitt operator, a Sobel operator, a Canny operator, or a Laplacian operator of a second order. The fourth preset algorithm used to implement the clustering processing of the image in the following embodiments can be the same as or different from the second preset algorithm, and the fourth preset algorithm will not be repeatedly introduced in the following embodiments.
[0089] Specifically, the clustering analysis can determine the regions of the first target image, the dilation and the corrosion can be performed on the white part or the highlight part in the image, that is, on the edge line of the hair region of the first intermediate image, the flood fill processing can fill the edge line of the corrosion operation, accurately remove the broken hair, and further improve the accuracy of determining the top position of the head, thereby facilitating accurate cutting of the initial face image. It should be noted that the image after the flood fill processing still contains gray scale information, and the second intermediate image after the flood fill processing is binarized in this embodiment, which can further improve the accuracy of determining the top position of the head.
[0090] In some embodiments, before performing the edge detection on the first intermediate image, the first intermediate image can be subjected to noise reduction processing to obtain a clear first intermediate image. Specifically, the first intermediate image can be filtered according to a median filter, and then the filtered first intermediate image can be subjected to edge detection, which can improve the accuracy of removing the broken hair.
[0091] In some embodiments, before performing the edge detection on the first intermediate image, the first intermediate image can be subjected to noise reduction processing to obtain a clear first intermediate image. Specifically, the first intermediate image can be filtered according to a median filter, and then the filtered first intermediate image can be subjected to edge detection, which can improve the accuracy of removing the broken hair.
[0092] In this embodiment, the second target image does not include the broken hair or includes a very small broken hair region, and the target boundary line can be determined based on the second target image, thereby avoiding the interference of the broken hair. The position of the target boundary line can be regarded as the top position of the initial face image, and this embodiment can accurately determine the top position of the head, thereby facilitating image cutting or cropping of the top position region based on the top position of the head, shortening the processing time, and improving the accuracy and efficiency of the image recognition device or the self-service photo collection equipment in cropping the ID photo.
[0093] From the above analysis, the image recognition method provided by the embodiment of the application can first detect the target feature points of the initial face image, and determine the target region according to the target feature points, wherein the target region contains the top of the initial face image. Then, the initial face image is cut out according to the target region to obtain a first target image. The first target image is then preprocessed to remove the top hair and obtain a second target image. Finally, the target dividing line is determined according to the second target image. The whole process has a short processing time, and the top position of the face image can be accurately determined to determine the cropping region, thereby significantly improving the accuracy of the self-service photo collection device in cropping the ID photo.
[0094] The above embodiment obtains the target feature points of the initial face image, and then determines the target region based on the target feature points. Considering that the process of determining the target region may face the problem of large amount of calculation, in a possible implementation manner, the target feature points of the initial face image are detected, and the target region is determined according to the target feature points, including:
[0095] Detecting initial feature points of the initial face image.
[0096] Determining target feature points based on the initial feature points, and determining the target region according to the target feature points, wherein the number of initial feature points is greater than the number of target feature points.
[0097] In this embodiment, the target feature points can be determined by screening the initial feature points, the target region can be determined based on the target feature points with a smaller number of feature points, the target region can be quickly determined, and the efficiency of determining the top position of the initial face image can be improved.
[0098] In some embodiments, two feature points AB corresponding to the corner positions of the left eye region and the right eye region can be determined according to the left eye region and the right eye region respectively. Figure 5 In some embodiments, two feature points AB corresponding to the corner positions of the left eye region and the right eye region can be determined according to the left eye region and the right eye region respectively. Figure 5 The above embodiment provides a determination diagram of the target region involved in the image recognition, wherein the line segment AB is obtained by connecting the two feature points AB, and the midpoint a of the line segment AB is calculated. The line segment L perpendicular to the line segment AB is drawn through the midpoint a, and the line segment L can be used as the facial midline of the initial face image. After determining the facial midline, the point b spaced a first preset distance such as 2 cm from the midpoint a on the line segment L is determined, and the line segment l is obtained by extending the b point to the left and right sides by a second preset distance such as 2 cm. The straight lines l1 and l2 are drawn through the two end points of the line segment l in the opposite direction of the line segment L. The target region is composed of the line segment l, the straight lines l1 and l2, and the top edge of the initial face image.
[0099] The point b is away from the feature points of the nose region, and the corner positions of the left eye region and the right eye region can be understood as a feature point of the left eye region away from the nose region and a feature point of the right eye region away from the nose region.
[0100] In some embodiments, the four feature points ABCD corresponding to the corner positions of the eyes can be determined according to the left and right eye regions respectively to determine the facial midline in the face image, wherein the CD points can be understood as two feature points of the feature points of the left and right eyes close to the nose region, the AC point is located on the right eye side, the BD point is located on the left eye side, the midpoint of the line segment AC is obtained by connecting the AC point, the midpoint of the line segment BD is obtained by connecting the BD point, the midpoint of the two line segments is obtained respectively, and the line segment l3 is obtained by connecting the two midpoints, and the line segment l3 is perpendicular to the line segment l3 passing through the midpoint of the line segment l3 to obtain the facial midline of the initial face image. Then the target region can be determined in the same way as in the above-mentioned embodiments. In an ideal case, the l3 in the present embodiment and the L in the above-mentioned embodiments coincide. In order to facilitate the display, the line segments mentioned in the present embodiment and the above-mentioned embodiments are all represented by dashed lines. Obviously, the present embodiment can improve the accuracy of determining the target region. Figure 3
[0101] Considering that the obtained part of the initial face image may be caused by different shooting angles or the rotation of the head of the person being photographed, the facial part is offset, and the accuracy of the facial midline determined according to the AB feature points or the ABCD feature points in the above-mentioned embodiments is not high. In a possible implementation, the determining the target feature point based on the initial feature point comprises:
[0102] performing face pose estimation on the initial face image according to a first preset algorithm to obtain angle information of the face orientation;
[0103] determining the target feature point according to the angle information and the initial feature point.
[0104] Specifically, the first preset algorithm can realize face pose estimation on the face image, and can include at least one of a landmark-based algorithm and a landmark-free algorithm.
[0105] Still taking the above-mentioned embodiments as an example, if the angle information of the face orientation indicates that the face is offset to the left side, the midline determined according to the BA feature points corresponding to the left and right eyes will be close to the right eye side, i.e. the side where the A feature point is located. In this case, the determining the target feature point according to the angle information and the initial feature point can include: connecting the AB two feature points to obtain a line segment AB, the feature point A on the right eye side remains unchanged, the feature point B on the left eye side is extended by a preset distance away from the feature point A along the line segment AB to obtain a point B', the point B' can be used as a new feature point, and the midline is determined again according to the feature points AB'. The accuracy of determining the midline can be improved, and the process of determining the target region according to the newly determined midline can refer to the above-mentioned embodiments, which will not be described here.
[0106] The extended preset distance can be determined according to the angle information of the face orientation, and a conversion table including the angle information and the preset distance to be extended can be obtained through pre-testing. For example, when the angle information is 1°, the corresponding preset distance is 0.2 cm, and when the angle information is 5°, the corresponding preset distance is 0.5 cm.
[0107] Please refer to Figure 6 , Figure 6 The second image processing process involved in the image recognition provided in the present application is shown in the figure, wherein (h) represents a third intermediate image, and (i) represents a fourth intermediate image. In a possible implementation, the first target image includes a skin region, a hair region, and a background region. After the initial face image is cut out according to the target region to obtain the first target image, the method further includes:
[0108] calculating a color value of a target skin color and modifying the color value of the background region of the first target image to the color value of the target skin color to obtain a third intermediate image, wherein the color value of the target skin color is a skin color value of the skin region of the first target image;
[0109] performing clustering analysis on the third intermediate image according to a fourth preset algorithm to obtain a fourth intermediate image;
[0110] determining a first boundary line according to the fourth intermediate image;
[0111] determining a target boundary line according to the second target image, including:
[0112] determining a second boundary line according to the second target image;
[0113] calculating a median line of the first boundary line and the second boundary line, and taking the median line as the target boundary line.
[0114] In the present embodiment, the first target image includes a background region, a hair region, and a skin region. The three regions of the first target image can also refer to the three regions S1, S2, and S3 in Figure 2 . The color value of the target skin color is modified to the color value of the background region of the first target image, which can be understood as color filling of the background region of the first target image. Considering that the color to be filled is the skin color, this process can also be understood as skin color filling. After the skin color filling, the original background region becomes a skin region. After clustering of the third intermediate image, the new skin region S1' and the hair region S2 are obtained. The color value of the target skin color is the skin color value of the skin region of the first target image, or the skin color value of the nose bridge region S4 indicated by the rectangular frame in Figure 7 . The color value of the target skin color can be the skin color value of the nose bridge region S4 in the initial face image. Figure 7An initial face image nose bridge region schematic diagram involved in an image recognition method provided by the embodiment of the application, it should be noted that the color value of the target skin color is the color value mean of the color value of the skin color corresponding to the skin region of the first target image or the color value of the skin color of the initial face image nose bridge region, taking the color value mean of any one of the two regions close to the color value of the skin region of the first target image facilitates subsequent clustering analysis of the third intermediate image.
[0115] Wherein, the color value of the background region of the third intermediate image is modified, which can be understood as obtained by color filling the first target image, after clustering analysis, the fourth intermediate image only contains two types of information, i.e. skin region and hair region, and the first dividing line can be accurately determined according to the fourth intermediate image.
[0116] Similarly, the second dividing line can be accurately determined according to the second target image, and the median line of the first dividing line and the second dividing line can be taken as the target dividing line, i.e. representing the head top position, which can improve the accuracy of determining the head top position.
[0117] It should be noted that after the head top position is determined, the image recognition device or the self-service photo collection equipment can cut or crop the top end of the initial face image according to the head top position, not along the target dividing line, and in the embodiment, the accurate determination of the head top position is realized, and as for completing the cutting or cropping, the cutting or cropping can be performed according to the actual need of leaving a white area and the head top position, for example, if 1cm needs to be left above the head top position, a straight line parallel to the target dividing line is determined at a position 1cm away from the target dividing line, and the image recognition device or the self-service photo collection equipment can cut or crop along the straight line parallel to the target dividing line.
[0118] Optionally, the second target image and the fourth intermediate image both include the hair region and the background region, the first dividing line is determined according to the fourth intermediate image, and the method comprises:
[0119] Starting from the background region of the fourth intermediate image to the hair region of the fourth intermediate image, and calculating a target ratio of a first pixel point and a second pixel point in each row of pixel points, wherein the first pixel point is a pixel point of the background region of the fourth intermediate image, and the second pixel point is a pixel point of the hair region of the fourth intermediate image;
[0120] Taking a row of pixel points corresponding to the first preset ratio as the first dividing line;
[0121] The second dividing line is determined according to the second target image, and the method comprises:
[0122] traversing from the background region of the second target image to the hair region of the second target image, and calculating a target ratio of a third pixel point and a fourth pixel point in each row of pixel points, wherein the third pixel point is a pixel point in the background region of the second target image, and the fourth pixel point is a pixel point in the hair region of the second target image;
[0123] taking a row of pixel points corresponding to a target ratio that is first greater than or equal to a second preset ratio as a second boundary line.
[0124] In the embodiment, the target ratio is actually a ratio of the number of the first pixel points to the number of the second pixel points, and the pixel value of the pixel point is 0, which indicates that the pixel point is black. When traversing from the background region to the hair region of the fourth intermediate image, the hair will gradually appear, and in each row of pixel points, the number of black pixel points will be more and more. If the first pixel point is a black pixel point, and the second pixel point is a white pixel point, and the first preset ratio is 3 / 4, it can be determined that the row of pixel points in which the ratio of the number of black pixel points to the number of white pixel points is first greater than or equal to 3 / 4 is the first boundary line. The second boundary line is determined in the same way. The first preset ratio and the second preset ratio can be the same or different, and the first preset ratio and the second preset ratio can be preset according to whether the first pixel point, the third pixel point, is black or white, and whether the second pixel point, the fourth pixel point, is black or white.
[0125] It should be noted that, in the process of determining the first boundary line, if it is detected that the pixel point is not black or white, that is, there is a gray color such as a pixel value of 128 or other non-0 non-255, a binarization operation is performed on the fourth intermediate image, and the first boundary line is determined based on the fourth intermediate image after binarization in the determination manner in the above embodiment.
[0126] Considering that there are situations where the hair color and the skin color are close, it is difficult to locate the top-of-the-head position of the initial face portrait. In one possible implementation, after the fourth intermediate image is obtained by clustering analysis on the third intermediate image according to the fourth preset algorithm, the method further includes:
[0127] obtaining an HSV image corresponding to the third intermediate image;
[0128] calculating a color value of a target hair color according to the HSV image and the second target image, wherein the color value of the target hair color is a color value of the hair region of the first target image;
[0129] detecting whether a difference between the color value of the target hair color and a color value of a target skin color is within a preset numerical range;
[0130] In a case where the difference between the color value of the target hair color and the color value of the target skin color is within a preset numerical range, the first target image is subjected to cluster analysis according to a fourth preset algorithm to obtain a third target image.
[0131] The first boundary line is determined according to the third target image.
[0132] In the embodiment, the color value of the target hair color can be calculated through the HSV image of the third intermediate image and the second target image, and it is further determined whether the color value of the target hair color is close to the color value of the target skin color, that is, whether the difference between the color values of the two is within a preset numerical range. If the difference between the color values of the two is within the preset numerical range, it indicates that the target hair color and the target skin color are the same or close. In this case, the first boundary line cannot be determined according to the fourth intermediate image obtained through cluster analysis. The numerical value involved in the calculation of the corresponding color value can refer to the HSV color range table as shown in Table 1.
[0133] Table 1
[0134]
[0135] Specifically, the first target image includes three regions of a background region, a hair region and a skin color region. The color value of the background region of the first target image in the above embodiment can not be modified, but the first target image can be directly subjected to cluster analysis according to the fourth preset algorithm. The hair region and the skin color region are classified into the same class and distinguished from the background region. The first boundary line can be determined according to the third target image obtained after cluster analysis. The process of determining the first boundary line can refer to the above embodiment, which will not be described here.
[0136] In some embodiments, if the difference between the color value of the target hair color and the color value of the target skin color is within a preset numerical range, the color value of the target skin color can be changed, such as taking the average color value of the left cheek region or the average color value of the right cheek region of the initial face image as the color value of the target skin color. Then, the new color value of the target skin color is compared with the color value of the target skin color. If the difference between the color values of the two is still within the preset numerical range, the operation of subjecting the first target image to cluster analysis according to the fourth preset algorithm in the above embodiment can be performed. If the difference between the color values of the two is not within the preset numerical range, it indicates that the new skin color is not close to the target hair color. The newly obtained third intermediate image can be subjected to cluster analysis to obtain a new fourth intermediate image, and the first boundary line is determined according to the new fourth intermediate image.
[0137] In summary, the image recognition method provided in the embodiments of the present application first detects target feature points of an initial face image, and determines a target region according to the target feature points, wherein the target region contains the top of the initial face image. Then, the initial face image is cut out according to the target region to obtain a first target image. The first target image is then preprocessed to remove the hair on the top of the head, and a second target image is obtained. In the case where the hair color and skin color are close, the first target image is re-clustered and analyzed, and a target boundary line is determined according to the second target image. The entire process has a short processing time, and the top position of the face image can be accurately determined to further determine the cropping region, thereby significantly improving the accuracy of the self-service photo collection device in cropping the ID photo.
[0138] Corresponding to the method embodiments, the present application also provides an image recognition device 800, please see Figure 8 , Figure 8 The function module schematic diagram of the image recognition device provided in the present application is shown in the following table.
[0139] The detection module 810 is configured to detect target feature points of an initial face image, and determine a target region according to the target feature points, wherein the target region contains the top of the initial face image.
[0140] The cut-out module 820 is configured to cut out the initial face image according to the target region to obtain a first target image.
[0141] The first processing module 830 is configured to pre-process the first target image to obtain a second target image.
[0142] The second processing module 840 is configured to determine a target boundary line according to the second target image, wherein the position of the target boundary line is the position of the top of the initial face image, and the target boundary line is used to indicate the cropping of the initial face image.
[0143] The image recognition device provided in the present application first detects target feature points of an initial face image by the detection module, and determines a target region according to the target feature points, wherein the target region contains the top of the initial face image. Then, the initial face image is cut out according to the target region by the cut-out module to obtain a first target image. The first target image is preprocessed by the first processing module to remove the hair on the top of the head, and a second target image is obtained. Finally, a target boundary line is determined according to the second target image by the second processing module. The entire process has a short processing time, and the top position of the face image can be accurately determined to further determine the cropping region, thereby significantly improving the accuracy of the self-service photo collection device in cropping the ID photo.
[0144] The present application also provides a computer device, please seeFigure 9 , Figure 9 A computer device internal structure diagram is provided for the embodiments of the present application. The computer device includes a processor, a memory and a network interface connected through a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system, and can also store a computer program. When the computer program is executed by the processor, the processor can implement the image recognition method applied to the computer device in the above embodiments. The computer program can also be stored in the internal memory. When the computer program is executed by the processor, the processor can execute the image recognition method. Those skilled in the art can understand that the structure shown in the above embodiments is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement. Figure 9
[0145] The embodiments of the present application also disclose a computer readable storage medium, which stores a computer program. When the computer program is executed by a processor, the image recognition method in the method embodiments is implemented.
[0146] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware. The program can be stored in a non-volatile computer readable storage medium. When the program is executed, the processes of the above-mentioned embodiments can be included. Any reference to the memory, storage, database or other medium used in the embodiments provided by the present application can include non-volatile and / or volatile memory. The non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. The volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM) and memory bus dynamic RAM (RDRAM) and the like.
[0147] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described, however, any combination of the technical features is considered to be within the scope of the present specification.
Claims
1. An image recognition method characterized by, The method comprises: detecting a target feature point of an initial human face image, and determining a target region according to the target feature point, wherein the target region contains a top of the initial human face image; masking the initial human face image according to the target region to obtain a first target image; performing a preset processing on the first target image to obtain a second target image; determining a target boundary line according to the second target image, wherein the position of the target boundary line is the position of the top of the initial human face image, and the target boundary line is used to indicate that the initial human face image is cropped; wherein the first target image comprises a skin region, a hair region and a background region, the second target image comprises a hair region and a background region, and after the first target image is obtained by masking the initial human face image according to the target region, the method further comprises: calculating a color value of a target skin color and modifying the color value of the background region of the first target image to the color value of the target skin color to obtain a third intermediate image, wherein the color value of the target skin color is the skin color value of the skin region of the first target image; performing clustering analysis on the third intermediate image according to a fourth preset algorithm to obtain a fourth intermediate image; determining a first boundary line according to the fourth intermediate image; wherein the determining of the target boundary line according to the second target image comprises: determining a second boundary line according to the second target image; calculating a median line of the first boundary line and the second boundary line, and taking the median line as the target boundary line.
2. The image recognition method of claim 1, wherein, The detecting of the target feature point of the initial human face image and the determining of the target region according to the target feature point comprise: detecting an initial feature point of the initial human face image; determining the target feature point based on the initial feature point, and determining the target region according to the target feature point, wherein the number of the initial feature points is greater than the number of the target feature points.
3. The image recognition method of claim 2, wherein, The determining of the target feature point based on the initial feature point comprises: performing human face posture estimation on the initial human face image according to a first preset algorithm to obtain angle information of a human face orientation; determining the target feature point according to the angle information and the initial feature point.
4. The image recognition method of claim 1, wherein, The performing of the preset processing on the first target image to obtain the second target image comprises: performing clustering analysis on the first target image according to a second preset algorithm to obtain a first intermediate image, wherein the first intermediate image comprises a skin region, a hair region and a background region; performing edge detection on the first intermediate image according to a third preset algorithm to determine an edge line of the hair region of the first intermediate image; performing inflation, corrosion and flood processing on the edge line in sequence to obtain a second intermediate image in which the broken hair at the edge line is eliminated; performing binaryzation processing on the second intermediate image to obtain the second target image.
5. The image recognition method of claim 1, wherein, The fourth intermediate image comprises a hair region and a background region, and the determining of the first boundary line according to the fourth intermediate image comprises: Traverse from a background region of the fourth intermediate image to a hair region of the fourth intermediate image, and calculate a target ratio of a first pixel point and a second pixel point in each row of pixel points, where the first pixel point is a pixel point of the background region of the fourth intermediate image, and the second pixel point is a pixel point of the hair region of the fourth intermediate image; A row of pixel points corresponding to a target ratio that is first greater than or equal to a first preset ratio is taken as the first boundary line; The second target image is used to determine the second boundary line, including: Traverse from a background region of the second target image to a hair region of the second target image, and calculate a target ratio of a third pixel point and a fourth pixel point in each row of pixel points, where the third pixel point is a pixel point of the background region of the second target image, and the fourth pixel point is a pixel point of the hair region of the second target image; A row of pixel points corresponding to a target ratio that is first greater than or equal to a second preset ratio is taken as the second boundary line.
6. The image recognition method of claim 1, wherein, After the third intermediate image is obtained by performing the clustering analysis on the third intermediate image according to the fourth preset algorithm, the method further includes: An HSV image corresponding to the third intermediate image is obtained; A color value of a target hair color is calculated according to the HSV image and the second target image, where the color value of the target hair color is a color value of the hair region of the first target image; It is detected whether a difference between the color value of the target hair color and a color value of a target skin color is within a preset numerical range; In a case where the difference between the color value of the target hair color and the color value of the target skin color is within the preset numerical range, a third target image is obtained by performing a clustering analysis on the first target image according to the fourth preset algorithm; The first boundary line is determined according to the third target image.
7. An image recognition apparatus characterized by comprising: The device includes: A detection module is configured to detect a target feature point of an initial face image and determine a target region according to the target feature point, where the target region contains a top of the initial face image; An image matting module is configured to perform image matting on the initial face image according to the target region to obtain a first target image; A first processing module is configured to perform a preset processing on the first target image to obtain a second target image; A second processing module is configured to determine a target boundary line according to the second target image, where a position of the target boundary line is a position of the top of the initial face image, and the target boundary line is used to indicate that the initial face image is cropped; The first target image includes a skin region, a hair region and a background region, and the second target image includes the hair region and the background region; The image recognition device is further configured to calculate a color value of a target skin color and modify a color value of the background region of the first target image to the color value of the target skin color to obtain a third intermediate image, where the color value of the target skin color is a skin color value of the skin region of the first target image; A fourth intermediate image is obtained by performing a clustering analysis on the third intermediate image according to a fourth preset algorithm. determine a first boundary line according to the fourth intermediate image; the second processing module is further configured to determine a second boundary line according to the second target image; a median line of the first boundary line and the second boundary line is calculated, and the median line is taken as the target boundary line.
8. A computer device, comprising: The computer device comprises a memory and a processor, and the memory stores a computer program, which, when executed by the processor, implements the image recognition method in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, which, when executed by one or more processors, implements the image recognition method in any one of claims 1-6.
Citation Information
Patent Citations
Certificate image cutting method and system
CN102592260A
Method and tool for assisting operator to make standard identity card photo
CN110288531A
Identification photo generation and detection method and system based on intelligent three-dimensional portrait acquisition
CN115620364A