Disclosure of Invention
In order to solve the technical problems or at least partially solve the technical problems, embodiments of the present application provide an egg detection method, an egg detection device, an electronic apparatus, and a storage medium.
In a first aspect, an embodiment of the present application provides an egg detection method, including:
acquiring an egg tray image to be detected, wherein the egg tray image to be detected comprises eggs placed in an egg tray;
positioning the eggs from the egg tray image to be detected to obtain a first egg image corresponding to the eggs and position information of the eggs in the egg tray;
classifying the first egg image by adopting a pre-trained egg classification model, wherein the obtained classification result comprises a first egg type of the egg;
for a second egg image of which the classification result does not meet the preset condition, adopting a pre-trained egg detection model to perform pixel identification, and determining the second egg type of the egg according to the identification result;
and generating labels corresponding to the eggs according to the types of the first eggs, the types of the second eggs and the position information.
Optionally, the positioning the eggs from the egg tray image to be detected to obtain a first egg image and position information of the eggs in the egg tray includes:
identifying a first circle corresponding to the poultry egg from the egg tray image to be detected;
determining the first egg image from the first circle.
Optionally, the positioning the eggs from the egg tray image to be detected to obtain a first egg image and position information of the eggs in the egg tray, further includes:
when all egg trough positions of the egg tray are not covered by the first egg image, acquiring an intersection point of a transverse connecting line and a longitudinal connecting line of the first circular circle center;
obtaining a second circle by taking the intersection point as a circle center according to the average radius of the first circle;
determining the first egg image from the second circle.
Optionally, the positioning the eggs from the egg tray image to be detected to obtain a first egg image and position information of the eggs in the egg tray, further includes:
when all egg tray positions of the egg tray are not covered by the first egg image, performing sliding window from the circle centers of the first circle and the second circle according to the average diameter of the first circle and/or the second circle to obtain a third circle;
determining the first egg image from the third circle.
Optionally, the positioning the eggs from the egg tray image to be detected to obtain a first egg image and position information of the eggs in the egg tray, further includes:
and filtering the first egg image according to the position information and/or the size information corresponding to the first egg image.
Optionally, the positioning the eggs from the egg tray image to be detected to obtain a first egg image and position information of the eggs in the egg tray, further includes:
calculating the overlapping rate of two adjacent circles;
adjusting a position and/or size of the first egg image when the overlap ratio is greater than or equal to a first threshold.
Optionally, the first egg type comprises normal eggs and abnormal eggs; the classification result further includes: a probability corresponding to the first egg category;
the poultry egg image with the classification result not meeting the preset condition comprises the following steps:
the first egg type is a normal egg and the probability corresponding to the first egg type is less than or equal to a second threshold value.
Optionally, the pixel recognition is performed by using a pre-trained egg detection model, and the second egg category of the egg is determined according to the recognition result, including:
performing image semantic segmentation on the second egg image according to the egg detection model to obtain a mask image corresponding to the second egg image;
and determining a second egg type of the second egg image according to the pixel value of each pixel in the mask image.
Optionally, the method further includes:
generating a sorting instruction according to the tag, wherein the sorting instruction is used for controlling sorting equipment to execute sorting operation corresponding to the egg type on the eggs corresponding to the position information in the egg tray;
and sending the sorting instruction to the sorting equipment.
In a second aspect, embodiments of the present application provide an egg detection device, including:
the device comprises an acquisition module, a storage module and a display module, wherein the acquisition module is used for acquiring an egg tray image to be detected, and the egg tray image to be detected comprises eggs placed in an egg tray;
the positioning module is used for positioning the eggs from the egg tray image to be detected to obtain a first egg image corresponding to the eggs and position information of the eggs in the egg tray;
a first classification module, configured to classify the first egg image using a pre-trained egg classification model, where an obtained classification result includes a first egg type of the egg;
the second classification module is used for carrying out pixel identification on a second egg image of which the classification result does not meet the preset condition by adopting a pre-trained egg detection model, and determining the second egg type of the egg according to the identification result;
and the generating module is used for generating the labels corresponding to the eggs according to the first egg type, the second egg type and the position information.
In a third aspect, an embodiment of the present application provides an electronic device, including: the system comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the above method steps when executing the computer program.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the above-mentioned method steps.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages:
by taking a picture of the whole plate of eggs, firstly, an egg classification model is adopted to quickly carry out coarse-grained classification on the eggs, and for the eggs with the coarse-grained classification result not meeting the preset condition, an egg detection model is adopted to carry out pixel identification, namely fine-grained classification. Therefore, through twice classification of the coarse and fine particle sizes, the detection efficiency is effectively improved, light source irradiation is not needed during detection, the detection is not influenced by physical conditions, slightly damaged eggs can be accurately identified, and the egg detection accuracy is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The whole plate of poultry eggs are detected based on the computer vision mode, the detection efficiency is effectively improved, light source irradiation is not needed during detection, the influence of physical conditions is avoided, and the detection accuracy is high.
First, a method for detecting eggs according to an embodiment of the present invention will be described.
Fig. 1 is a flowchart of an egg detection method according to an embodiment of the present disclosure. As shown in fig. 1, the method comprises the steps of:
step S11, acquiring an egg tray image to be detected, wherein the egg tray image to be detected comprises eggs placed in an egg tray;
s12, positioning eggs from the egg tray images to be detected to obtain first egg images corresponding to the eggs and position information of the eggs in the egg tray;
step S13, classifying the first egg image by adopting a pre-trained egg classification model, wherein the obtained classification result comprises a first egg type of the egg;
step S14, for a second egg image of which the classification result does not meet the preset condition, adopting a pre-trained egg detection model to carry out pixel identification, and determining the second egg type of the egg according to the identification result;
and step S15, generating labels corresponding to the eggs according to the types of the first eggs, the types of the second eggs and the position information.
In this embodiment, by taking a picture of the whole egg, the egg classification model is first used to quickly perform coarse-grained classification on the eggs, and for eggs whose coarse-grained classification result does not meet the preset conditions, the egg detection model is used to perform pixel identification, that is, fine-grained classification. Therefore, through twice classification of the coarse and fine particle sizes, the detection efficiency is effectively improved, light source irradiation is not needed during detection, the detection is not influenced by physical conditions, slightly damaged eggs can be accurately identified, and the egg detection accuracy is improved.
The egg tray image to be detected comprises a whole egg tray, for example, the egg tray has the specification of 5 multiplied by 6, namely, comprises 30 egg grooves, and 30 eggs can be placed in the egg tray. By the method of the embodiment, the egg types of the 30 eggs and the positions of each egg in the egg tray can be identified at one time.
In practice, only normal eggs or only abnormal eggs may be identified, or both normal and abnormal eggs may be identified, i.e., the type and location of each egg is detected.
Optionally, the method further includes: generating a sorting instruction according to the tag, wherein the sorting instruction is used for controlling sorting equipment to execute sorting operation corresponding to the type of the poultry eggs corresponding to the position information in the egg tray; and sending the sorting instruction to the sorting equipment.
In this embodiment, after detection, abnormal eggs and normal eggs in the egg tray are identified, and the sorting device can be controlled to perform corresponding sorting operations on the eggs in the egg tray. Therefore, abnormal eggs are found and removed in time, loss caused by the influence of the abnormal eggs on normal eggs is reduced, and the storage and processing quality of the eggs is improved. And, sorting accuracy and efficiency are improved.
In addition, since the sorting device may be contaminated when picking up abnormal eggs, for example, when picking up damaged eggs, the egg liquid flows out to contaminate the sorting device, or pick up mildewed eggs to contaminate the sorting device, etc., and further, the normal operation of the sorting device is disturbed, and even the sorting device may be damaged due to a fault, only normal eggs are picked up and sorted to other egg trays, and the contact operation is not performed on abnormal eggs. After normal eggs are sorted, the sorting equipment can be controlled to move the egg tray containing abnormal eggs to the garbage bin.
Fig. 2 is a flowchart of an egg detection method according to another embodiment of the present disclosure. As shown in fig. 2, the step S12 includes:
step S21, identifying a first circle corresponding to the egg from the egg tray image to be detected;
at step S22, a first egg image is determined based on the first circle.
In the embodiment, when the egg tray is overlooked, the circular characteristic of the eggs and the fixed position of the egg tray are utilized, and the circular shape corresponding to the eggs in the egg tray can be detected in a Hough transform characteristic detection mode, so that the eggs are quickly positioned.
However, due to the influence of light and the egg placement position, the positions of the eggs cannot be accurately positioned by adopting the hough transform mode. For example, if some egg grooves in the egg tray lack eggs, the positions of the missing eggs cannot be located by using the hough transform method. For another example, if the presented image is oval due to incorrect egg placement, or if circular information is not obvious due to too close egg distance, missing detection may occur by using hough transform.
To solve the above problem, the eggs in the egg flat image to be detected can be more accurately positioned in the following manner.
And (I) for the position of the missing poultry egg, positioning and determining the position of the missing poultry egg through connecting lines of circle centers of other circles.
Fig. 3 is a flowchart of an egg detection method according to another embodiment of the present disclosure. As shown in fig. 3, the step S12 further includes:
step S31, when all egg tray positions of the egg tray are not covered by the first egg image, acquiring the intersection point of the transverse connecting line and the longitudinal connecting line of the first circular circle center;
step S32, taking the intersection point as the center of a circle, and obtaining a second circle according to the average radius of the first circle;
in step S33, a first egg image is determined based on the second circle.
Fig. 4 is a schematic diagram illustrating a first circle recognized from an egg tray image to be detected according to an embodiment of the present application. As shown in fig. 4, the circles in the second row, the second column, and the third row, the fourth column of the egg tray are not identified. The centers of the circles corresponding to the two positions can be determined through the intersection points of the transverse connecting lines and the longitudinal connecting lines of the centers of the other circles, and then the circles corresponding to the two positions can be obtained according to the average radius of the other circles, such as the dotted circle in fig. 4.
And (II) the position of the missing egg can be determined by sliding the window from other circles.
The step S12 further includes: when all egg tray positions of the egg tray are not covered by the first egg image, performing sliding window from the circle centers of the first circle and the second circle according to the average diameter of the first circle and/or the second circle to obtain a third circle; determining a first egg image from the third circle.
Through the two modes, the eggs or empty egg slots which are not identified in the Hough transform mode can be positioned, so that all eggs on the egg tray in the image can be identified quickly and accurately.
In addition, the circle recognized from the egg tray image by the hough transform mode may not be the circle corresponding to the egg, for example, the small hole on the egg tray is also recognized as a circle. Therefore, the circle identified by the hough transform needs to be filtered. Optionally, the step S12 further includes: and filtering the first egg image according to the corresponding position information and/or size information of the first egg image. Especially, when the number of the finally identified first egg images is larger than the number of egg grooves of the egg plate, the images of non-eggs can be excluded according to the corresponding position information or size information of the images, such as the circular radius.
Moreover, due to a certain recognition error existing in the hough transform mode, the recognized circles may overlap with each other, which further causes the error of the obtained egg image to be larger, and reduces the accuracy of subsequent classification. Thus, when circular overlap occurs, the entire first egg image position or size is required, reducing the overlap rate. Optionally, the step S12 further includes: calculating the overlapping rate of two adjacent circles; when the overlap ratio is greater than or equal to the first threshold, adjusting a position and/or size of the first egg image.
For example, an intersection-to-intersection ratio (IOU) of two adjacent circles may be calculated, and when the IOU is greater than or equal to a preset threshold, the egg image may be shifted by adjusting the position of the circle or by reducing the radius of the circle, or the size of the egg image may be reduced. Therefore, each egg image is closer to the egg and only contains the information of the egg, and the accuracy of subsequent classification based on the egg images is improved.
Optionally, the egg classification model in step S13 may be obtained based on convolutional neural network training such as MobileNetV1, MobileNetV2, MobileNetV3, and the like.
Optionally, the first egg type comprises normal eggs and abnormal eggs. The poultry egg image with the classification result not meeting the preset condition comprises the following steps: the first egg type is a normal egg. In order to avoid missing detection of slightly damaged eggs, fine-grained classification is carried out on the egg images of which the coarse-grained classification results are normal eggs. Therefore, the accuracy and the efficiency of egg detection can be improved.
Optionally, the classification result further includes: a probability corresponding to the first egg category. In step S14, the egg images whose classification results do not meet the preset conditions include: the first egg type is a normal egg and the probability corresponding to the first egg type is less than or equal to a second threshold.
For example, based on an egg classification model trained by MobileNetV2, the output results include egg types and corresponding probabilities. If the probability that a certain egg is a normal egg is more than 99.5%, determining that the egg is a normal egg; if the probability that a certain egg is a normal egg is less than or equal to 99.5%, that is, the damage of the egg may be slight or the egg shell has small flaws, the egg needs to be subjected to subsequent fine-grained classification; and if the classification result is abnormal eggs, directly classifying the eggs as abnormal eggs. Therefore, the detection efficiency is further improved while the damaged eggs are accurately detected.
Optionally, in step S14, performing pixel recognition by using a pre-trained egg detection model, and determining a second egg category of the egg according to the recognition result, including:
performing image semantic segmentation on the second egg image according to the egg detection model to obtain a mask image corresponding to the second egg image;
a second egg type of the second egg image is determined based on the pixel values of the pixels in the mask image.
Optionally, the poultry egg detection model may be obtained by training a neural network based on image semantic segmentation, such as CGNet, ERFNet, ESPNet, ICNet, and the like.
And for the egg image of which the classification result does not meet the preset condition, performing foreground classification on each pixel in the image by using an egg detection model, namely performing image semantic segmentation on the egg image, and determining the egg type through the pixel value in the mask image returned by the model. If the mask image has a promising pixel value, the egg is broken and classified as an abnormal egg. For example, the mask image is a black-and-white image, and the white portion pixel value is 0 and the black portion pixel value is 1. For an egg without breakage, the corresponding mask image should have no black pixels or no black pixels corresponding to the breakage state. If a black pixel corresponding to a broken morphology appears in the mask image, it may be determined that the type corresponding to the egg should be an abnormal egg.
The damaged egg has various damaged forms, including serious damage, such as complete damage, clear visible cracks and the like, and slight damage, such as slight dent, flat round small hole and the like. Therefore, abnormal egg samples of different abnormal types can be collected in advance, and the training of the egg detection model is carried out through the abnormal egg samples, so that the egg detection model can identify various types, particularly slightly damaged eggs.
Optionally, the egg detection model may be obtained based on CGNet, and the model not only uses the features of each pixel when classifying each pixel, but also fully uses the features of the pixels around the pixel and the features of the full image, thereby improving the classification accuracy for slightly damaged eggs.
Optionally, in the above method embodiment, a multithreading technology is adopted, and the egg images are subjected to parallel classification processing, for example, 30 egg images are obtained by positioning, parallel coarse and fine granularity classification is performed by adopting 5 threads, and final classification results are summarized, so that the egg detection efficiency is improved, and the detection time is reduced.
Fig. 5 is a schematic diagram of an egg tray image detection result provided in the embodiment of the present application. As shown in fig. 5, in which a slightly broken egg is accurately identified.
The following are embodiments of the disclosed apparatus that may be used to perform embodiments of the disclosed methods.
Fig. 6 is a block diagram of an egg detection device according to an embodiment of the present disclosure, which may be implemented as part or all of an electronic device through software, hardware or a combination of the two. As shown in fig. 6, the egg detection apparatus includes:
the acquisition module 51 is used for acquiring an egg tray image to be detected, wherein the egg tray image to be detected comprises eggs placed in an egg tray;
the positioning module 52 is configured to position eggs from the egg tray image to be detected, so as to obtain a first egg image corresponding to the eggs and position information of the eggs in the egg tray;
the first classification module 53 is configured to classify the first egg image by using a pre-trained egg classification model, where an obtained classification result includes a first egg type of an egg;
the second classification module 54 is configured to perform pixel recognition on a second egg image of which the classification result does not meet the preset condition by using a pre-trained egg detection model, and determine a second egg category of the egg according to the recognition result;
and the generating module 55 is configured to generate tags corresponding to the eggs according to the first egg type, the second egg type and the location information.
An embodiment of the present application further provides an electronic device, as shown in fig. 7, the electronic device may include: the system comprises a processor 1501, a communication interface 1502, a memory 1503 and a communication bus 1504, wherein the processor 1501, the communication interface 1502 and the memory 1503 complete communication with each other through the communication bus 1504.
A memory 1503 for storing a computer program;
the processor 1501, when executing the computer program stored in the memory 1503, implements the steps of the method embodiments described below.
The communication bus mentioned in the electronic device may be a peripheral component interconnect (pci) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
The present application also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method embodiments described below.
It should be noted that, for the above-mentioned apparatus, electronic device and computer-readable storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
It is further noted that, herein, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.