CNN-based crack egg detection method
Through the CNN-based crack detection method, using the ResNet deep residual neural network and attention mechanism, the problem of low efficiency of traditional manual detection is solved, and efficient and accurate poultry egg crack identification and quality judgment are achieved.
Patent Information
- Application Number
- CN202510715475.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-09-05
AI Technical Summary
Traditional egg crack detection relies on manual observation, which is inefficient and affected by subjective factors, making it difficult to achieve efficient and accurate egg quality detection.
A CNN-based crack detection method is adopted. The ResNet deep residual neural network is combined with the attention mechanism to preprocess and extract features of poultry egg images, build a crack detection model, and achieve accurate crack identification by training and adjusting network parameters.
The accuracy and efficiency of egg crack detection are improved, and it can more accurately determine whether eggs have cracks, supporting the automatic screening and quality determination of eggs.
Smart Images

Figure CN120599362A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine vision, and in particular to a crack egg detection method based on CNN. Background Art
[0002] Crack detection is a crucial step in ensuring egg quality during egg production and processing. Traditional detection methods rely primarily on manual observation, which is subject to significant subjective factors and inefficient. Therefore, the use of machine vision technology for crack detection in poultry eggs is of great significance. It can improve detection efficiency, reduce manual labor, lower production costs, and enhance product quality and safety. In poultry egg processing plants, this technology can be used to perform real-time crack detection on eggs on the production line and remove or mark cracked eggs. This not only improves production efficiency but also reduces defective rates, enhancing product quality and safety. Furthermore, this technology can be integrated with other automated equipment and systems to achieve fully automated production and management of poultry egg production lines. For example, machine vision systems can be combined with sorting equipment to automatically sort and pack cracked eggs. Alternatively, they can be integrated with database management systems to enable real-time collection, storage, and analysis of egg production data.
[0003] Korean Patent KR102283869B1 discloses an automated egg quality inspection system. The system comprises: an imaging unit mounted on a conveyor line including a conveyor belt to form a darkroom. The imaging unit images eggs conveyed while rotating while positioned above the conveyor belt in the darkroom, generating egg images and transmitting the generated egg images to a screening unit; an illumination unit positioned below the imaging unit to illuminate the images; and a screening unit that performs artificial intelligence analysis and screening on the egg images from the imaging unit to generate location information for eggs classified as defective. This patented technology ensures high reliability in screening for defective eggs by imaging eggs as they pass through the darkroom and analyzing the multiple captured egg images through artificial intelligence. Summary of the Invention
[0004] In view of the shortcomings of the existing technology, the present invention provides a crack egg detection method and a control method thereof based on CNN.
[0005] To achieve the above object, the present invention provides the following technical solutions: On the one hand, a crack egg detection method based on CNN is provided, comprising the following steps: Step S1: using a camera to collect a predetermined number of images of poultry eggs, and marking the collected images as two types of samples, namely, samples with cracks and samples without cracks, to construct a training data set; Step S2, preprocessing the egg image using methods including grayscale, histogram equalization, and bilateral filtering; Step S3: Establish a crack detection model based on ResNet deep residual neural network; Step S4: putting the data processed in step S2 into the model established in step S3 for training to obtain a preliminary crack detection model; Step S5: training the region of interest of the feature map according to each convolutional layer, adjusting the network structure and network parameters, and then retraining the preliminary crack recognition model to obtain the optimal crack detection model; Step S6: construct a detection data set using the collected egg images, perform image preprocessing on them using grayscale, histogram equalization and bilateral filtering, pass the preprocessed egg images into the optimal crack recognition model, and output the image detection results.
[0006] Preferably, in step S3, a ResNet deep residual neural network crack detection model is constructed using a residual network guided by two consecutive attentions.
[0007] Preferably, the construction of the ResNet deep residual neural network crack detection model includes: constructing a first ResNet unit, setting a first attention mechanism after the first ResNet unit, constructing a second ResNet unit after the first attention mechanism, setting a second attention mechanism after the second ResNet unit, using local average pooling to reduce the number of connection layer parameters after the second attention concentration, and after the local average pooling, using a fully connected layer for feature integration, and finally the output layer uses a softmax activation function to output the detection result.
[0008] Preferably, the first ResNet unit and the second ResNet unit each include two consecutive convolution kernels, and the convolution kernel size is 3x3.
[0009] Preferably, the first ResNet unit and the second ResNet unit can set the part of the feature map that does not belong to the target to zero by multiplying the mask map with the feature map, thereby retaining only the features of the target area.
[0010] Preferably, the first channel attention mechanism and the second channel attention mechanism both perform local average pooling and local maximum pooling operations on the input feature map, and the one-dimensional feature vectors obtained by the two pooling operations are merged and encoded using a multi-layer perceptron, and the encoding result is passed through a Sigmoid activation function to obtain a vector representing the weight of each channel.
[0011] Preferably, the encoding using a multi-layer perceptron comprises: encoding a one-dimensional feature vector input into an output space of fixed dimension.
[0012] Preferably, the use of a fully connected layer for feature integration includes: the fully connected layer outputs a classification score vector, in which each element corresponds to the score of a category.
[0013] Preferably, the output layer outputting the detection result using the softmax activation function includes: converting the score vector into a probability distribution through the softmax activation function.
[0014] Preferably, the preprocessed egg image is passed into the optimal crack recognition model, and the image detection result is output, including: comparing the probability of the softmax output with a preset value, when the probability is greater than the preset value, it is determined that cracks appear in the egg, otherwise, it is determined that no cracks appear.
[0015] Compared with the prior art, the present invention has the following beneficial effects: (1) The present invention establishes a crack detection model based on the ResNet deep residual neural network. The model uses a residual network guided by an attention mechanism, which can effectively capture the local details and texture features of cracked eggs, and improves the sensitivity to small changes inside cracked eggs. The details and texture features of poultry egg images can be used to more accurately determine whether poultry eggs have cracks, which helps to screen poultry eggs and accurately determine the quality of poultry eggs. (2) The crack egg detection method based on CNN of the present invention encodes the features extracted from local features, and the network can effectively utilize local information to improve the accuracy of crack egg classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A flow chart of a cracked egg detection method based on CNN provided by the present invention; Figure 2 The crack detection model based on ResNet deep residual neural network provided by the present invention; Figure 3 Another crack detection model based on ResNet deep residual neural network is provided by the present invention. DETAILED DESCRIPTION
[0017] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0018] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0019] Example 1 like Figure 1 As shown, this embodiment provides a crack egg detection method based on CNN, which includes: Step S1: using a camera to collect a predetermined number of images of poultry eggs, and marking the collected images as two types of samples, namely, samples with cracks and samples without cracks, to construct a training data set; In step S1, a high-precision camera is used to capture images of eggs. The captured images are then labeled as crack-free or crack-free. Specifically, a labeling tool such as LabelImg or LabelImg is selected. For cracked eggs, a rectangular box (for target detection) is used to accurately mark the cracked area, ensuring that the box or labeled points closely follow the crack edges to avoid omissions. For eggs without cracks, crack labeling is not required and the image information can be marked as "no cracks." The labeled images and annotation files are categorized by crack presence and stored in separate folders.
[0020] Step S2, preprocessing the egg image using graying, histogram equalization, and bilateral filtering; To improve the model's generalization and performance, in step S2, the egg images are preprocessed before being input into the CNN model. Specifically, the egg images are first grayscaled, converting them into grayscale images. Histogram equalization is then performed on the grayscaled images, adjusting the grayscale histogram of the input image to make its grayscale values more evenly distributed and enhance the image contrast. Finally, bilateral filtering is applied to smooth the image while preserving its edges.
[0021] Step S3: Establish a crack detection model based on ResNet deep residual neural network; like Figure 2As shown, in step S3, a ResNet deep residual neural network crack detection model is constructed using a residual network guided by two consecutive attentions. The crack detection model construction process is as follows: the construction of the ResNet deep residual neural network crack detection model includes: constructing a first ResNet unit, setting a first attention mechanism after the first ResNet unit, constructing a second ResNet unit after the first attention mechanism, setting a second attention mechanism after the second ResNet unit, using local average pooling after the second attention concentration to reduce the number of connection layer parameters, and after the local average pooling, using a fully connected layer for feature integration. Finally, the output layer uses a softmax activation function to output the detection result.
[0022] When constructing the crack detection model, the first ResNet unit and the second ResNet unit select the ResNet18 network. The ResNet18 network includes at least 4 convolutional layers and 8 residual blocks. Each convolutional layer uses a 3x3 convolution kernel and a ReLU activation function to extract local features of the image input to the ResNet network. Each residual block consists of two convolutional layers and a skip connection.
[0023] The first and second ResNet units each include two consecutive convolution kernels of 3x3 size. The input features undergo two consecutive convolutions to extract local context information. Residual connections are introduced to accelerate network optimization. Finally, the output features are element-wise multiplied with the segmentation mask image. The operation formulas of the first and second ResNet units are as follows: (1) Among them, represents the input, F(x) represents the features learned by the convolution block, R(x) represents the Mask feature map, Y(x) represents the learned features output under the guidance of the segmentation Mask attention, and m is used to match the dimensions of the residual block and the segmentation Mask map.
[0024] The first ResNet unit and the second ResNet unit can set the part of the feature map that does not belong to the target to zero by multiplying the mask map with the feature map, thereby retaining only the features of the target area. The mask map is used to distinguish different targets in the image. By multiplying the mask map with the feature map, the part of the feature map that does not belong to the target can be set to zero, thereby retaining only the features of the target area, which enables the network to generate an accurate pixel-level segmentation mask for each target instance and achieve accurate segmentation of the target. The mask map can be used as an attention mechanism to guide the network to focus on specific areas. For example, in certain target detection or segmentation tasks, the mask map is used to focus the network's attention on the target area of interest, ignoring the background or other irrelevant information, which helps to improve the model's recognition and segmentation accuracy of the target.
[0025] Both the first-channel attention mechanism and the second-channel attention mechanism perform local average pooling and local maximum pooling operations on the input feature map. The one-dimensional feature vectors obtained by the two pooling operations are merged and encoded using a multi-layer perceptron. The encoded result is passed through the Sigmoid activation function to obtain a vector representing the weight of each channel. In this step, encoding using a multi-layer perceptron is to encode the one-dimensional feature vector input into an output space of a fixed dimension to achieve the purpose of dimensionality reduction. The formula of the Sigmoid activation function is as follows: (2) In this step, the output layer of the multilayer perceptron uses the Sigmoid function to construct a nonlinear model, mapping the value input to the Sigmoid function to a range between 0 and 1 and outputting it in the form of probability.
[0026] Step S4: putting the data processed in step S2 into the model established in step S3 for training to obtain a preliminary crack detection model; Step S5: training the region of interest of the feature map according to each convolutional layer, adjusting the network structure and network parameters, and then retraining the preliminary crack recognition model to obtain the optimal crack detection model; During the training process, the performance of the model is evaluated by monitoring the loss function indicators and adjusting them as needed. In this crack detection model, the binary cross entropy loss function is used to evaluate the model performance. The binary cross entropy loss function is as follows: (3) Where N represents the total number of pixels in the input image, represents the true label of the i-th pixel, where 1 represents the positive class and 0 represents the negative class. represents the probability that the i-th pixel is predicted to be a positive class.
[0027] The binary cross entropy loss function is used to judge the quality of the prediction results of a binary classification model. If the predicted value is 1, approaches 1, then The value of should be close to 0. On the contrary, if the predicted value Approaching 0.
[0028] In step S5, adjusting the network structure includes adjusting the number of network layers, and the training parameters include batch size, learning rate, and training cycle.
[0029] Step S6: construct a detection data set using the collected egg images, perform image preprocessing on them using grayscale, histogram equalization and bilateral filtering, pass the preprocessed egg images into the optimal crack recognition model, and output the image detection results.
[0030] The method of using a fully connected layer for feature integration includes: the fully connected layer outputting a classification score vector, wherein each element corresponds to a score for a category. The method of using a softmax activation function to output the detection result in the output layer includes: converting the score vector into a probability distribution via the softmax activation function. The method of transmitting the preprocessed egg image to an optimal crack recognition model and outputting the image detection result includes: comparing the probability output by the softmax function with a preset value; if the probability is greater than the preset value, the egg is determined to have cracks; otherwise, the egg is determined to have no cracks.
[0031] Example 2 like Figure 3 As shown, in the process of establishing a crack detection model based on the ResNet deep residual neural network, in order to facilitate the output of crack egg detection results, the masked egg image is position-annotated after the first ResNet unit and before the first attention mechanism. The annotation information is based on the original content or preprocessed content of the image. When performing position annotation, the position of the target object of interest will be marked on the image.
[0032] In summary, the present invention proposes a CNN-based crack egg detection method. The present invention establishes a crack detection model based on the ResNet deep residual neural network. The model adopts a residual network guided by an attention mechanism, which can effectively capture the local details and texture features of cracked eggs, and improves the sensitivity to small changes inside cracked eggs. The details and texture features of the egg images can be used to more accurately determine whether the eggs are cracked, which helps to screen the eggs and accurately determine the quality of the eggs.
[0033] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0034] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0035] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a specific manner as specified in the instructions, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0036] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a specific manner as specified in the instructions, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0037] It should be noted that the technical features in the above embodiments can be combined in any way, and the technical solutions formed by the combination all fall within the scope of protection of this application. In this article, terms such as "including", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including a..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0038] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A cracked egg detection method based on CNN, characterized in that: The steps include: Step S1: using a camera to collect a predetermined number of images of poultry eggs, and marking the collected images as two types of samples, namely, samples with cracks and samples without cracks, to construct a training data set; Step S2, preprocessing the egg image using grayscale, histogram equalization, and bilateral filtering; Step S3: Establish a crack detection model based on ResNet deep residual neural network; Step S4: putting the data processed in step S2 into the model established in step S3 for training to obtain a preliminary crack detection model; Step S5: training the region of interest of the feature map according to each convolutional layer, adjusting the network structure and network parameters, and then retraining the preliminary crack recognition model to obtain the optimal crack detection model; Step S6: construct a detection data set using the collected egg images, perform image preprocessing on them using grayscale, histogram equalization and bilateral filtering, pass the preprocessed egg images into the optimal crack recognition model, and output the image detection results.
2. The crack egg detection method based on CNN according to claim 1, characterized in that: In step S3, a ResNet deep residual neural network crack detection model is constructed using a residual network guided by two consecutive attentions.
3. The crack egg detection method based on CNN as claimed in claim 2, characterized in that: The construction of the ResNet deep residual neural network crack detection model includes: Construct the first ResNet unit, set the first attention mechanism after the first ResNet unit, construct the second ResNet unit after the first attention mechanism, set the second attention mechanism after the second ResNet unit, use local average pooling after the second attention mechanism to reduce the number of connection layer parameters, after the local average pooling, use the fully connected layer for feature integration, and finally the output layer uses the softmax activation function to output the detection results.
4. The crack egg detection method based on CNN as claimed in claim 3, characterized in that: The first ResNet unit and the second ResNet unit each include two consecutive convolution kernels, and the convolution kernel size is 3x3.
5. The crack egg detection method based on CNN as claimed in claim 3, characterized in that: The first ResNet unit and the second ResNet unit can set the part of the feature map that does not belong to the target to zero by multiplying the mask map with the feature map, thereby retaining only the features of the target area.
6. The crack egg detection method based on CNN according to claim 3, characterized in that: The first-channel attention mechanism and the second-channel attention mechanism both perform local average pooling and local maximum pooling operations on the input feature map. The one-dimensional feature vectors obtained by the two pooling operations are merged and encoded using a multi-layer perceptron. The encoding results are passed through a Sigmoid activation function to obtain a vector representing the weight of each channel.
7. The crack egg detection method based on CNN according to claim 6, characterized in that: The encoding using a multi-layer perceptron includes encoding a one-dimensional feature vector input into an output space of a fixed dimension.
8. The crack egg detection method based on CNN according to claim 3, characterized in that: The use of a fully connected layer for feature integration includes: the fully connected layer outputs a classification score vector, in which each element corresponds to the score of a category.
9. The crack egg detection method based on CNN according to claim 8, characterized in that: The output layer outputs the detection result using the softmax activation function, including: converting the score vector into a probability distribution through the softmax activation function.
10. The cracked egg detection method based on CNN according to claim 9, characterized in that: The preprocessed egg image is passed into the optimal crack recognition model, and the image detection result is output, including: comparing the probability output by softmax with a preset value, when the probability is greater than the preset value, it is determined that cracks appear in the egg, otherwise, it is determined that no cracks appear.
Citation Information
Patent Citations
Automated egg quality inspection system
KR102283869B1