Color feature analysis-based egg detection and classification method, product and equipment
By using a color feature analysis method, industrial cameras and color judgment trees are employed for egg detection and classification, solving the problems of low efficiency and high misjudgment rate in existing technologies, and achieving high-precision, automated egg sorting and data-driven management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XICHANG COLLEGE
- Filing Date
- 2026-02-11
- Publication Date
- 2026-05-19
AI Technical Summary
Existing egg sorting technologies suffer from problems such as low efficiency, high misjudgment rate, numerous interference factors, and difficulty in automation and data digitization. In particular, in industrial scenarios, existing YOLO series detection models cannot achieve high-precision color classification and statistics.
A color feature analysis-based method is used to acquire BGR images through an industrial camera and convert them into RGB images. The average values of H, S, and V within the bounding box are calculated, and classification is performed by combining the color decision tree. Confidence scores and statistical reports are then output to achieve automated detection and classification.
It achieves high-precision egg color classification with a misjudgment rate of less than 1.5% and a classification consistency of up to 97.2%, increasing efficiency to 120 eggs/second, reducing manual intervention, and supporting the continuity and data-driven management of the production line.
Smart Images

Figure CN122067016A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of egg sorting technology, specifically relating to an egg detection and classification method, product, and equipment based on color feature analysis. Background Technology
[0002] Currently, egg sorting production lines still rely primarily on manual sorting. Workers must inspect each eggshell color and classify them under strong light, a method with three major drawbacks. First, subjective judgment varies greatly: the color classification of the same batch of eggs is easily affected by the subjective judgment of different workers and changes in the angle of light, often resulting in misclassifications of similar colors such as "light brown" and "normal brown," making it difficult to guarantee classification consistency. Second, sorting efficiency is a bottleneck: even skilled workers can only sort at a maximum speed of 2 eggs per second, far from meeting the capacity requirements of large production lines of 60,000 eggs per hour, becoming a key constraint on capacity improvement. Third, there are many interfering factors on-site: interference from tray reflections, fecal matter on eggshell surfaces, residual feathers, and environmental shadows leads to a false detection rate of over 8% for traditional fixed threshold detection methods, and parameters need to be readjusted when the production line is changed, seriously affecting production continuity.
[0003] While existing YOLO detection models can locate eggs, in industrial scenarios they only output a binary judgment result of "whether there is an egg" without color category confidence data or the ability to generate classification statistical reports. Ultimately, they still need to rely on manual secondary verification and have not been able to completely eliminate reliance on manual labor.
[0004] In summary, the industry urgently needs an automated solution that integrates "detection, color classification, and statistics" to completely replace manual sorting and output eggshell color percentage data that can be directly integrated into ERP systems, providing data support for intelligent upgrading of production lines and optimization of production management. Summary of the Invention
[0005] The present invention aims to at least partially solve one of the technical problems in the aforementioned related technologies.
[0006] Therefore, the purpose of this invention is to provide an egg detection and classification method, product, and equipment based on color feature analysis, which can realize automated egg detection and classification and has the advantages of high precision and high efficiency.
[0007] To solve the above-mentioned technical problems, the present invention is implemented as follows: This invention provides a method for egg detection and classification based on color feature analysis, the method comprising: S1: Acquire BGR images using an industrial camera, then perform channel swapping to obtain RGB images; S2: Normalize the RGB pixels to [0,1], then convert them to HSV pixel by pixel, and calculate the average H, S, and V values of the N pixels within the bounding box; S3: Normalize the calculated average value to 0-255, and then perform color classification. S4: Calculate the confidence level of each category based on the classification results; S5: Output the number of eggs of each type and the total number of eggs for a single image; S6: Accumulate the data from N images and calculate the percentage at the dataset level; S7: Generate a report containing bounding boxes, color categories, confidence levels, color percentages, and average egg counts to complete the detection process.
[0008] In addition, the egg detection and classification method based on color feature analysis according to the present invention may also have the following additional technical features: In some implementations, the formula for channel switching in step S1 is: ; In some implementations, the pixel-by-pixel conversion to HSV in step S2 is performed as follows: ; The average values of H, S, and V for N pixels within the bounding box are calculated as follows: in, i For the first i 1 pixel.
[0009] In some implementations, the criteria for color classification in step S3 include: White eggs: ; Light brown eggs: ; Dark brown eggs: ; Regular brown eggs: ; Unknown category: .
[0010] In some implementations, the confidence level in step S4 is calculated as follows: White: ; brown: ; Light brown and dark brown: ; unknown: .
[0011] In some implementations, the total number of eggs in step S5 is calculated as follows: ; in, c Indicates the first c kind, Indicates the first c The number of eggs, C This represents the set of egg types in the image.
[0012] In some implementations, the dataset-level percentage calculation method in step S6 is as follows: ; in, C This represents the corresponding set of egg types. c Indicates the first c kind, c’ Indicates the first c 'kind.
[0013] In some of these implementations, the average number of eggs in step S7 The calculation method is as follows: ; in, N Indicates the number of terms in the summation; This represents the number of eggs corresponding to the j-th image.
[0014] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the egg detection and classification method based on color feature analysis as described in any of the preceding embodiments.
[0015] This invention also provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the egg detection and classification method based on color feature analysis as described in any of the preceding embodiments.
[0016] Compared with the prior art, the present invention has at least the following beneficial effects: In this embodiment of the invention, the egg detection and classification method based on color feature analysis provides the following steps: After the industrial camera acquires a BGR image, it performs channel switching through a fixed formula to convert it into an RGB image. This standardizes the channel switching formula, avoids color deviation caused by differences in image formats from different devices, and improves the consistency of basic image data. After normalizing the RGB pixels to [0,1], each pixel is converted to the HSV color space. The average values of H, S, and V of N pixels within the bounding box are calculated. Compared to the RGB space, the HSV color space is closer to the human eye's perception of color and makes it easier to distinguish subtle color differences in the eggshell. Combined with the calculation of the average pixel value within the bounding box, it can effectively avoid the interference of local stains and reflections on the color judgment of a single pixel, laying the foundation for accurate classification in the future. In this embodiment of the invention, the egg detection and classification method based on color feature analysis provides a more comprehensive classification dimension compared to the traditional fixed single threshold method, which uses a three-dimensional threshold based on the normalized values of H, S, and V (0-255). Combined with thresholds calibrated from a massive number of samples, the color classification accuracy reaches 97.2%, exceeding the 92% level of manual sorting. The brown color family is refined into light brown, normal brown, and dark brown, solving the problem of misjudging "light brown" and "normal brown" in manual sorting and improving classification consistency. The threshold can be automatically recalculated to adapt to the color differences of different varieties and batches of eggs, reducing the cost of manual parameter adjustment when changing production lines and improving production line continuity. In this embodiment of the invention, the egg detection and classification method based on color feature analysis quantifies the reliability of color classification, provides an objective basis for judging boundary samples (such as eggs with colors between light brown and regular brown), and replaces manual subjective evaluation; different confidence limits are set for different categories to conform to the actual classification difficulty (such as white eggs have the highest classification accuracy and the highest confidence limit), making the results more valuable and reducing the cost of secondary verification; In this embodiment of the invention, the egg detection and classification method based on color feature analysis provides a lightweight color analysis module (i.e., the method of this invention) that is directly embedded after the YOLO series model locates the eggs. No additional independent network is required, so that the inference time of a single image is increased by only <2ms, avoiding the efficiency loss of secondary network inference. The single-thread detection speed reaches 120 eggs / s, which is far superior to the speed of 2 eggs / s of a skilled worker. In this embodiment of the invention, the egg detection and classification method based on color feature analysis provides a multi-parameter joint judgment based on the HSV color space, which avoids the influence of single interference factors such as tray reflection, feces, feathers, and shadows. It has strong anti-interference ability and a misclassification rate of <1.5% under light variation of 200-800 lux, reflective tray and feces interference, which is far lower than the 8% of the traditional fixed threshold method.
[0017] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0018] Figure 1 This is a flowchart of an egg detection and classification method based on color feature analysis, as disclosed in one embodiment of the present invention. Figure 2 This is a flowchart of a CNN model construction process disclosed in one embodiment of the present invention; Figure 3 This is a flowchart of a single image processing procedure disclosed in one embodiment of the present invention; Figure 4 This is a flowchart of the YOLO detection process disclosed in one embodiment of the present invention; Figure 5 This is a flowchart of a CNN classification and recognition process disclosed in one embodiment of the present invention. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings and specific examples and application scenarios.
[0021] This invention constructs a color judgment tree, mapping a three-dimensional threshold of brightness-saturation-hue into five categories: white, light brown, brown, dark brown, and unknown. The thresholds are statistically calibrated using 120,000 field samples and can be automatically recalculated with the production line. A piecewise linear confidence level is introduced, assigning a confidence interval of 0.30-0.95 to each color category, quantifying boundary samples that are difficult for humans to judge. After locating the cow face bounding box using YOLO, rapid feature extraction based on the HSV color space is performed on the detection area (using cv2.cvtColor and cv2.inRange to detect brown / black / white cow hair colors). By calculating the pixel proportion of each color mask, a piecewise linear function is used to map the proportion to the confidence interval, quantifying ambiguous samples that are difficult for humans to judge, achieving integrated detection-classification-statistics. The single-image inference time is increased by less than 2 ms, eliminating the need for a secondary network. Multi-threaded image reading and multi-process training are employed, with an 8-core CPU achieving an offline processing speed of 500 images / second. A JSON interface containing color proportions is output, which can be directly called by MES / ERP systems to complete egg production quality traceability.
[0022] Please see Figure 1As shown in the figure, in some embodiments of the present invention, a method for detecting and classifying eggs based on color feature analysis is provided, including the following steps: Step 1: Obtain a BGR image through an industrial camera, and complete channel exchange according to the following formula to obtain an RGB image; ; Step 2: Normalize the RGB pixels to [0, 1], and then convert them to HSV pixel by pixel according to the following formula, and calculate the average value of N pixels within the bounding box; ; where, i is the i th pixel.
[0023] Step 3: Normalize the calculated average value to 0 - 255, and then perform color decision tree classification according to the following formula: White eggs: ; Light brown eggs: ; Dark brown eggs: ; Ordinary brown eggs (first define the brown hue window): ; Unknown category: .
[0024] The uniqueness of the current threshold system lies in the triple design of "hierarchical lightness segmentation + two-dimensional intersection constraint + hue circular window": (1) The lightness V adopts an accurate stratification strategy. For white, V > 180 covers the brightest 7% interval (180 - 255), for light brown, 150 < V ≤ 180 covers the medium-highlight 12% interval, for ordinary brown, 100 < V ≤ 180 covers the medium-bright 31% interval, and for dark brown, 80 < V ≤ 100 covers the low-bright 8% interval. The four layers of V thresholds do not overlap at all and accurately correspond to the boundary of human visual perception; (2) The saturation S adopts two key demarcation points of 30 and 50. S < 50 defines "colorless" (white), and S > 30 defines "colored" (all brown systems), forming a mathematical segmentation of "gray - color"; (3) The hue H adopts a two-interval design brown_hue = (5 ≤ H ≤ 30) ∨ (H ≥ 170). Utilizing the surrounding characteristics of the HSV color ring (0° red is adjacent to 180° dark red), it completely covers the orange-red brown system, and light brown uniquely adopts a quadruple condition intersection (V > 150 ∧ V ≤ 180 ∧ S > 30 ∧ brown_hue) to strictly define the boundary samples, reducing the misjudgment of 95% of the fuzzy zones.
[0025] Step 4: Calculate the confidence levels for each category using the following formula: White: ; brown: ; : ; unknown: .
[0026] The above formula uses a tiered upper limit (white / brown 0.95 > light brown 0.90 > dark brown 0.80 > unknown 0.30) to reflect the decreasing recognition difficulty. The white two-dimensional weighted average V:S=75:50 reflects the dominant role of brightness, while brown... Symmetrical penalty with 140 as the optimal center – comparative verification: changing the white upper limit to 0.90 increases the false positive rate by +6%, changing the V weight to 60 increases it by +9%, changing the brown center to 120 increases it by +13%, changing the light brown upper limit to 0.95 increases it by +12%, changing the dark brown upper limit to 0.90 increases it by +14%, and changing the unknown baseline to 0.40 increases it by +11%, achieving a high-confidence sample accuracy of 98.3%. Any parameter adjustment causes a drop to 89%-95%, ensuring that the threshold selection reaches a local optimum. The white threshold is 0.95, and the calculation incorporates normalized brightness (…). ) and saturation ( The difference between the values considers the color distribution in the brightness and saturation spaces, ensuring that the confidence level is not affected by a single factor, but rather by a comprehensive consideration of multiple color features. Brown uses 0.95 as the threshold, but the calculation incorporates normalized saturation. The calculation of the absolute difference between the brightness and 140 is optimized for a specific color range of brown (brightness around 140, moderate saturation). The absolute difference measures how close the brightness is to the target value, improving the recognition accuracy of brown. Different thresholds (0.90 and 0.80) are used for light brown and dark brown, and the calculation is based on a linear transformation of normalized brightness. The calculation for light brown focuses on brightness above 100, while that for dark brown focuses on the overall brightness level. Different thresholds reflect the different distribution ranges of light brown and dark brown in the color space. By adjusting the thresholds, these two similar colors can be distinguished more accurately. The confidence level for unknown categories is directly set to a fixed value of 0.30 without complex calculations. When a color cannot be clearly classified into the above categories, a lower confidence level is assigned to represent the uncertainty of classification. This simplifies the handling of unknown categories and avoids assigning high confidence levels to uncertain classification results by using a low threshold.
[0027] The classification specificity of this invention: Different thresholds are used for different color categories (e.g., 0.95 for white and brown, 0.90 for light brown, 0.80 for dark brown, and 0.30 for unknown), reflecting the differences in the distribution of each color in the color space and the difficulty of classification. Multi-feature fusion: The confidence calculation for white and brown combines multiple features of brightness and saturation (e.g., the difference between normalized brightness and saturation, absolute difference, etc.), improving classification accuracy through multi-feature fusion. Uncertainty handling: Unknown categories use a fixed low threshold, explicitly representing the uncertainty of the classification result and avoiding misclassification.
[0028] Step 5: Output the number of eggs of each type from a single image. and total number ; c Indicates the first c kind; Step 6: Accumulate data from N images. Calculate the percentage of the dataset level according to the formula; .
[0029] Step 7: Generate data including bounding boxes, color categories, confidence levels, color percentages, and average egg count. The JSON / Excel report completes the testing process; .
[0030] After on-site verification with 50,000 samples, the system achieved a color classification accuracy of 97.2%, exceeding the 92% level of manual sorting. With a single-threaded sorting rate of 120 samples / second and a multi-threaded sorting rate of 500 samples / second, the system can save 6 sorting workers for the same production capacity. Under conditions of 200-800 lux, reflective trays, and interference from manure, the misclassification rate is less than 1.5%, demonstrating strong robustness. The system outputs the white / brown shell ratio in real time, which can be directly used for feed formulation and flock selection. It only requires a conventional industrial camera and edge box, and can be integrated into existing conveyor belts with zero light source and zero mechanical modification, resulting in extremely low implementation costs.
[0031] Any part of this invention not described in detail can be referred to in the prior art or in the art known to those skilled in the art. This embodiment does not limit such part and will not describe it in detail here.
[0032] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
Claims
1. A method for egg detection and classification based on color feature analysis, characterized in that, The method includes: S1: Acquire BGR images using an industrial camera, then perform channel swapping to obtain RGB images; S2: Normalize the RGB pixels to [0,1], then convert them to HSV pixel by pixel, and calculate the average H, S, and V values of the N pixels within the bounding box; S3: Normalize the calculated average value to 0-255, and then perform color classification. S4: Calculate the confidence level of each category based on the classification results; S5: Output the number of eggs of each type and the total number of eggs for a single image; S6: Accumulate the data from N images and calculate the percentage at the dataset level; S7: Generate a report containing bounding boxes, color categories, confidence levels, color percentages, and average egg counts to complete the detection process.
2. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, The formula for channel switching in step S1 is: 。 3. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, In step S2, the pixel-by-pixel conversion to HSV is performed as follows: ; The average values of H, S, and V for N pixels within the bounding box are calculated as follows: in, i For the first i 1 pixel.
4. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, The criteria for color classification in step S3 include: White eggs: ; Light brown eggs: ; Dark brown eggs: ; Regular brown eggs: ; Unknown category: 。 5. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, The confidence level in step S4 is calculated as follows: White: ; brown: ; Light brown and dark brown: ; unknown: 。 6. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, The total number of eggs in step S5 is calculated as follows: ; in, c Indicates the first c kind, Indicates the first c The number of eggs, C This represents the set of egg types in the image.
7. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, The calculation method for the dataset-level percentage in step S6 is as follows: 。 8. The egg detection and classification method based on color feature analysis according to claim 1, characterized in that, Average number of eggs in step S7 The calculation method is as follows: ; in, N Indicates the number of terms in the summation; This represents the number of eggs corresponding to the j-th image.
9. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the egg detection and classification method based on color feature analysis as described in any one of claims 1-8.
10. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the steps of the egg detection and classification method based on color feature analysis as described in any one of claims 1-8.