A method and system for counting cereal grains

By employing dual-frequency structured light phase-shifting fringe imaging technology and a geometric centroid error correction model, the problems of illumination variation and grain stacking and adhesion in grain detection and counting have been solved, achieving high-precision, fast, and stable detection and counting, applicable to a variety of grains.

CN122115375APending Publication Date: 2026-05-29ANHUI AGRICULTURAL UNIVERSITY
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ANHUI AGRICULTURAL UNIVERSITY
Filing Date
2026-02-11
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing technologies for grain detection and counting suffer from a difficulty in balancing accuracy, speed, and stability, especially when ambient light changes or when grains are stacked or stuck together, resulting in decreased accuracy and efficiency.

Method used

The dual-frequency structured light phase-shifting fringe imaging technology is adopted. The low-frequency fringes enhance the anti-interference ability and the high-frequency fringes achieve high-precision phase measurement. Accurate counting is achieved by phase difference, gray-scale hole filling and adaptive threshold processing, combined with the geometric centroid error correction model.

Benefits of technology

Achieving high-precision and rapid grain detection and counting in complex environments significantly reduces interference from changes in ambient light, minimizes false detections and missed detections, improves robustness and automation, and increases counting efficiency by more than 50 times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122115375A_ABST
    Figure CN122115375A_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of agricultural automation detection, and discloses a grain counting method, which comprises the following steps: S1, an image acquisition system is built, the system comprises an industrial camera, a stripe projector, a fixed support and a background plate; the optical center of the industrial camera and the stripe projector are adjusted to be coplanar, and the stripe projector is made to project perpendicularly to the background plate; a double-frequency structured light phase shift stripe image of a background without grain is acquired, and a double-frequency structured light phase shift stripe image of a scene containing the grain is acquired. The application adopts a double-frequency structured light phase shift stripe imaging technology, has high anti-interference ability to noise, environmental light changes and uneven surface reflection through a low-frequency stripe enhancement system, and realizes high-precision phase measurement in combination with a high-frequency stripe, so that the problem that a traditional RGB image is easily affected by light changes is effectively overcome.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of agricultural automation detection technology, specifically a method and system for counting grains. Background Technology

[0002] Grains come in many varieties, including wheat, corn, rice, soybeans, and oats. They are not only a staple food for most of the world's population but are also widely used in animal feed, oilseeds, and industrial raw materials. During grain production and processing, the quality and quantity of grain grains directly determine crop yield and market value. Therefore, accurate detection and counting of grains are of great practical significance for improving agricultural production efficiency and ensuring food quality.

[0003] Traditional methods for detecting and counting grain grains rely heavily on manual operation and simple mechanical equipment. While these methods are easy to operate, they suffer from high costs, low efficiency, large errors, and susceptibility to human interference. Furthermore, these methods are not only inefficient but also fail to meet the demands of precision agriculture in large-scale production.

[0004] Currently, grain detection and counting mainly rely on spectral analysis and machine vision technology. For example, Chinese patent document CN121275688A discloses a soybean detection method based on near-infrared spectroscopy. This method determines the sample type by extracting near-infrared spectral classification index values ​​of soybean samples, and selects a preprocessing model and detection model based on the type to obtain relevant soybean detection parameters. In addition, the paper "Transactions of the Chinese Society of Agricultural Engineering, 2026, 42(2): 1-10" proposes an improved model based on YOLOv8n. This model combines an attention mechanism, a lightweight module, and an optimized loss function to achieve real-time online monitoring of rice grains.

[0005] However, existing technologies have not yet achieved an ideal balance between accuracy, speed, and stability. While spectral analysis methods offer high accuracy, data processing is complex and slow. Machine learning methods based on RGB images are susceptible to changes in ambient lighting and struggle to accurately distinguish grains when they are stacked or stuck together, leading to decreased detection accuracy and efficiency. Therefore, there is an urgent need for a grain detection and counting method that can balance efficiency, accuracy, and stability to meet the technological demands of modern agricultural production for efficient, precise, and stable detection and counting. Summary of the Invention

[0006] The purpose of this invention is to provide a method and system for counting grains, which aims to solve the above-mentioned problems in the prior art. This method can significantly reduce the interference of changes in ambient light and can still achieve accurate and rapid detection and counting even in cases of overlapping grains and complex backgrounds.

[0007] Therefore, the present invention proposes a method for counting grains, comprising the following steps:

[0008] S1. Construct an image acquisition system, which includes an industrial camera, a stripe projector, a fixed bracket, and a background plate; adjust the optical centers of the industrial camera and the stripe projector to be coplanar, and make the stripe projector perpendicular to the background plate for projection; acquire dual-frequency structured light phase-shifting stripe images of a background without grains and dual-frequency structured light phase-shifting stripe images of a scene containing grains.

[0009] S2. Filter and preprocess the dual-frequency structured light phase-shifting fringe image of the background to obtain the absolute high-frequency phase distribution of the background; perform phase calculation and region division on the dual-frequency structured light phase-shifting fringe image of the scene to obtain the absolute high-frequency phase distribution of the scene.

[0010] S3. Calculate the difference between the absolute high-frequency phase distribution of the scene and the absolute high-frequency phase distribution of the background to obtain a seed phase map; perform grayscale hole filling processing on the seed phase map, and obtain a filled phase map reflecting the seed protrusion characteristics by performing difference operation on the phase maps before and after filling.

[0011] S4. Based on the filled phase map, an adaptive thresholding method is used to perform image binarization processing. After morphological processing, connected regions are extracted, and the geometric centroid position of each connected region is calculated.

[0012] S5. The geometric centroid positions are jointly judged and screened using a geometric centroid error correction model, and the number of grains is counted based on the number of valid centroids retained.

[0013] Furthermore, in step S1, the dual-frequency structured light phase-shifting fringe image includes a high-frequency fringe image and a low-frequency fringe image; wherein, the low-frequency fringe image is used to improve the system's anti-interference capability and provide periodic constraints for high-frequency phase unwrapping, and the high-frequency fringe image is used to provide high-precision phase measurement information; when acquiring the background image and the scene image, the spatial frequency, phase shift step number, and projection order of the dual-frequency structured light fringes are kept consistent.

[0014] Furthermore, in step S2, the filtering and phase preprocessing of the background phase-shifted stripe image specifically includes:

[0015] Gaussian filtering was applied to the high-frequency and low-frequency phase-shifted stripe images of the background, respectively.

[0016] Based on the N-step phase shift method, the high-frequency truncation phase and low-frequency truncation phase of the filtered image are calculated respectively.

[0017] Based on a preset modulation threshold, a first mask region is constructed;

[0018] Within the first mask region, the high-frequency truncated phase is unwrapped using the absolute low-frequency phase corresponding to the low-frequency truncated phase, thereby obtaining the absolute high-frequency phase distribution of the background.

[0019] Furthermore, in step S2, the phase calculation and region division of the phase-shifting fringe image of the scene specifically includes:

[0020] Based on the N-step phase shift method, the high-frequency truncated phase and low-frequency truncated phase of the object scene image are calculated respectively;

[0021] A second mask region is constructed based on a preset modulation threshold and after morphological erosion.

[0022] Within the second mask region, the high-frequency truncated phase is unwrapped using the absolute low-frequency phase corresponding to the low-frequency truncated phase, thereby obtaining the absolute high-frequency phase distribution of the scene.

[0023] Furthermore, in step S3, the grayscale hole filling process specifically involves: identifying hole regions in the seed phase map, and replacing the phase values ​​of all pixels within each hole region with the maximum value of the phase values ​​of the pixels at the hole boundary.

[0024] Furthermore, in step S4, the adaptive thresholding method specifically involves dynamically calculating the binarization segmentation threshold based on the ratio of the median to the maximum value of the pixel values ​​in the effective region of the filled phase map, and the average value of the pixel values ​​in the effective region.

[0025] Furthermore, in step S4, the geometric centroid position of each connected region is calculated, specifically by taking the arithmetic mean of the coordinates of all pixels within the connected region as the geometric centroid position of that connected region.

[0026] Furthermore, in step S5, the geometric centroid error correction model includes a region shape error correction module, a neighborhood conflict error correction module, and a mapping verification module.

[0027] The region shape correction module is used to remove the centroids corresponding to abnormal regions based on the preset area range and shape ratio range of the connected regions, and to estimate the number of seeds in large connected regions.

[0028] The neighborhood conflict correction module is used to calculate the Euclidean distance between any two centroids. When the distance is less than a preset threshold, the centroid with the smaller corresponding convex feature intensity or connected region area is removed.

[0029] The mapping verification module is used to map the centroid to the effective phase region and remove centroids located outside the effective region.

[0030] Furthermore, in step S1, the fixed bracket includes a main fixed bracket, a secondary bracket, and an optical axis cross clamp; the industrial camera and the stripe projector are mounted on the secondary bracket, and the secondary bracket is vertically connected to the main fixed bracket through the optical axis cross clamp to achieve height and horizontal position adjustment.

[0031] This invention also proposes a grain grain detection and counting system for implementing the aforementioned grain grain detection and counting method, comprising:

[0032] The image acquisition module is used to build the system and acquire dual-frequency structured light phase-shifting fringe images of the background and the scene.

[0033] The phase processing module is used to process the background and scene images separately, obtain their respective absolute high-frequency phase distributions, and calculate and generate a filled phase map that reflects the protruding features of the grains.

[0034] The feature extraction module is used to perform binarization, morphological processing, and connected region analysis on the filled phase map, and extract the geometric centroid position of each connected region;

[0035] The error correction and counting module is used to filter valid centroids through the geometric centroid error correction model and complete the counting based on the number of valid centroids.

[0036] Compared with the prior art, the beneficial effects of the present invention are:

[0037] This invention employs dual-frequency structured light phase-shifting fringe imaging technology. By enhancing the anti-interference ability of the low-frequency fringe system against noise, ambient light changes, and surface reflection inhomogeneity, and combining it with high-frequency fringe to achieve high-precision phase measurement, it effectively overcomes the problem that traditional RGB images are easily affected by changes in illumination.

[0038] This invention, through phase difference, grayscale hole filling and adaptive threshold processing, can significantly distinguish the boundaries between seeds and background, and between seeds themselves. Even when seeds are stacked, adhered or have a complex distribution, it can still achieve high-precision detection and reduce false detections and missed detections.

[0039] This invention constructs a multi-module centroid correction model that includes region shape correction, neighborhood conflict correction, and mapping verification. It can automatically eliminate false centroids, abnormal centroids, and duplicate detection results without manual intervention, significantly improving the robustness and automation level of the system.

[0040] The method proposed in this invention, by adjusting parameters such as region area, shape ratio, and distance threshold, can be applied to the detection and counting of various grains such as wheat, corn, soybeans, rice, and oats, and has good versatility and scalability. Attached Figure Description

[0041] Figure 1 This is an overall flowchart of the grain grain detection and counting method provided in the embodiments of the present invention;

[0042] Figure 2 This is a schematic diagram of the image acquisition system in an embodiment of the present invention;

[0043] Figure 3 This is an example of a single-background phase-shifting fringe image and a scene phase-shifting fringe image containing seeds, obtained in an embodiment of the present invention.

[0044] Figure 4 This is a truncated phase image of a single background and scene obtained by phase shifting method in an embodiment of the present invention;

[0045] Figure 5 This is the absolute phase image of a single background and scene obtained after phase unwrapping in the embodiments of the present invention;

[0046] Figure 6 This is a schematic diagram of the first mask region M1 and the second mask region M2 constructed in an embodiment of the present invention;

[0047] Figure 7 This is a schematic diagram illustrating the process of obtaining a filled phase map from a seed phase map through grayscale hole filling and differential operation in an embodiment of the present invention;

[0048] Figure 8 This is a schematic diagram illustrating the extraction of connected regions from a binarized image and the calculation of the geometric centroid position in an embodiment of the present invention;

[0049] Figure 9 This is a flowchart of the geometric centroid error correction model in an embodiment of the present invention;

[0050] Figure 10 This is a visual schematic diagram of the final detection and counting results in an embodiment of the present invention. Detailed Implementation

[0051] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0052] This invention discloses a method for counting grain grains. In this embodiment, an industrial area scan camera with a resolution of 2048×1536 and a digital stripe projector with a projection resolution of 1920×1080 are selected as the core devices for image acquisition. A black matte horizontal background is selected as the background. All operations are completed in a laboratory environment with normal temperature and pressure. The grain grains to be detected are wheat grains. For the detection and counting of other grains such as corn, soybeans, rice, oats, etc., only the relevant threshold parameters need to be adjusted according to the shape and size of the grains themselves. The remaining steps are the same as in this embodiment.

[0053] The grain grain detection and counting method of the present invention is based on an image acquisition system consisting of an industrial camera, a stripe projector, and a fixed bracket. The fixed bracket includes a main fixed bracket, a secondary bracket, and an optical axis cross clamp. The industrial camera and the stripe projector are both mounted on the secondary bracket. The secondary bracket is vertically connected to the main fixed bracket through the optical axis cross clamp, which allows for flexible adjustment of the height of the secondary bracket and the horizontal position of the industrial camera and the stripe projector. Ultimately, the optical centers of the camera and the projector are coplanar, and the stripe projector can project perpendicular to a black matte horizontal background.

[0054] The method for detecting and counting grains proposed in this embodiment includes the following steps:

[0055] S1. Construct an image acquisition system, which includes an industrial camera, a stripe projector, a fixed bracket, and a background plate; adjust the optical centers of the industrial camera and the stripe projector to be coplanar, and make the stripe projector perpendicular to the background plate for projection; acquire dual-frequency structured light phase-shifting stripe images of a background without grains and dual-frequency structured light phase-shifting stripe images of a scene containing grains.

[0056] More specifically, following the connection method of the fixed bracket described above, complete the installation and debugging of the industrial camera and stripe projector. Adjust the height and horizontal position of the sub-bracket using the optical axis cross clamp to ensure that the optical centers of the industrial camera and the stripe projector are on the same horizontal reference plane. At the same time, adjust the projection angle of the stripe projector to ensure that it can project perpendicularly to the black horizontal background board, thus completing the construction of the image acquisition system.

[0057] Dual-frequency structured light stripes (including high-frequency and low-frequency stripes) are projected onto the background. In this embodiment, the low-frequency stripes are used to improve the system's anti-interference capability and to periodically constrain the high-frequency phase, while the high-frequency stripes are used to provide high-precision phase measurement. The mathematical expressions for the light intensity of the high- and low-frequency structured light phase-shifting stripes can be expressed as follows:

[0058]

[0059]

[0060] In the formula: and Represents the high- and low-frequency structured light phase-shifting fringe images in pixel coordinates The light intensity value at that location, Indicates average intensity. Indicates modulation intensity; and This represents the high- and low-frequency truncated phases to be solved; Indicates the first The phase shift amount corresponding to each phase shift.

[0061] It should be noted that the low-frequency structured light stripes are used to improve the system's resistance to noise, ambient light variations, and surface reflection inhomogeneities, and to periodically constrain the high-frequency phase results; the high-frequency structured light stripes are used to provide high-precision phase measurement information and ensure the stability of phase unwrapping. In this implementation, the spatial frequency parameters, phase shift steps, and projection order of the dual-frequency structured light stripes remain consistent throughout the experiment and measurement process. In this embodiment, the spatial frequency of the high-frequency stripes is taken as 0.05 pixels. -1 The spatial frequency of the low-frequency stripes is taken as 0.01 pixels. -1 Phase shift steps Choose 4.

[0062] During the implementation process, the background board was first left empty of any grains. The positions of the sub-support and camera system were then fine-tuned using the optical axis cross clamp to precisely align the center of the projected stripes with the center of the background board. After alignment, the sub-support and camera system were fixedly installed to avoid errors introduced by relative displacement of the system during subsequent image acquisition. Subsequently, a background phase-shifted stripe image without any grains was acquired. Next, randomly select a number of untreated wheat grains and spread them irregularly on the background board (allowing a small amount of stacking and adhesion of the grains). Maintain the spatial frequency, phase shift step number, and projection order of the dual-frequency structured light stripes exactly the same as when acquiring the background image. Then, project the structured light stripes again and acquire an image of the scene containing the grains, showing the phase shift stripes of the object. .

[0063] S2. Filter and preprocess the dual-frequency structured light phase-shifting fringe image of the background to obtain the absolute high-frequency phase distribution of the background; perform phase calculation and region division on the dual-frequency structured light phase-shifting fringe image of the scene to obtain the absolute high-frequency phase distribution of the scene.

[0064] In detail, in this step, a differential processing method is used for the background phase-shifting fringe image and the object scene phase-shifting fringe image to ultimately obtain the absolute high-frequency phase of the background. absolute high frequency phase of the scene The core processing includes operations such as Gaussian filtering, truncated phase calculation, mask region construction, and phase unwrapping.

[0065] In this implementation, the background phase-shifted stripe image is processed as follows:

[0066] 1. Gaussian filtering: For the acquired background phase-shifted stripe image. In this embodiment, a Gaussian filter is applied. The filter formula is as follows:

[0067]

[0068]

[0069] In the formula, This represents the convolution operation. The standard deviation of the Gaussian filter kernel (in this embodiment) Take 1.5). The filtered background phase-shifted stripe image is denoted as... , .

[0070] 2. Truncation Phase Calculation: In this embodiment, the truncated phase is calculated using an N-step phase-shift method for the filtered background phase-shifted fringe image. The formula is as follows:

[0071]

[0072] In the formula, For the number of phase shift steps, Background phase-shifted stripe image after filtering , The high-frequency cutoff phase of the background was calculated. Low-frequency truncated phase And map all phase values ​​to The standard range.

[0073] 3. First mask region construction: Set modulation threshold (In this embodiment) (Using a value of 0.3), the mask regions of the high-frequency and low-frequency stripe phase-shifted images of the background are extracted respectively. A logical AND operation is performed on the two mask regions to construct the first mask region. .

[0074] 4. Phase unwrapping to obtain absolute high-frequency phase: in the first mask region Internally, the phase unwrapping formula is used, combined with the absolute low-frequency phase, to unwrap the high-frequency truncated phase. The formula is as follows:

[0075]

[0076] In the formula, This represents the rounding function. These represent the spatial periods of the high-frequency and low-frequency fringes, respectively. Since the low-frequency fringe contains only one fringe period, its absolute low-frequency phase... Low-frequency cutoff phase Equal, that is After substituting the values ​​into the calculation, the absolute high-frequency phase of the background is obtained. .

[0077] In this implementation, the processing of the scene phase-shifting fringe image is as follows:

[0078] 1. Truncation Phase Calculation: Calculate the phase-shifted fringe image of the acquired scene. Without performing Gaussian filtering, the truncated phase is directly calculated using the N-step phase shifting method formula described above, thus obtaining the high-frequency truncated phase of the scene. Low-frequency truncated phase And map the phase value to The standard range, the absolute low-frequency phase of the scene. .

[0079] 2. Second mask region construction: using the same modulation threshold as the background phase-shifted stripe image. The mask regions of the high-frequency and low-frequency stripe phase-shifted images of the extracted scene are extracted and subjected to a logical AND operation. The resulting mask regions are then subjected to morphological erosion processing (in this embodiment, a 3×3 rectangular structural element is used for erosion) to remove unstable regions such as seed edge stripe distortion and occlusion, and a second mask region is constructed. .

[0080] 3. Phase unwrapping to obtain absolute high-frequency phase: in the second mask region Substituting the phase unwrapping formula above, and combining it with the absolute low-frequency phase of the scene... High-frequency phase cutoff Unwrap the object to obtain its absolute high-frequency phase. .

[0081] S3. Calculate the difference between the absolute high-frequency phase distribution of the scene and the absolute high-frequency phase distribution of the background to obtain a seed phase map; perform grayscale hole filling processing on the seed phase map, and obtain a filled phase map reflecting the seed protrusion characteristics by performing a difference operation on the phase maps before and after filling. More detailed, refer to the following steps:

[0082] 1. Calculate the seed phase map: In this embodiment, the absolute high-frequency phase difference between the scene and the background is calculated to obtain a seed phase map containing only the effective measurement area. The formula is:

[0083]

[0084] 2. Grayscale hole filling: This involves analyzing the phase map of the grains. The grayscale hole filling process is performed using the following formula:

[0085]

[0086] In the formula, This represents the h-th hole region. This represents all pixels at the boundary of the hole. The phase diagram is obtained by taking the maximum phase value and filling it in. .

[0087] 3. Obtain the filled phase map using differential operations: The filled phase map... Phase diagram with original grain Performing a difference operation yields a filled phase map that reflects the protrusion characteristics of the grains. The formula is:

[0088]

[0089] All calculations in this step are performed in the second mask region. The internal filling operation can effectively eliminate most of the adhesion boundaries between grains, highlighting the raised structural features of the grains.

[0090] S4. Based on the filled phase map, an adaptive thresholding method is used for image binarization. After morphological processing, connected regions are extracted, and the geometric centroid positions of each connected region are calculated. More specifically, the following steps are followed:

[0091] 1. Adaptive Threshold Binarization: Based on Filled Phase Map Construct an adaptive threshold model to generate a binary threshold. The formula is:

[0092]

[0093] Where the proportionality coefficient The calculation formula is:

[0094]

[0095] In the formula, Indicates the second mask area Number of pixels in the effective area To fill the median of the phase map, To fill the phase map with the maximum value; fill the phase map with the maximum value. Medium pixel value greater than The area is set to 255 (white, target area), and the pixel value is less than... Set the region to 0 (black, background area) to complete the binarization process.

[0096] 2. Morphological Opening Operation: A morphological opening operation is performed on the binarized image (in this embodiment, a 2×2 rectangular structuring element is used, with erosion followed by dilation) to remove incomplete and discontinuous pseudo-structures in the image, obtaining a binary image containing only the effective target of grain grains. .

[0097] 3. Extract connected components and calculate geometric centroids: For binary images Perform connected component analysis to extract all independent connected components; then use the formula in claim 8 to calculate the geometric centroid position of each connected component. The formula is:

[0098]

[0099] In the formula, This represents the number of pixels in the i-th connected region. Let be the geometric centroid coordinates of the i-th connected region.

[0100] S5. The geometric centroid positions are jointly judged and screened using the geometric centroid error correction model, and the number of grains is counted based on the number of valid centroids retained.

[0101] More specifically, in this embodiment, a geometric centroid error correction model is constructed. This model includes a region shape error correction module, a neighborhood conflict error correction module, and a mapping verification module. The geometric centroids obtained in the above steps are jointly judged and pseudo-centroids are removed, retaining only the true and valid grain centroids. Finally, the number of valid centroids is counted. The specific operations of each module are as follows:

[0102] (1) Region shape correction module;

[0103] The area range (80-150 pixels in this example) and shape ratio (1:1-3:1 aspect ratio) of the normal connected regions of the wheat grains to be tested were statistically analyzed in advance through multiple experiments.

[0104] 1. Regions with a connected area of ​​less than 80 pixels and a shape ratio exceeding the range of 1:1 to 3:1 are identified as false targets, and their corresponding geometric centroids are marked as false centroids and directly removed.

[0105] 2. If the area of ​​the connected region is significantly larger than the normal range (greater than 300 pixels in this embodiment) and presents a continuous structure, it is determined to be a grain stacking / covering area. By calculating the ratio of the area of ​​this region to the average area of ​​the normal connected region of wheat grains (115 pixels in this embodiment), the number of effective centroids corresponding to this region is approximately estimated.

[0106] (2) Neighborhood conflict correction module;

[0107] For the remaining centroids after region shape correction, calculate any two centroids. Euclidean distance between The formula is:

[0108]

[0109] Set Euclidean distance threshold (In this embodiment, 10 pixels are used) When When a conflict is determined between two centroids, the centroid with the smaller corresponding convex strength or connected region area is removed, while the centroid with the larger convex strength or region area is retained.

[0110] (3) Mapping verification module;

[0111] The centroid set after the first two error correction modules is mapped to the second mask region. Inside, determine one by one whether the coordinates of each centroid fall within the range of... Within the valid pixel area, remove all pixels located in... The centroids outside the effective region are used to obtain the final set of effective centroids.

[0112] (4) Counting of grains;

[0113] The number of centroids in the above effective centroid set is counted, and this number is the actual number of grains on the background plate, thus completing the accurate detection and counting of grains.

[0114] It is worth mentioning that this embodiment uses wheat grains as the detection object. If it is necessary to detect other grains such as corn, soybeans, rice, and oats, it is only necessary to adjust the area threshold and shape ratio threshold in the region shape correction module, and the Euclidean distance threshold in the neighborhood conflict correction module according to the actual shape and size of the grains. The remaining steps, calculation formulas, and operation methods are completely consistent with this embodiment, and can all achieve high-precision and high-robust detection and counting.

[0115] The grain grain detection and counting method of this invention significantly reduces the interference of ambient light changes on detection by using phase processing technology of dual-frequency structured light phase-shifting fringes, solving the problems of false detection and missed detection caused by grain stacking and adhesion in traditional machine vision technology. At the same time, it highlights the characteristic information of grains by operations such as gray-scale hole filling and adaptive threshold binarization. Combined with a geometric centroid error correction model composed of three major modules, it achieves accurate removal of false centroids. Finally, under the condition of complex distribution of grain grains, it achieves fast, accurate and stable detection and counting with a detection accuracy of over 99% and a counting efficiency that is more than 50 times higher than manual counting. It is suitable for grain grain detection and counting scenarios in large-scale agricultural production.

[0116] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0117] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0118] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical or other forms.

[0119] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0120] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0121] If the aforementioned integrated units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0122] The embodiments of the present invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the embodiments above are only for helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for counting grain kernels, characterized in that, Includes the following steps: S1. Construct an image acquisition system, which includes an industrial camera, a stripe projector, a fixed bracket, and a background plate; adjust the optical centers of the industrial camera and the stripe projector to be coplanar, and make the stripe projector perpendicular to the background plate for projection; acquire dual-frequency structured light phase-shifting stripe images of a background without grains and dual-frequency structured light phase-shifting stripe images of a scene containing grains. S2. Filter and preprocess the dual-frequency structured light phase-shifting fringe image of the background to obtain the absolute high-frequency phase distribution of the background; perform phase calculation and region division on the dual-frequency structured light phase-shifting fringe image of the scene to obtain the absolute high-frequency phase distribution of the scene. S3. Calculate the difference between the absolute high-frequency phase distribution of the scene and the absolute high-frequency phase distribution of the background to obtain a seed phase map; perform grayscale hole filling processing on the seed phase map, and obtain a filled phase map reflecting the seed protrusion characteristics by performing difference operation on the phase maps before and after filling. S4. Based on the filled phase map, an adaptive thresholding method is used to perform image binarization processing. After morphological processing, connected regions are extracted, and the geometric centroid position of each connected region is calculated. S5. The geometric centroid positions are jointly judged and screened using a geometric centroid error correction model, and the number of grains is counted based on the number of valid centroids retained.

2. The method for detecting and counting grains according to claim 1, characterized in that, In step S1, the dual-frequency structured light phase-shifting fringe image includes a high-frequency fringe image and a low-frequency fringe image; wherein, the low-frequency fringe image is used to improve the system's anti-interference capability and provide periodic constraints for high-frequency phase unwrapping, and the high-frequency fringe image is used to provide high-precision phase measurement information; when acquiring the background image and the object scene image, the spatial frequency, phase shift step number, and projection order of the dual-frequency structured light fringes are kept consistent.

3. The method for detecting and counting grains according to claim 1 or 2, characterized in that, In step S2, the filtering and phase preprocessing of the background phase-shifted stripe image specifically includes: Gaussian filtering was applied to the high-frequency and low-frequency phase-shifted stripe images of the background, respectively. Based on the N-step phase shift method, the high-frequency truncation phase and low-frequency truncation phase of the filtered image are calculated respectively. Based on a preset modulation threshold, a first mask region is constructed; Within the first mask region, the high-frequency truncated phase is unwrapped using the absolute low-frequency phase corresponding to the low-frequency truncated phase, thereby obtaining the absolute high-frequency phase distribution of the background.

4. The method for detecting and counting grains according to claim 1 or 2, characterized in that, In step S2, the phase calculation and region division of the phase-shifted fringe image of the scene specifically includes: Based on the N-step phase shift method, the high-frequency truncated phase and low-frequency truncated phase of the object scene image are calculated respectively; A second mask region is constructed based on a preset modulation threshold and after morphological erosion. Within the second mask region, the high-frequency truncated phase is unwrapped using the absolute low-frequency phase corresponding to the low-frequency truncated phase, thereby obtaining the absolute high-frequency phase distribution of the scene.

5. The method for detecting and counting grain grains according to claim 1, characterized in that, In step S3, the grayscale hole filling process specifically involves: identifying hole regions in the seed phase map and replacing the phase values ​​of all pixels within each hole region with the maximum value of the phase values ​​of the pixels at the hole boundary.

6. The method for detecting and counting grains according to claim 1, characterized in that, In step S4, the adaptive thresholding method specifically involves dynamically calculating the binarization segmentation threshold based on the ratio of the median to the maximum value of the pixel values ​​in the effective region of the filled phase map, and the average value of the pixel values ​​in the effective region.

7. The method for detecting and counting grains according to claim 1, characterized in that, In step S4, the geometric centroid position of each connected region is calculated. Specifically, the arithmetic mean of the coordinates of all pixels within the connected region is used as the geometric centroid position of the connected region.

8. The method for detecting and counting grains according to claim 1, characterized in that, In step S5, the geometric centroid error correction model includes a region shape error correction module, a neighborhood conflict error correction module, and a mapping verification module; The region shape correction module is used to remove the centroids corresponding to abnormal regions based on the preset area range and shape ratio range of the connected regions, and to estimate the number of seeds in large connected regions. The neighborhood conflict correction module is used to calculate the Euclidean distance between any two centroids. When the distance is less than a preset threshold, the centroid with the smaller corresponding convex feature intensity or connected region area is removed. The mapping verification module is used to map the centroid to the effective phase region and remove centroids located outside the effective region.

9. The method for detecting and counting grains according to claim 1, characterized in that, In step S1, the fixed bracket includes a main fixed bracket, a secondary bracket, and an optical axis cross clamp; the industrial camera and the stripe projector are mounted on the secondary bracket, and the secondary bracket is vertically connected to the main fixed bracket through the optical axis cross clamp to achieve height and horizontal position adjustment.

10. A grain grain detection and counting system, used to implement the grain grain detection and counting method according to any one of claims 1 to 9, characterized in that, include: The image acquisition module is used to build the system and acquire dual-frequency structured light phase-shifting fringe images of the background and the scene. The phase processing module is used to process the background and scene images separately, obtain their respective absolute high-frequency phase distributions, and calculate and generate a filled phase map that reflects the protruding features of the grains. The feature extraction module is used to perform binarization, morphological processing, and connected region analysis on the filled phase map, and extract the geometric centroid position of each connected region; The error correction and counting module is used to filter valid centroids through the geometric centroid error correction model and complete the counting based on the number of valid centroids.

Citation Information

Patent Citations

  • Soybean detection method and device based on near infrared spectrum and storage medium

    CN121275688A