Disclosure of Invention
In view of the above, embodiments of the present invention provide a method and apparatus for detecting a living body, and an electronic device, which overcome or at least partially solve the above problems.
According to an aspect of an embodiment of the present invention, there is provided a method for detecting a living body, including: acquiring a first object image of an object to be identified, which is shot by a color camera, and a second object image of the object to be identified, which is shot by an infrared camera; identifying whether the object to be identified is a living body according to the color space of the first object image, and identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network; if the object to be identified is identified as a living body according to the color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network, determining that the object to be identified is a living body; otherwise, determining that the object to be identified is not a living body.
In an optional manner, the step of identifying whether the object to be identified is a living body according to the color space of the first object image further includes: converting an RGB color space of the first object image into an HSV color space; acquiring hue and saturation of an HSV color space of the first object image; judging whether the HSV color space of the first object image is positioned in a preset living body area or a preset non-living body area based on the hue and the saturation; if the object to be identified is located in the preset living body area, determining that the object to be identified is a living body; and if the object to be identified is positioned in the preset non-living body area, determining that the object to be identified is not a living body.
In an alternative manner, the preset living body region and the preset non-living body region are obtained by detecting a plurality of living body samples and non-living body samples.
In an optional manner, the step of identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network further includes: reducing the size of the second object image to a preset size; inputting the reduced second object image into a preset neural network for detection; and judging whether the object to be identified after the shrinkage is a living body or not according to the detection result.
In an alternative manner, the preset neural network is obtained by taking a network structure of MobilenetV as a base network and optimizing the number of cores of each layer of MobilenetV by adopting a model pruning algorithm, wherein the activation layer of MobilenetV3 is Relu layers.
According to one aspect of the embodiment of the invention, an acquisition module is provided, and is used for acquiring a first object image of an object to be identified, which is shot by a color camera, and a second object image of the object to be identified, which is shot by an infrared camera; the identification module is used for identifying whether the object to be identified is a living body according to the color space of the first object image, and identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network; a first determining module, configured to determine that the object to be identified is a living body if the object to be identified is identified as a living body according to a color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network; and the second determining module is used for determining that the object to be identified is not a living body.
In an alternative manner, the identification module includes: a conversion unit configured to convert an RGB color space of the first object image into an HSV color space; an acquisition unit configured to acquire hue and saturation of an HSV color space of the first object image; a first judging unit configured to judge whether an HSV color space of the first object image is located in a preset living area or a preset non-living area based on the hue and saturation; a first determining unit, configured to determine that the object to be identified is a living body if the HSV color space of the first object image is located in a preset living body area; and the second determining unit is used for determining that the object to be identified is not a living body if the HSV color space of the first object image is located in a preset non-living body area.
In an alternative manner, the preset living body region and the preset non-living body region are obtained by detecting a plurality of living body samples and non-living body samples.
In an alternative manner, the identification module includes: a reduction unit configured to reduce the size of the second object image to a preset size; the input unit is used for inputting the reduced second object image into a preset neural network for detection; and the second judging unit is used for judging whether the object to be identified after the shrinkage is a living body or not according to the detection result.
In an alternative manner, the preset neural network is obtained by taking a network structure of MobilenetV as a base network and optimizing the number of cores of each layer of MobilenetV by adopting a model pruning algorithm, wherein the activation layer of MobilenetV3 is Relu layers.
According to an aspect of an embodiment of the present invention, there is provided an electronic device including: at least one processor, and a memory communicatively coupled to the at least one processor, the memory storing instructions executable by the at least one processor to enable the at least one processor to perform the method as described above.
According to an aspect of an embodiment of the present invention, there is provided a non-transitory computer-readable storage medium storing computer-executable instructions which, when executed by an electronic device, cause the electronic device to perform a method as described above.
The embodiment of the invention has the beneficial effects that: different from the existing living body detection method, the embodiment of the invention obtains the first object image of the object to be identified, which is shot by the color camera, and the second object image of the object to be identified, which is shot by the infrared camera; identifying whether the object to be identified is a living body according to the color space of the first object image, and identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network; if the object to be identified is identified as a living body according to the color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network, determining that the object to be identified is a living body; otherwise, the method for determining that the object to be identified is not a living body can realize the detection of the living body and resist the attack of the black and white non-living body, and the printing attack of the infrared living body is black and white, so that the method can resist the printing attack of the infrared living body.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Example 1
Referring to fig. 1, fig. 1 is a flowchart of a living body detection method according to an embodiment of the invention, the method includes the following steps:
Step S101, a first object image of an object to be identified, which is shot by a color camera, and a second object image of the object to be identified, which is shot by an infrared camera, are acquired.
The color cameras, in some embodiments, are RGB cameras. In some embodiments, the color camera and the infrared camera simultaneously photograph the object to be identified.
Step S102, identifying whether the object to be identified is a living body according to the color space of the first object image, and identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network.
The living body shot by the color camera is colored, the color space is RGB color space, and the black-white non-living body is black-white, which have obvious differences, so that the attack of the black-white non-living body can be resisted by judging whether the first object image is colored or black-white. Specifically, referring to fig. 2, step S102 includes:
Step S1021, converting the RGB color space of the first object image into an HSV color space.
Included in the HSV color space are hue, saturation, and brightness. In the HSV color space, the first object image of the living body and the black-and-white non-living body are significantly different in hue and saturation. The attack of the infrared living body can be resisted by comparing the first object image of the living body with the hue and saturation of the black-white non-living body. Since the first object image photographed by the color camera is an RGB color space, it is necessary to convert the RGB color space of the first object image into an HSV color space.
Step S1022 acquires hue and saturation of the HSV color space of the first object image.
Step S1023, based on the hue and saturation, determines whether the HSV color space of the first object image is located in a preset living area or a preset non-living area, if so, executes step S1024, and if so, executes step S1025.
The preset living body region and the preset non-living body region are obtained by detecting a plurality of living body samples and non-living body samples. Since the hue and saturation of the first object image of the living body and the black-and-white non-living body are significantly different, it is only necessary to collect the hues and the saturation in the HSV color spaces of the images of the first object of the living body and collect the hues and the saturation in the HSV color spaces of the black-and-white non-living body, and it can be determined whether the HSV color space of the first object image is located in a preset living body area or in a preset non-living body area by the areas of the hues and the saturation.
Here, for example, a large number of face image samples of a living body sample and a large number of face image samples of a black-and-white non-living body sample are collected, converted into HSV color space, hue and saturation are obtained, and a chart is made, see fig. 3. Real in fig. 3 is the living body, like is the non-living body, hue is the hue, and saturation is the saturation. As can be seen from fig. 3, the straight line L1 in fig. 3 divides the corresponding region of hue and saturation into a living region and a non-living region, the region where the point representing real is located is the living region, and the region where the point representing fake is located is the non-living region. When the first object image is a facial image, whether the object to be identified is a living body or a non-living body can be determined by judging whether the HSV color space of the first object image is located in the living body area in fig. 3 or the non-living body area in fig. 3. For example, if the hue of the HSV color space of the first object image is 120 and the saturation is 150, the object to be identified is determined to be a living body. For another example, if the hue of the HSV color space of the first object image is 120 and the saturation is 25, the object to be identified is determined to be a non-living body.
Step S1024, determining that the object to be identified is a living body.
Step S1025, determining that the object to be identified is not a living body.
Further, it is also required to identify whether the second object image photographed by the infrared camera is a living body. Specifically, referring to fig. 4, step S102 further includes:
step S1026, reducing the size of the second object image to a preset size.
When the living body detection method is applied to embedded equipment such as an access control device, an attendance machine and the like, if a good effect is to be achieved, the calculation amount is large, the equipment operation speed is low, the instantaneity is poor, and the user experience is affected. In order to increase the calculation speed, the size of the second object image can be reduced, so that the number of channels of each residual module is reduced, the calculation amount is reduced, and the speed of processing one image by a network is increased. In some embodiments, the second object image has a size 224x224 and the predetermined size 112x112.
Step S1027, inputting the reduced second object image into a preset neural network for detection.
The preset neural network is obtained by taking a network structure of MobilenetV as a basic network and adopting a model pruning algorithm to optimize the number of cores of each layer of MobilenetV, wherein an activation layer of MobilenetV is Relu layers. Relu layers are simple, and the operation efficiency can be improved on the premise of ensuring the detection accuracy.
Step 1028, determining whether the object to be identified after shrinking is a living body according to the detection result.
For example, when the face of the living body is subjected to infrared shooting, a non-living body except for the printing attack of the infrared living body has no bright pupil effect, so that whether the face of the object to be identified has the bright pupil effect or not can be judged through the preset neural network, and whether the object to be identified is a living body except for the printing attack of the infrared living body or not can be judged.
Step S103, if the object to be identified is identified as a living body according to the color space of the first object image, and if the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network, determining that the object to be identified is a living body, otherwise, executing step S104.
In general, only the second object image is required, and whether the object to be recognized is a living body can be recognized in combination with a predetermined neural network, but a print attack on an infrared living body is easily mistaken as a living body. Since the print attack of the infrared living body is black and white, the first object image is photographed by a color camera and is colored, and the two images are obviously different. And identifying the object to be identified as a living body through the first object image, identifying the object to be identified as the living body according to the second object image and combining a preset neural network, and determining that the object to be identified is the living body if the object to be identified is not the living body.
Step S104, determining that the object to be identified is not a living body.
In the embodiment of the invention, a first object image of an object to be identified, which is shot by a color camera, and a second object image of the object to be identified, which is shot by an infrared camera, are acquired; identifying whether the object to be identified is a living body according to the color space of the first object image, and identifying whether the object to be identified is a living body according to the second object image and in combination with a preset neural network; if the object to be identified is identified as a living body according to the color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network, determining that the object to be identified is a living body; otherwise, the method for determining that the object to be identified is not a living body can realize the detection of the living body and resist the attack of the black and white non-living body, and the printing attack of the infrared living body is black and white, so that the method can resist the printing attack of the infrared living body.
Example two
Referring to fig. 5, fig. 5 is a schematic diagram of a living body detection apparatus according to an embodiment of the invention, the apparatus 400 includes: an acquisition module 401, an identification module 402, a first determination module 403 and a second determination module 404. The acquiring module 401 is configured to acquire a first object image of an object to be identified, which is captured by the color camera, and a second object image of the object to be identified, which is captured by the infrared camera; an identifying module 402, configured to identify, according to a color space of the first object image, whether the object to be identified is a living body, and identify, according to the second object image and in combination with a preset neural network, whether the object to be identified is a living body; a first determining module 403, configured to determine that the object to be identified is a living body if the object to be identified is identified as a living body according to the color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network; a second determining module 404 is configured to determine that the object to be identified is not a living body.
In some embodiments, the identification module 402 includes: a conversion unit 4021, an acquisition unit 4022, a first judgment unit 4023, a first determination unit 4024, and a second determination unit 4025. Wherein the conversion unit 4021 is configured to convert an RGB color space of the first object image into an HSV color space; an acquisition unit 4022 configured to acquire hue and saturation of an HSV color space of the first object image; a first judging unit 4023 configured to judge whether an HSV color space of the first object image is located in a preset living area or a preset non-living area based on the hue and saturation; a first determining unit 4024 configured to determine that the object to be identified is a living body if the HSV color space of the first object image is located in a preset living body area; the second determining unit 4025 is configured to determine that the object to be identified is not a living body if the HSV color space of the first object image is located in a preset non-living body area.
In some embodiments, the predetermined living area and the predetermined non-living area are obtained by detecting a plurality of living samples and non-living samples.
Further, the identification module 402 includes: a reduction unit 4026, an input unit 4027, and a second determination unit 4028. A reducing unit 4026 configured to reduce the size of the second object image to a preset size; an input unit 4027 configured to input the reduced second object image into a preset neural network for detection; a second judging unit 4028 for judging whether the reduced object to be identified is a living body according to the detection result.
In some embodiments, the preset neural network is based on a network structure of MobilenetV, and the number of cores of each layer of MobilenetV is optimized by using a model pruning algorithm, wherein the activation layer of MobilenetV3 is Relu layers.
In the embodiment of the invention, a first object image of an object to be identified, which is shot by a color camera, and a second object image of the object to be identified, which is shot by an infrared camera, are acquired by an acquisition module; identifying whether the object to be identified is a living body or not according to the color space of the first object image through an identification module, and identifying whether the object to be identified is a living body or not according to the second object image and in combination with a preset neural network; if the object to be identified is identified as a living body according to the color space of the first object image, and the object to be identified is identified as a living body according to the second object image and in combination with a preset neural network, determining that the object to be identified is a living body through a first determining module; otherwise, determining that the object to be identified is not a living body through a second determining module. By the device, the living body can be detected, and the attack of black and white non-living bodies can be resisted.
Example III
Referring to fig. 6, fig. 6 is a schematic diagram of a hardware structure of an electronic device for performing a method for detecting a living body according to an embodiment of the invention. As shown in fig. 6, the electronic device 500 includes: one or more processors 501 and a memory 502, one for example in fig. 6.
The processor 501 and the memory 502 may be connected by a bus or otherwise, which is illustrated in fig. 6 as a bus connection.
The memory 502 is a non-volatile computer readable storage medium, and may be used to store a non-volatile software program, a non-volatile computer executable program, and modules, such as program instructions/modules (e.g., the respective modules shown in fig. 5) corresponding to the living body detection method in the embodiment of the present invention. The processor 501 executes various functional applications and data processing of the living body detection apparatus by executing nonvolatile software programs, instructions, and modules stored in the memory 502, that is, implements the living body detection method of the above-described method embodiment.
Memory 502 may include a storage program area that may store an operating system, at least one application program required for functionality, and a storage data area; the storage data area may store data created according to the use of the detection device of the living body, or the like. In addition, memory 502 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 502 optionally includes memory remotely located relative to processor 501, which may be connected to the in-vivo detection device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The one or more modules are stored in the memory 502, and when executed by the one or more processors 501, perform the method of detecting a living body in any of the above-described method embodiments, for example, performing the method steps S101 to S104 in fig. 1, the method steps S1021 to S1025 in fig. 2, and the method steps S1026 to S1028 in fig. 4 described above, to implement the functions of the modules 401 to 404 and the modules 4021 to 4028 in fig. 5.
The product can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. Technical details not described in detail in this embodiment may be found in the methods provided in the embodiments of the present invention.
An embodiment of the present invention provides a nonvolatile computer-readable storage medium storing computer-executable instructions that are executed by an electronic device to perform the method for detecting a living body in any of the above-described method embodiments, for example, perform the method steps S101 to S104 in fig. 1, the method steps S1021 to S1025 in fig. 2, and the method steps S1026 to S1028 in fig. 4, which implement the functions of the modules 401 to 404 and the modules 4021 to 4028 in fig. 5.
An embodiment of the present invention provides a computer program product including a computer program stored on a non-volatile computer readable storage medium, the computer program including program instructions which, when executed by a computer, cause the computer to perform the method for detecting a living body in any of the above-described method embodiments, for example, performing the method steps S101 to S104 in fig. 1, the method steps S1021 to S1025 in fig. 2, and the method steps S1026 to S1028 in fig. 4 described above, to implement the functions of the modules 401 to 404 and the modules 4021 to 4028 in fig. 5.
From the above description of embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus a general purpose hardware platform, or may be implemented by hardware. Those skilled in the art will appreciate that all or part of the processes implementing the methods of the above embodiments may be implemented by a computer program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and where the program may include processes implementing the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a random-access Memory (Random Access Memory, RAM), or the like.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; the technical features of the above embodiments or in the different embodiments may also be combined within the idea of the invention, the steps may be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention.