Living face detection method and device
By training a first-level detection model that can perform face detection and live body classification at the same time, the inefficiency problem caused by the separation of face detection and live body detection tasks in the prior art is solved, and a faster and more efficient live face detection is achieved. .
Patent Information
- Application Number
- CN202010856310.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-24
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2040-08-24
AI Technical Summary
Existing live face detection technology usually separates face detection tasks and live body detection tasks, resulting in an increase in detection time and reducing detection efficiency.
By training a first-level detection model, the classification of living and non-living faces is achieved while detecting the face area. The model is trained based on the live face area image in the positive sample, the non-living face area image, and the background area image in the negative sample.
While detecting the face area, the classification of living faces and non-living faces is achieved, reducing the time for living face detection and improving the detection efficiency of living face detection.
Smart Images

Figure CN114092986B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and device for detecting a living human face. Background Art
[0002] Facial recognition technology is often used in application scenarios that require user identity verification, such as mobile phone face unlocking, mobile phone face payment, and face door opening.
[0003] In actual applications, many face recognition technologies cannot determine whether the input face image is the live face image corresponding to the user, which leads to security risks when the user performs identity authentication. For example, using the user's photo or the user's image in the video can also pass the identity authentication. Therefore, in order to improve the security of face recognition, people have proposed live face detection technology. On the basis of the original face recognition technology, it can distinguish whether the input face image is a live face image, so as to defend against attacks based on non-live face images such as user photos and videos, and improve the security of face recognition technology. However, it has been found in practice that the existing live face detection technology usually separates the face detection task and the liveness detection task, which will increase the time of live face detection and reduce the detection efficiency of live face detection. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and device for detecting living faces, which can classify living faces and non-living faces while detecting face areas, thereby reducing the time of living face detection and improving the detection efficiency of living face detection.
[0005] In order to solve the above technical problems, the first aspect of the present invention discloses a method for detecting a living face, the method comprising:
[0006] After determining positive samples consisting of live face area images and non-live face area images and negative samples consisting of background area images, training a predetermined primary detection model based on face bounding boxes and classification labels corresponding to all live face area images in the positive samples, face bounding boxes and classification labels corresponding to all non-live face area images in the positive samples, and background bounding boxes and classification labels corresponding to all background area images in the negative samples to obtain a trained primary detection model;
[0007] The first image to be detected is input into the trained first-level detection model for analysis to obtain a first-level detection result corresponding to the first image to be detected, wherein the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate that the image in the first face bounding box is a living face area image or a non-living face area image.
[0008] As an optional implementation, in the first aspect of the present invention, after the first image to be detected is input into the trained primary detection model for analysis and the primary detection result corresponding to the first image to be detected is obtained, the method further includes:
[0009] According to the first-level detection result, all uncertain face bounding boxes are selected from all the first face bounding boxes in the first face bounding box set, and the image selected by each of the uncertain face bounding boxes in all the uncertain face bounding boxes is an image of an area of a living face that is uncertain whether it is an image;
[0010] Generating a second image to be detected from the first image to be detected according to all the uncertain face boundary boxes, wherein the second image to be detected is an image in the first image to be detected in which it is uncertain whether it is an image of a living face region;
[0011] Inputting the second image to be detected into a predetermined secondary detection model for analysis, obtaining a secondary detection result corresponding to the second image to be detected, wherein the secondary detection result at least includes: a second classification label corresponding to the second image to be detected, wherein the second classification label is used to indicate whether the second image to be detected is a living face region image or a non-living face region image;
[0012] A final detection result corresponding to the first image to be detected is determined according to the first-level detection result and the second-level detection result, and the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image.
[0013] As an optional implementation, in the first aspect of the present invention, the first-level detection result further includes a first confidence value corresponding to each of the first classification labels, and the first confidence value corresponding to each of the first classification labels is a numerical value used to indicate the accuracy of the first classification label;
[0014] And, selecting all uncertain face bounding boxes from all the first face bounding boxes in the first face bounding box set according to the first level detection result includes:
[0015] Selecting all to-be-determined face bounding boxes whose first confidence values are greater than or equal to a confidence threshold from among all the first face bounding boxes in the first face bounding box set;
[0016] Selecting any one first target face bounding box and any one second target face bounding box from all the face bounding boxes to be determined, wherein the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face region image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face region image;
[0017] Calculating an overlap ratio between the first target face bounding box and the second target face bounding box, and determining whether the overlap ratio is greater than or equal to an overlap ratio threshold;
[0018] If the overlap rate is greater than or equal to the overlap rate threshold, an uncertain face bounding box is determined according to the first target face bounding box and the second target face bounding box.
[0019] As an optional implementation manner, in the first aspect of the present invention, determining the uncertain face bounding box according to the first target face bounding box and the second target face bounding box includes:
[0020] Determine an overlapping face bounding box according to the first target face bounding box and the second target face bounding box, wherein the overlapping face bounding box is a face bounding box corresponding to an overlapping portion of a living face image region corresponding to the first target face bounding box and a non-living face image region corresponding to the second target face bounding box;
[0021] Calculating a first ratio of the overlapping face bounding box in the first target face bounding box and a second ratio of the overlapping face bounding box in the second target face bounding box, and determining whether the first ratio is greater than or equal to the second ratio;
[0022] If the first proportion is greater than or equal to the second proportion, determining the first target face bounding box as an uncertain face bounding box;
[0023] If the first proportion is not greater than or equal to the second proportion, the second target face bounding box is determined as an uncertain face bounding box.
[0024] As an optional implementation, in the first aspect of the present invention, after determining the uncertain face bounding box according to the first target face bounding box and the second target face bounding box, the method further includes:
[0025] The first face bounding box whose first confidence value is not greater than or equal to the confidence threshold is selected from all the first face bounding boxes, and the selected first face bounding box is added to all the uncertain face bounding boxes.
[0026] As an optional implementation, in the first aspect of the present invention, the first-level detection result further includes: facial key points corresponding to each of the first face bounding boxes, the facial key points being key points used to perform an alignment operation on a living face area image or a non-living face area image in the first face bounding box;
[0027] And, generating a second image to be detected from the first image to be detected according to all the uncertain face bounding boxes includes:
[0028] Extracting a target face region image corresponding to each of the uncertain face boundary boxes from the first image to be detected;
[0029] According to the facial key points corresponding to each of the uncertain face bounding boxes, the target face area image corresponding to each of the uncertain face bounding boxes is aligned with a preset standard face image to obtain a second to-be-detected image corresponding to each of the uncertain face bounding boxes.
[0030] As an optional implementation, in the first aspect of the present invention, the secondary detection result further includes a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a numerical value used to indicate the accuracy of the second classification label;
[0031] And, determining a final detection result corresponding to the first to-be-detected image according to the first-level detection result and the second-level detection result includes:
[0032] Determining whether the first classification label and the second classification label corresponding to the first classification label are the same;
[0033] If the first classification label and the second classification label corresponding to the first classification label are different, determining whether a confidence value difference is greater than a difference threshold, the confidence value difference being equal to a second confidence value of the second classification label corresponding to the first classification label minus a first confidence value of the first classification label;
[0034] If the confidence value difference is greater than the difference threshold, taking the first face bounding box corresponding to the first classification label as the second face bounding box in the final detection result, and taking the second classification label corresponding to the first classification label as the third classification label corresponding to the second face bounding box;
[0035] If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
[0036] A second aspect of the present invention discloses a living face detection device, the device comprising:
[0037] A training module is used for, after determining positive samples consisting of live face region images and non-live face region images and negative samples consisting of background region images, training a predetermined primary detection model based on face bounding boxes and classification labels corresponding to all live face region images in the positive samples, face bounding boxes and classification labels corresponding to all non-live face region images in the positive samples, and background bounding boxes and classification labels corresponding to all background region images in the negative samples, to obtain a trained primary detection model;
[0038] An analysis module is used to input a first image to be detected into the trained first-level detection model for analysis to obtain a first-level detection result corresponding to the first image to be detected, wherein the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate whether the image in the first face bounding box is a living face area image or a non-living face area image.
[0039] As an optional implementation, in the second aspect of the present invention, the device further includes:
[0040] a selection module, configured to, after the analysis module inputs the first image to be detected into the trained first-level detection model for analysis and obtains the first-level detection result corresponding to the first image to be detected, select all uncertain face bounding boxes from all the first face bounding boxes in the first face bounding box set according to the first-level detection result, wherein the image selected by each of the uncertain face bounding boxes is an image whose uncertainty is whether it is an image of a living face area;
[0041] A generating module, configured to generate a second image to be detected from the first image to be detected according to all the uncertain face boundary frames, wherein the second image to be detected is an image of the first image to be detected in which it is uncertain whether it is an image of a living face region;
[0042] Furthermore, the analysis module is further used to input the second image to be detected into a predetermined secondary detection model for analysis to obtain a secondary detection result corresponding to the second image to be detected, wherein the secondary detection result at least includes: a second classification label corresponding to the second image to be detected, wherein the second classification label is used to indicate that the second image to be detected is a living face area image or a non-living face area image;
[0043] And, the device also includes:
[0044] A determination module is used to determine a final detection result corresponding to the first image to be detected based on the first-level detection result and the second-level detection result, wherein the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image.
[0045] As an optional implementation, in the second aspect of the present invention, the first-level detection result also includes a first confidence value corresponding to each of the first classification labels, and the first confidence value corresponding to each of the first classification labels is a numerical value used to indicate the accuracy of the first classification label;
[0046] And, the selection module includes:
[0047] a selection submodule, configured to select all to-be-determined face bounding boxes whose first confidence value is greater than or equal to a confidence threshold from all the first face bounding boxes in the first face bounding box set;
[0048] And, the selection submodule is further used to select any one first target face bounding box and any one second target face bounding box from all the face bounding boxes to be determined, the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face area image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face area image;
[0049] And, the selection module further includes:
[0050] a calculation submodule, configured to calculate an overlap ratio between the first target face bounding box and the second target face bounding box, and determine whether the overlap ratio is greater than or equal to an overlap ratio threshold;
[0051] A determination submodule is used to determine an uncertain face bounding box according to the first target face bounding box and the second target face bounding box after the calculation submodule determines that the overlap rate is greater than or equal to the overlap rate threshold.
[0052] As an optional implementation, in the second aspect of the present invention, the specific manner in which the determining submodule determines the uncertain face bounding box according to the first target face bounding box and the second target face bounding box is:
[0053] Determine an overlapping face bounding box according to the first target face bounding box and the second target face bounding box, wherein the overlapping face bounding box is a face bounding box corresponding to an overlapping portion of a living face image region corresponding to the first target face bounding box and a non-living face image region corresponding to the second target face bounding box;
[0054] Calculating a first ratio of the overlapping face bounding box in the first target face bounding box and a second ratio of the overlapping face bounding box in the second target face bounding box, and determining whether the first ratio is greater than or equal to the second ratio;
[0055] If the first proportion is greater than or equal to the second proportion, determining the first target face bounding box as an uncertain face bounding box;
[0056] If the first proportion is not greater than or equal to the second proportion, the second target face bounding box is determined as an uncertain face bounding box.
[0057] As an optional embodiment, in the second aspect of the present invention, the selection submodule is also used to select the first face bounding box whose first confidence value is not greater than or equal to the confidence threshold from all the first face bounding boxes after the determination submodule determines the uncertain face bounding box based on the first target face bounding box and the second target face bounding box, and add the selected first face bounding box to all the uncertain face bounding boxes.
[0058] As an optional implementation, in the second aspect of the present invention, the first-level detection result further includes: facial key points corresponding to each of the first face bounding boxes, the facial key points being key points used to perform an alignment operation on a living face area image or a non-living face area image in the first face bounding box;
[0059] And, the specific manner in which the generating module generates the second image to be detected from the first image to be detected according to all the uncertain face boundary boxes is:
[0060] Extracting a target face region image corresponding to each of the uncertain face boundary boxes from the first image to be detected;
[0061] According to the facial key points corresponding to each of the uncertain face bounding boxes, the target face area image corresponding to each of the uncertain face bounding boxes is aligned with a preset standard face image to obtain a second to-be-detected image corresponding to each of the uncertain face bounding boxes.
[0062] As an optional implementation, in the second aspect of the present invention, the secondary detection result further includes a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a numerical value used to indicate the accuracy of the second classification label;
[0063] And, the specific manner in which the determination module determines the final detection result corresponding to the first to-be-detected image according to the first-level detection result and the second-level detection result is:
[0064] Determining whether the first classification label and the second classification label corresponding to the first classification label are the same;
[0065] If the first classification label and the second classification label corresponding to the first classification label are different, determining whether a confidence value difference is greater than a difference threshold, the confidence value difference being equal to a second confidence value of the second classification label corresponding to the first classification label minus a first confidence value of the first classification label;
[0066] If the confidence value difference is greater than the difference threshold, taking the first face bounding box corresponding to the first classification label as the second face bounding box in the final detection result, and taking the second classification label corresponding to the first classification label as the third classification label corresponding to the second face bounding box;
[0067] If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
[0068] The third aspect of the present invention discloses another living face detection device, the device comprising:
[0069] A memory storing executable program code;
[0070] a processor coupled to the memory;
[0071] The processor calls the executable program code stored in the memory to execute the method for detecting living faces disclosed in the first aspect of the present invention.
[0072] A fourth aspect of the present invention discloses a computer storage medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method for detecting living faces disclosed in the first aspect of the present invention.
[0073] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0074] In the embodiment of the present invention, by using the pre-determined positive samples and negative samples to train the first-level detection model, and then inputting the first image to be detected into the trained first-level detection model, a first-level detection result including a first face bounding box set and a first classification label is obtained, so that the detection task of the face area and the classification task of the face area can be completed simultaneously in the first-level detection model. It can be seen that the implementation of the present invention can realize the classification of live faces and non-live faces while detecting the face area, thereby reducing the time of live face detection and improving the detection efficiency of live faces. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0076] Figure 1 It is a flow chart of a method for detecting a living face disclosed in an embodiment of the present invention;
[0077] Figure 2 It is a flowchart of another method for detecting living faces disclosed in an embodiment of the present invention;
[0078] Figure 3 It is a structural schematic diagram of a living face detection device disclosed in an embodiment of the present invention;
[0079] Figure 4 It is a structural schematic diagram of another living face detection device disclosed in an embodiment of the present invention;
[0080] Figure 5 It is a structural schematic diagram of another living face detection device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0081] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme 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 only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0082] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or equipment that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or equipment.
[0083] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0084] The present invention discloses a method and device for detecting a live face, which uses a pre-determined positive sample and a negative sample to train a primary detection model, and then inputs a first image to be detected into the trained primary detection model to obtain a primary detection result including a first face bounding box set and a first classification label, thereby being able to simultaneously complete the detection task of the face region and the classification task of the face region in the primary detection model, thereby being able to reduce the time of live face detection and improve the detection efficiency of live faces. The following are detailed descriptions respectively.
[0085] Embodiment 1
[0086] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a method for detecting a living face disclosed in an embodiment of the present invention. Figure 1 As shown, the method for detecting living faces may include the following operations:
[0087] 101. After determining the positive samples consisting of live face region images and non-live face region images and the negative samples consisting of background region images, a pre-determined primary detection model is trained based on the face bounding boxes and classification labels corresponding to all live face region images in the positive samples, the face bounding boxes and classification labels corresponding to all non-live face region images in the positive samples, and the background bounding boxes and classification labels corresponding to all background region images in the negative samples to obtain a trained primary detection model. After executing step 101, step 102 may be triggered.
[0088] In the above step 101, since the main task of the first-level detection model is to extract the live face region image and the non-live face region image in the first image to be detected and the first classification label corresponding to each region image, the first-level detection model is trained using positive samples including the face bounding box and classification label corresponding to the live face region image, the face bounding box and classification label corresponding to the non-live face region image, and negative samples including the background bounding box and classification label corresponding to the background region image, so that the first-level detection model can obtain the ability to extract the live face region image and the non-live face region image in the first image to be detected and the first classification label corresponding to each region image. Here, the classification label can be set to different values to represent different classification results. For example, the value of the classification label is 1, which means that the classification result is a live face region image, the value of the classification label is 2, which means that the classification result is a non-live face region image, and the value of the classification label is 3, which means that the classification result is a background region image. The face bounding box can be represented by the center pixel coordinate value of the bounding box and the size of the bounding box (length pixel value and width pixel value).
[0089] Optionally, a difficult sample mining strategy can be adopted for positive samples and negative samples so that the ratio of positive and negative samples is maintained at 1:3. Further optionally, before training the predetermined first-level detection model, any one or more operations such as image expansion, image cropping and image rotation can be performed on the positive samples and negative samples to increase the number of positive and negative samples. Further optionally, the predetermined first-level detection model can be a neural network model such as MTCNN, SSD, etc., wherein the first-level detection model is preferably an SSD neural network model. Further optionally, the first-level detection model can be a neural network model that uses an image of a preset pixel size as a model input, uses the output of a specified layer as a predicted output, and has an initial learning rate of a preset learning rate. For example, the first-level detection model can be a neural network model with a preset pixel size of 300*300, a specified layer as the output of conv6_2 (or conv7_2 or conv8_2 or conv9_2), and an initial learning rate of 10^(-2). When the first-level detection model is an SSD neural network model, in the SSD neural network model, the size of the face bounding box can be calculated by the following formula:
[0090]
[0091] Among them, i∈[2,max-1], max represents the number of prediction layers in the SSD neural network model, sc min , sc i , sc max They represent the sizes of the prior boxes of the lowest prediction layer, the i-th prediction layer, and the highest prediction layer in the SSD neural network model respectively.
[0092] 102. Input the first image to be detected into the trained primary detection model for analysis to obtain a primary detection result corresponding to the first image to be detected.
[0093] In the above step 102, the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to frame a live face area image or a non-live face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate that the image in the first face bounding box is a live face area image or a non-live face area image. The first image to be detected can be an image captured by a camera, or an image extracted from a specified storage address (for example, a specified disk logical address, a specified server, etc.). The detection result of the first image to be detected by the trained first-level detection model can be as follows: For example, the first image to be detected contains a live face, that is, the first-level detection result obtained after the first-level detection model analyzes the first image to be detected includes a first face bounding box and a first classification label, wherein the first face bounding box will frame the image portion of the live face in the first image to be detected, and the value of the first classification label is 1, which means that the classification result is a live face.
[0094] In an optional embodiment, the first image to be detected may be a plurality of frame images extracted from a video;
[0095] And, after inputting the first image to be detected into the trained primary detection model for analysis and obtaining the primary detection result corresponding to the first image to be detected, the method for detecting living faces may further include:
[0096] Among the first classification labels corresponding to each frame image in all the frame images, counting a first number of first classification labels used to indicate that the image in the first face boundary frame is a living face region image;
[0097] Among the first classification labels corresponding to each frame image in all the frame images, counting the second number of the first classification labels used to indicate that the image in the first face boundary frame is a non-living face region image;
[0098] Determine whether the first quantity is greater than or equal to the second quantity;
[0099] If it is determined that the first number is greater than or equal to the second number, determining that the human faces in the video corresponding to the plurality of frame images are living human faces;
[0100] If it is determined that the first number is not greater than or equal to the second number, it is determined that the human faces in the videos corresponding to the multiple frame images are not living human faces.
[0101] For example, there are ten frame images in total. After the first-level detection model is used to analyze six frame images, six first classification labels are obtained to indicate that the image in the first face boundary frame is a live face region image. After the first-level detection model is used to analyze four frame images, four first classification labels are obtained to indicate that the image in the first face boundary frame is a non-live face region image. Among them, the first classification labels used to indicate live face region images account for the highest proportion, so it is determined that the face in the video is a live face.
[0102] It can be seen that by implementing this optional embodiment, it is possible to determine whether the face in the video corresponding to the frame image is a live face based on the detection results of multiple frame images, thereby realizing the function of determining whether the face in the video is a live face.
[0103] It can be seen that implementation Figure 1 The described method for detecting living faces uses predetermined positive samples and negative samples to train a primary detection model, and then inputs a first image to be detected into the trained primary detection model to obtain a primary detection result including a first face bounding box set and a first classification label, thereby being able to simultaneously complete the detection task of the face area and the classification task of the face area in the primary detection model, thereby being able to reduce the time for live face detection and improve the detection efficiency of live faces.
[0104] Embodiment 2
[0105] See also Figure 2 , Figure 2 FIG. 1 is a flow chart of a method for detecting a living face disclosed in an embodiment of the present invention. Figure 2 As shown, the method for detecting living faces may include the following operations:
[0106] 201. After determining the positive samples consisting of living face area images and non-living face area images and the negative samples consisting of background area images, a predetermined first-level detection model is trained based on the face bounding boxes and classification labels corresponding to all living face area images in the positive samples, the face bounding boxes and classification labels corresponding to all non-living face area images in the positive samples, and the background bounding boxes and classification labels corresponding to all background area images in the negative samples to obtain a trained first-level detection model.
[0107] 202. Input the first image to be detected into the trained primary detection model for analysis to obtain a primary detection result corresponding to the first image to be detected.
[0108] 203. According to the first-level detection result, select all uncertain face bounding boxes from all first face bounding boxes in the first face bounding box set.
[0109] In the above step 203, the image framed by each uncertain face boundary box in all the uncertain face boundary boxes is an image of the living face region for which it is uncertain whether or not.
[0110] In an optional embodiment, the first-level detection result may further include a first confidence value corresponding to each first classification label, where the first confidence value corresponding to each first classification label is a numerical value used to indicate the accuracy of the first classification label, wherein a higher first confidence value indicates a higher accuracy of the first classification label corresponding to the first confidence value;
[0111] And, selecting all uncertain face bounding boxes from all first face bounding boxes in the first face bounding box set according to the first-level detection result may include:
[0112] Selecting all to-be-determined face bounding boxes whose first confidence values are greater than or equal to a confidence threshold from among all first face bounding boxes in the first face bounding box set;
[0113] Selecting any first target face bounding box and any second target face bounding box from all face bounding boxes to be determined, the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face region image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face region image;
[0114] Calculating an overlap ratio between the first target face bounding box and the second target face bounding box, and determining whether the overlap ratio is greater than or equal to an overlap ratio threshold;
[0115] If the overlap rate is greater than or equal to the overlap rate threshold, an uncertain face bounding box is determined according to the first target face bounding box and the second target face bounding box.
[0116] In this optional embodiment, the confidence threshold can be set to 0.9. Among all the first face bounding boxes, if the overlap rate of two first face bounding boxes is greater than the overlap rate threshold (for example, 0.7), and the two first face bounding boxes are respectively classified as living faces and non-living faces with confidence values greater than the confidence threshold, the two classification results conflict, which means that the analysis process of the first-level detection model for the images selected by the two first face bounding boxes is not accurate, so it is necessary to determine the uncertain face bounding box based on the two first face bounding boxes, so that the subsequent second-level detection model can perform analysis based on the uncertain face bounding box, thereby making the obtained detection result more accurate. Here, the operation of selecting any first target face bounding box and any second target face bounding box from all face bounding boxes to be determined can be performed multiple times to traverse each combination of the first target face bounding box and the second target face bounding box, and determine whether each combination of the first target face bounding box and the second target face bounding box meets the conditions for being determined as an uncertain face bounding box, thereby screening out all first target face bounding boxes and second target face bounding boxes that are likely to be determined as uncertain face bounding boxes.
[0117] It can be seen that by implementing this optional embodiment, by selecting two first face bounding boxes that have a high overlap rate but are classified as different classification results with a high confidence value, and then determining an uncertain face bounding box based on the two first face bounding boxes, the determination of the uncertain face bounding box is made more accurate, the amount of data processing in subsequent processes is reduced, and the detection efficiency is improved while the accuracy of the detection results is improved.
[0118] In this optional embodiment, further optionally, determining the uncertain face bounding box according to the first target face bounding box and the second target face bounding box may include:
[0119] Determine an overlapping face bounding box according to the first target face bounding box and the second target face bounding box, wherein the overlapping face bounding box is a face bounding box corresponding to an overlapping portion of a living face image area corresponding to the first target face bounding box and a non-living face image area corresponding to the second target face bounding box;
[0120] Calculate a first ratio of the overlapping face bounding box in the first target face bounding box and a second ratio of the overlapping face bounding box in the second target face bounding box, and determine whether the first ratio is greater than or equal to the second ratio;
[0121] If the first proportion is greater than or equal to the second proportion, determining the first target face bounding box as an uncertain face bounding box;
[0122] If the first proportion is not greater than or equal to the second proportion, the second target face bounding box is determined as an uncertain face bounding box.
[0123] In this further optional embodiment, the first target face bounding box, the second target face bounding box and the overlapping face bounding box can all be represented by the center pixel coordinate value of the bounding box and the size of the bounding box (length pixel value and width pixel value). The number of pixels occupied by the bounding box can be calculated by the size of the bounding box, and then the proportion between each bounding box can be calculated by the number of pixels occupied by the bounding box. When the first proportion is greater than or equal to the second proportion, it means that it is more accurate to select the overlapping area with the first target face bounding box, so the first target face bounding box is determined as an uncertain face bounding box. When the first proportion is not greater than or equal to the second proportion, it means that it is more accurate to select the overlapping area with the second target face bounding box, so the second target face bounding box is determined as an uncertain face bounding box.
[0124] It can be seen that by implementing this further optional embodiment, by selecting the bounding box with the highest proportion of overlapping parts between the first target face bounding box and the second target face bounding box as the uncertain face bounding box, the determination of the uncertain face bounding box can be made more accurate, the amount of data processing in subsequent processes can be reduced, and the accuracy of the detection results can be improved while also improving the detection efficiency.
[0125] In this further optional embodiment, further optionally, after determining the uncertain face bounding box according to the first target face bounding box and the second target face bounding box, the method for detecting a living face may further include:
[0126] A first face bounding box whose first confidence value is not greater than or equal to the confidence threshold is selected from all first face bounding boxes, and the selected first face bounding box is added to all uncertain face bounding boxes.
[0127] In this further optional embodiment, when the first confidence value is not high, it means that the accuracy of the first-level detection result is not high, so it is necessary to select the corresponding first face bounding box and add it to the uncertain face bounding box, so as to perform further processing in the subsequent process to improve the accuracy of the detection result.
[0128] It can be seen that by implementing this further optional embodiment, by selecting the first face bounding box with a low confidence value as the uncertain face bounding box, the determination of the uncertain face bounding box can be made more comprehensive, thereby improving the accuracy of the detection result.
[0129] 204. Generate a second image to be detected from the first image to be detected according to all uncertain face bounding boxes.
[0130] In the above step 204, the second image to be detected is an image of the first image to be detected for which it is uncertain whether it is an image of a living human face region.
[0131] In an optional embodiment, the first-level detection result may further include: facial key points corresponding to each first face bounding box, where the facial key points are key points used to perform an alignment operation on the live face area image or the non-live face area image in the first face bounding box;
[0132] And, generating a second image to be detected from the first image to be detected according to all uncertain face bounding boxes may include:
[0133] Extracting a target face region image corresponding to each uncertain face boundary box from the first image to be detected;
[0134] According to the facial key points corresponding to each uncertain face bounding box, the target face area image corresponding to each uncertain face bounding box is aligned with the preset standard face image to obtain the second to-be-detected image corresponding to each uncertain face bounding box.
[0135] In this optional embodiment, the facial key points may be points preset on the face based on the facial features, contours, etc. For example, the tip of the nose may be a key point, the end of the eyebrows may be a key point, and the corner of the mouth may be a key point. The preset standard facial image may be a facial image of a specified pixel size placed in a specified position, for example, a 300 by 300 pixel centered facial image, or a 300 by 300 pixel facial image with the midline of the image tilted at 45 degrees. Image alignment is a common image processing method that can map all pixels of an image to another image based on the feature points on the image (i.e., facial key points), thereby transforming the image into an image with substantially the same size, position, and shape as the other image.
[0136] It can be seen that by implementing this optional embodiment, firstly capturing the target face area image corresponding to the uncertain face boundary box, and then aligning the target face area image to obtain the second image to be detected, the factors affecting the detection accuracy of the detection model in the original target face area image can be reduced, thereby making subsequent detection results more accurate.
[0137] 205. Input the second image to be detected into a predetermined secondary detection model for analysis to obtain a secondary detection result corresponding to the second image to be detected.
[0138] In the above step 205, the secondary detection result includes at least: a second classification label corresponding to the second image to be detected, and the second classification label is used to indicate that the second image to be detected is a living face area image or a non-living face area image. The secondary detection model can be a deep learning network model, preferably a onet model in MTCNN. Since the secondary detection model is used to detect images that the primary detection model fails to accurately judge, it is necessary to use a deep learning network model as the secondary detection model to ensure that the secondary detection model has a sufficiently powerful detection capability. Here, the second classification label can also be set to different values to represent different classification results. For example, the value of the second classification label is 1, which means that the classification result is a living face area image, and the value of the second classification label is 2, which means that the classification result is a non-living face area image.
[0139] 206. Determine a final detection result corresponding to the first image to be detected according to the primary detection result and the secondary detection result.
[0140] In the above step 206, the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image.
[0141] In an optional embodiment, the secondary detection result may further include a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a value used to indicate the accuracy of the second classification label;
[0142] And, determining the final detection result corresponding to the first to-be-detected image according to the primary detection result and the secondary detection result may include:
[0143] Determine whether the first classification label and the second classification label corresponding to the first classification label are the same;
[0144] If the first classification label and the second classification label corresponding to the first classification label are different, determine whether the confidence value difference is greater than the difference threshold, and the confidence value difference is equal to the second confidence value of the second classification label corresponding to the first classification label minus the first confidence value of the first classification label;
[0145] If the confidence value difference is greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the second classification label corresponding to the first classification label is used as the third classification label corresponding to the second face bounding box;
[0146] If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
[0147] In this optional embodiment, the difference threshold can be adjusted to one of the thresholds such as 0.4, 0.5, 0.6, etc. according to the actual effect. In the case that the first classification label output by the primary detection model and the second classification label output by the secondary detection model are inconsistent, it is determined whether the second confidence value output by the secondary detection model is greater than the first confidence value output by the primary detection model. Only when it is determined that the second confidence value is greater than the first confidence value, the second classification label is used as the third classification label.
[0148] It can be seen that when this optional embodiment is implemented, when the first classification label and the second classification label are inconsistent, the first confidence value and the second confidence value are used to determine which classification label is more reliable, thereby determining the third classification label, which can make the detection result more accurate.
[0149] In another optional embodiment, after determining the final detection result corresponding to the first image to be detected according to the primary detection result and the secondary detection result, the method for detecting a living face may further include:
[0150] Selecting a second image to be detected that meets a preset condition as an error-prone image, and combining all the error-prone images into an error-prone sample;
[0151] The first-level detection model is trained based on the face bounding boxes and classification labels corresponding to all living face area images in the error-prone samples and the face bounding boxes and classification labels corresponding to all non-living face area images in the error-prone samples.
[0152] It can be seen that by implementing this other optional embodiment, since most of the second images to be detected are images that the first-level detection model cannot accurately detect, some images are selected from the second images to be detected as training samples, and then the first-level detection model is trained based on the training samples. This can improve the detection capability of the first-level detection model, thereby making the detection results more accurate.
[0153] In this other optional embodiment, further optionally, the preset condition may be that the first confidence value and the second confidence value corresponding to the second image to be detected are both greater than the confidence threshold, and the first classification label and the second classification label corresponding to the second image to be detected are different, or, the first confidence value and the second confidence value corresponding to the second image to be detected are both not greater than the confidence threshold.
[0154] It can be seen that by implementing this further optional embodiment, by selecting the second image to be detected that is classified into different classification results with a higher confidence value or has a low confidence value as a training sample, the data of the training samples can be made more accurate and effective, thereby making the training of the first-level detection model more effective, and further making the detection results more accurate.
[0155] For the detailed description of step 201 and step 202, reference may be made to the detailed description of step 101 and step 102, which will not be described in detail here.
[0156] It can be seen that implementation Figure 2 The described method for detecting live faces uses a pre-determined positive sample and a pre-determined negative sample to train a primary detection model, and then inputs a first image to be detected into the trained primary detection model to obtain a primary detection result including a first face bounding box set and a first classification label, so that the detection task of the face region and the classification task of the face region can be completed simultaneously in the primary detection model, thereby reducing the time for live face detection and improving the detection efficiency of live faces. In addition, it is also possible to select images that the primary detection model fails to accurately judge based on the primary detection result, and then align these images and input them into the secondary detection model for analysis to obtain the secondary detection result, and finally combine the primary detection result and the secondary detection result to obtain the final detection result, thereby improving the accuracy of the detection result.
[0157] Embodiment 3
[0158] See also Figure 3 , Figure 3 FIG. 1 is a schematic diagram of a living face detection device disclosed in an embodiment of the present invention. Figure 3 As shown, the living face detection device may include:
[0159] A training module 301 is used to train a predetermined primary detection model based on face bounding boxes and classification labels corresponding to all live face area images in the positive samples, face bounding boxes and classification labels corresponding to all non-live face area images in the positive samples, and background bounding boxes and classification labels corresponding to all background area images in the negative samples after determining positive samples consisting of live face area images and non-live face area images and negative samples consisting of background area images, to obtain a trained primary detection model;
[0160] The analysis module 302 is used to input the first image to be detected into the trained first-level detection model for analysis to obtain the first-level detection result corresponding to the first image to be detected, and the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate whether the image in the first face bounding box is a living face area image or a non-living face area image.
[0161] It can be seen that implementation Figure 3 The described live face detection device trains a primary detection model by using predetermined positive samples and negative samples, and then inputs a first image to be detected into the trained primary detection model to obtain a primary detection result including a first face bounding box set and a first classification label, thereby being able to simultaneously complete the face area detection task and the face area classification task in the primary detection model, thereby being able to reduce the time of live face detection and improve the detection efficiency of live faces.
[0162] In an optional embodiment, if Figure 4 As shown, the living face detection device also includes:
[0163] The selection module 303 is used for inputting the first image to be detected into the trained first-level detection model for analysis in the analysis module 302, and after obtaining the first-level detection result corresponding to the first image to be detected, selecting all uncertain face bounding boxes from all first face bounding boxes in the first face bounding box set according to the first-level detection result, and the image selected by each uncertain face bounding box in all the uncertain face bounding boxes is an image of whether it is uncertain whether it is a living face area image;
[0164] A generating module 304 is used to generate a second image to be detected from the first image to be detected according to all uncertain face boundary frames, where the second image to be detected is an image of the first image to be detected in which it is uncertain whether it is a living face region image;
[0165] And, the analysis module 302 is further used to input the second image to be detected into a predetermined secondary detection model for analysis to obtain a secondary detection result corresponding to the second image to be detected, the secondary detection result at least including: a second classification label corresponding to the second image to be detected, the second classification label is used to indicate that the second image to be detected is a living face area image or a non-living face area image;
[0166] And, the device also includes:
[0167] The determination module 305 is used to determine the final detection result corresponding to the first image to be detected based on the first-level detection result and the second-level detection result, and the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image.
[0168] It can be seen that implementation Figure 4 The described living face detection device can select images that the first-level detection model cannot accurately judge based on the first-level detection results, and then align these images and input them into the second-level detection model for analysis to obtain the second-level detection results. Finally, the first-level detection results and the second-level detection results are combined to obtain the final detection results, thereby improving the accuracy of the detection results.
[0169] In this optional embodiment, further optional, such as Figure 4 As shown, the first-level detection result also includes a first confidence value corresponding to each first classification label, and the first confidence value corresponding to each first classification label is a value used to represent the accuracy of the first classification label;
[0170] And, the selection module 303 includes:
[0171] A selection submodule 3031 is used to select all to-be-determined face bounding boxes whose first confidence values are greater than or equal to a confidence threshold from all first face bounding boxes in the first face bounding box set;
[0172] And, the selection submodule 3031 is further used to select any first target face bounding box and any second target face bounding box from all face bounding boxes to be determined, the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face area image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face area image;
[0173] And, the selection module 303 further includes:
[0174] The calculation submodule 3032 is used to calculate the overlap rate between the first target face bounding box and the second target face bounding box, and determine whether the overlap rate is greater than or equal to an overlap rate threshold;
[0175] The determination submodule 3033 is used to determine the uncertain face bounding box according to the first target face bounding box and the second target face bounding box after the calculation submodule 3032 determines that the overlap rate is greater than or equal to the overlap rate threshold.
[0176] It can be seen that implementation Figure 4 The described living face detection device selects two first face bounding boxes that have a high overlap rate but are classified as different classification results with a high confidence value, and then determines an uncertain face bounding box based on the two first face bounding boxes, thereby making the determination of the uncertain face bounding box more accurate, reducing the amount of data processing in subsequent processes, and improving the accuracy of the detection results while also improving the detection efficiency.
[0177] In this further optional embodiment, further optional, such as Figure 4 As shown, the specific manner in which the determination submodule 3033 determines the uncertain face bounding box according to the first target face bounding box and the second target face bounding box is:
[0178] Determine an overlapping face bounding box according to the first target face bounding box and the second target face bounding box, wherein the overlapping face bounding box is a face bounding box corresponding to an overlapping portion of a living face image area corresponding to the first target face bounding box and a non-living face image area corresponding to the second target face bounding box;
[0179] Calculate a first ratio of the overlapping face bounding box in the first target face bounding box and a second ratio of the overlapping face bounding box in the second target face bounding box, and determine whether the first ratio is greater than or equal to the second ratio;
[0180] If the first proportion is greater than or equal to the second proportion, determining the first target face bounding box as an uncertain face bounding box;
[0181] If the first proportion is not greater than or equal to the second proportion, the second target face bounding box is determined as an uncertain face bounding box.
[0182] It can be seen that implementation Figure 4 The described living face detection device can make the determination of the uncertain face bounding box more accurate, reduce the amount of data processing in subsequent processes, and improve the accuracy of the detection results while also improving the detection efficiency by selecting the bounding box with the highest proportion of overlapping parts between the first target face bounding box and the second target face bounding box as the uncertain face bounding box.
[0183] In this further optional embodiment, further optional, as Figure 4 As shown, the selection submodule 3031 is also used to select a first face bounding box whose first confidence value is not greater than or equal to a confidence threshold from all first face bounding boxes after the determination submodule 3033 determines the uncertain face bounding box based on the first target face bounding box and the second target face bounding box, and add the selected first face bounding box to all uncertain face bounding boxes.
[0184] It can be seen that implementation Figure 4 The described living face detection device can make the determination of the uncertain face bounding box more comprehensive by selecting the first face bounding box with a low confidence value as the uncertain face bounding box, thereby improving the accuracy of the detection result.
[0185] In another optional embodiment, Figure 4 As shown, the first-level detection result also includes: face key points corresponding to each first face bounding box, the face key points are key points used to align the live face area image or the non-live face area image in the first face bounding box;
[0186] And, the specific manner in which the generating module 304 generates the second image to be detected from the first image to be detected according to all uncertain face boundary boxes is:
[0187] Extracting a target face region image corresponding to each uncertain face boundary box from the first image to be detected;
[0188] According to the facial key points corresponding to each uncertain face bounding box, the target face area image corresponding to each uncertain face bounding box is aligned with the preset standard face image to obtain the second to-be-detected image corresponding to each uncertain face bounding box.
[0189] It can be seen that implementation Figure 4 The described living face detection device first captures the target face area image corresponding to the uncertain face boundary box, and then aligns the target face area image to obtain a second image to be detected. Since the second image to be detected is the image obtained after alignment, it can reduce some factors in the original target face area image that affect the detection accuracy of the detection model, thereby making subsequent detection results more accurate.
[0190] In yet another optional embodiment, Figure 4 As shown, the secondary detection result also includes a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a value used to represent the accuracy of the second classification label;
[0191] And, the specific manner in which the determination module 305 determines the final detection result corresponding to the first to-be-detected image according to the primary detection result and the secondary detection result is:
[0192] Determine whether the first classification label and the second classification label corresponding to the first classification label are the same;
[0193] If the first classification label and the second classification label corresponding to the first classification label are different, determine whether the confidence value difference is greater than the difference threshold, and the confidence value difference is equal to the second confidence value of the second classification label corresponding to the first classification label minus the first confidence value of the first classification label;
[0194] If the confidence value difference is greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the second classification label corresponding to the first classification label is used as the third classification label corresponding to the second face bounding box;
[0195] If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
[0196] It can be seen that implementation Figure 4 The described living face detection device, when the first classification label and the second classification label are inconsistent, determines which classification label is more reliable through the first confidence value and the second confidence value, thereby determining the third classification label, which can make the detection result more accurate.
[0197] For a detailed description of the live face detection device, please refer to the detailed description of the live face detection method mentioned above, which will not be repeated here.
[0198] It can be seen that implementation Figure 4 The described live face detection device trains a first-level detection model by using predetermined positive and negative samples, and then inputs the first image to be detected into the trained first-level detection model to obtain a first-level detection result including a first face bounding box set and a first classification label, so that the detection task of the face area and the classification task of the face area can be completed simultaneously in the first-level detection model, thereby reducing the time of live face detection and improving the detection efficiency of live faces. In addition, it is also possible to select images that the first-level detection model fails to accurately judge based on the first-level detection results, and then align these images and input them into the second-level detection model for analysis to obtain the second-level detection results, and finally combine the first-level detection results and the second-level detection results to obtain the final detection results, thereby improving the accuracy of the detection results.
[0199] Embodiment 4
[0200] See also Figure 5 , Figure 5 FIG. 1 is a schematic diagram of the structure of another living face detection device disclosed in an embodiment of the present invention. Figure 5 As shown, the device may include:
[0201] A memory 501 storing executable program codes;
[0202] a processor 502 coupled to the memory 501;
[0203] The processor 502 calls the executable program code stored in the memory 501 to execute the method for detecting a living face described in the first or second embodiment.
[0204] Embodiment 5
[0205] An embodiment of the present invention discloses a computer storage medium storing a computer program for electronic data exchange, wherein the computer program enables a computer to execute the method for detecting a living face described in the first or second embodiment.
[0206] Embodiment 6
[0207] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer storage medium storing a computer program, and the computer program is operable to enable a computer to execute the method for detecting a living face described in Embodiment 1 or Embodiment 2.
[0208] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0209] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0210] Finally, it should be noted that the method and device for detecting a living face disclosed in the embodiments of the present invention disclose only the preferred embodiments of the present invention, which are only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting a living face, characterized in that: The method comprises: After determining positive samples consisting of live face area images and non-live face area images and negative samples consisting of background area images, training a predetermined primary detection model based on face bounding boxes and classification labels corresponding to all live face area images in the positive samples, face bounding boxes and classification labels corresponding to all non-live face area images in the positive samples, and background bounding boxes and classification labels corresponding to all background area images in the negative samples to obtain a trained primary detection model; Inputting a first image to be detected into the trained first-level detection model for analysis, and obtaining a first-level detection result corresponding to the first image to be detected, wherein the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate that the image in the first face bounding box is a living face area image or a non-living face area image; Furthermore, after inputting the first image to be detected into the trained primary detection model for analysis and obtaining the primary detection result corresponding to the first image to be detected, the method further includes: According to the first-level detection result, all uncertain face bounding boxes are selected from all the first face bounding boxes in the first face bounding box set, and the image selected by each of the uncertain face bounding boxes in all the uncertain face bounding boxes is an image of an area of a living face that is uncertain whether it is an image; Generating a second image to be detected from the first image to be detected according to all the uncertain face boundary boxes, wherein the second image to be detected is an image in the first image to be detected in which it is uncertain whether it is an image of a living face region; Inputting the second image to be detected into a predetermined secondary detection model for analysis, obtaining a secondary detection result corresponding to the second image to be detected, wherein the secondary detection result at least includes: a second classification label corresponding to the second image to be detected, wherein the second classification label is used to indicate whether the second image to be detected is a living face region image or a non-living face region image; Determine a final detection result corresponding to the first image to be detected according to the first-level detection result and the second-level detection result, wherein the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image; The first-level detection result further includes a first confidence value corresponding to each of the first classification labels, and the first confidence value corresponding to each of the first classification labels is a value used to indicate the accuracy of the first classification label; And, selecting all uncertain face bounding boxes from all the first face bounding boxes in the first face bounding box set according to the first level detection result includes: Selecting all to-be-determined face bounding boxes whose first confidence values are greater than or equal to a confidence threshold from among all the first face bounding boxes in the first face bounding box set; Selecting any one first target face bounding box and any one second target face bounding box from all the face bounding boxes to be determined, wherein the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face region image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face region image; Calculating an overlap ratio between the first target face bounding box and the second target face bounding box, and determining whether the overlap ratio is greater than or equal to an overlap ratio threshold; If the overlap rate is greater than or equal to the overlap rate threshold, determining an uncertain face bounding box according to the first target face bounding box and the second target face bounding box; Wherein, the secondary detection result also includes a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a value used to indicate the accuracy of the second classification label; And, determining a final detection result corresponding to the first to-be-detected image according to the first-level detection result and the second-level detection result includes: Determining whether the first classification label and the second classification label corresponding to the first classification label are the same; If the first classification label and the second classification label corresponding to the first classification label are different, determining whether a confidence value difference is greater than a difference threshold, the confidence value difference being equal to a second confidence value of the second classification label corresponding to the first classification label minus a first confidence value of the first classification label; If the confidence value difference is greater than the difference threshold, taking the first face bounding box corresponding to the first classification label as the second face bounding box in the final detection result, and taking the second classification label corresponding to the first classification label as the third classification label corresponding to the second face bounding box; If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
2. The method for detecting living faces according to claim 1, characterized in that: The determining of the uncertain face bounding box according to the first target face bounding box and the second target face bounding box includes: Determine an overlapping face bounding box according to the first target face bounding box and the second target face bounding box, wherein the overlapping face bounding box is a face bounding box corresponding to an overlapping portion of a living face image region corresponding to the first target face bounding box and a non-living face image region corresponding to the second target face bounding box; Calculating a first ratio of the overlapping face bounding box in the first target face bounding box and a second ratio of the overlapping face bounding box in the second target face bounding box, and determining whether the first ratio is greater than or equal to the second ratio; If the first proportion is greater than or equal to the second proportion, determining the first target face bounding box as an uncertain face bounding box; If the first proportion is not greater than or equal to the second proportion, the second target face bounding box is determined as an uncertain face bounding box.
3. The method for detecting a living face according to claim 1 or 2, characterized in that: After determining the uncertain face bounding box according to the first target face bounding box and the second target face bounding box, the method further includes: The first face bounding box whose first confidence value is not greater than or equal to the confidence threshold is selected from all the first face bounding boxes, and the selected first face bounding box is added to all the uncertain face bounding boxes.
4. The method for detecting a living face according to claim 1 or 2, characterized in that: The first-level detection result also includes: facial key points corresponding to each of the first face bounding boxes, the facial key points being key points used to perform an alignment operation on a living face region image or a non-living face region image in the first face bounding box; And, generating a second image to be detected from the first image to be detected according to all the uncertain face bounding boxes includes: Extracting a target face region image corresponding to each of the uncertain face boundary boxes from the first image to be detected; According to the facial key points corresponding to each of the uncertain face bounding boxes, the target face area image corresponding to each of the uncertain face bounding boxes is aligned with a preset standard face image to obtain a second to-be-detected image corresponding to each of the uncertain face bounding boxes.
5. A living face detection device, characterized in that: The device comprises: A training module is used for, after determining positive samples consisting of live face region images and non-live face region images and negative samples consisting of background region images, training a predetermined primary detection model based on face bounding boxes and classification labels corresponding to all live face region images in the positive samples, face bounding boxes and classification labels corresponding to all non-live face region images in the positive samples, and background bounding boxes and classification labels corresponding to all background region images in the negative samples, to obtain a trained primary detection model; an analysis module, configured to input a first image to be detected into the trained first-level detection model for analysis, and obtain a first-level detection result corresponding to the first image to be detected, wherein the first-level detection result at least includes: a first face bounding box set and a first classification label corresponding to each first face bounding box in the first face bounding box set, each first face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the first classification label corresponding to each first face bounding box is used to indicate that the image in the first face bounding box is a living face area image or a non-living face area image; And, the device further comprises: a selection module, configured to, after the analysis module inputs the first image to be detected into the trained first-level detection model for analysis and obtains the first-level detection result corresponding to the first image to be detected, select all uncertain face bounding boxes from all the first face bounding boxes in the first face bounding box set according to the first-level detection result, wherein the image selected by each of the uncertain face bounding boxes is an image whose uncertainty is whether it is an image of a living face area; A generating module, configured to generate a second image to be detected from the first image to be detected according to all the uncertain face boundary frames, wherein the second image to be detected is an image of the first image to be detected in which it is uncertain whether it is an image of a living face region; The analysis module is further used to input the second image to be detected into a predetermined secondary detection model for analysis to obtain a secondary detection result corresponding to the second image to be detected, wherein the secondary detection result at least includes: a second classification label corresponding to the second image to be detected, and the second classification label is used to indicate that the second image to be detected is a living face area image or a non-living face area image; a determination module, configured to determine a final detection result corresponding to the first image to be detected according to the first-level detection result and the second-level detection result, wherein the final detection result at least includes: a second face bounding box set and a third classification label corresponding to each second face bounding box in the second face bounding box set, each second face bounding box is used to select a living face area image or a non-living face area image in the first image to be detected, and the third classification label corresponding to each second face bounding box is used to indicate that the image in the second face bounding box is a living face area image or a non-living face area image; The first-level detection result further includes a first confidence value corresponding to each of the first classification labels, and the first confidence value corresponding to each of the first classification labels is a value used to indicate the accuracy of the first classification label; And, the selection module includes: A selection submodule is used to select all the to-be-determined face bounding boxes whose first confidence value is greater than or equal to the confidence threshold from all the first face bounding boxes in the first face bounding box set; select any one first target face bounding box and any one second target face bounding box from all the to-be-determined face bounding boxes, the first target face bounding box is used to indicate that the image in the first target face bounding box is a living face area image, and the second target face bounding box is used to indicate that the image in the second target face bounding box is a non-living face area image; a calculation submodule, configured to calculate an overlap ratio between the first target face bounding box and the second target face bounding box, and determine whether the overlap ratio is greater than or equal to an overlap ratio threshold; a determination submodule, configured to determine an uncertain face bounding box according to the first target face bounding box and the second target face bounding box after the calculation submodule determines that the overlap rate is greater than or equal to the overlap rate threshold; Wherein, the secondary detection result also includes a second confidence value corresponding to each second classification label, and the second confidence value corresponding to each second classification label is a value used to indicate the accuracy of the second classification label; And, the manner in which the determination module determines the final detection result corresponding to the first to-be-detected image according to the first-level detection result and the second-level detection result specifically includes: Determining whether the first classification label and the second classification label corresponding to the first classification label are the same; If the first classification label and the second classification label corresponding to the first classification label are different, determining whether a confidence value difference is greater than a difference threshold, the confidence value difference being equal to a second confidence value of the second classification label corresponding to the first classification label minus a first confidence value of the first classification label; If the confidence value difference is greater than the difference threshold, taking the first face bounding box corresponding to the first classification label as the second face bounding box in the final detection result, and taking the second classification label corresponding to the first classification label as the third classification label corresponding to the second face bounding box; If the confidence value difference is not greater than the difference threshold, the first face bounding box corresponding to the first classification label is used as the second face bounding box in the final detection result, and the first classification label is used as the third classification label corresponding to the second face bounding box.
6. A living face detection device, characterized in that: The device comprises: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for detecting a living face as described in any one of claims 1 to 4.
7. A computer storage medium storing computer instructions, wherein the computer instructions, when called, are used to execute the method for detecting a living face as described in any one of claims 1 to 4.