Garlic clove orientation machine vision automatic detection method, equipment and medium
By combining the illumination model with the surface normal vector calculation, the influence of illumination changes is eliminated, and the surface geometric information of garlic cloves is accurately extracted. This solves the problem of decreased recognition accuracy under uneven illumination conditions in existing methods, and achieves stable and accurate detection of the orientation of garlic cloves.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-03-13
AI Technical Summary
Existing methods for detecting the orientation of garlic cloves fail to fully utilize the three-dimensional geometric information of the object's surface and ignore the coupling effect of the illumination field and reflection characteristics. This leads to a decrease in recognition accuracy under uneven illumination conditions, making it difficult to accurately locate physiological key points such as the clove tip and root plate, thus limiting the stability of orientation judgment.
By collecting images of garlic cloves, establishing a system of linear equations for each pixel, calculating the surface vector magnitude, generating an albedo image and normalizing it, and defining the normal vector; binarizing the albedo image, calculating the centroid coordinates and principal axis direction; calculating the characteristic response maps of the clove tip and root plate, performing anomaly detection, and combining the illumination model with the calculation of the surface normal vector to eliminate the influence of illumination changes and extract the intrinsic geometric information of the garlic clove surface.
Under uneven lighting conditions, the stability and accuracy of garlic clove surface recognition were improved, key points of clove tip and root plate were accurately extracted, the accuracy and stability of orientation judgment were improved, and automated sorting operations were supported.
Smart Images

Figure CN121661036A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision technology, and in particular to a machine vision-based automatic detection method, equipment, and medium for the orientation of garlic cloves. Background Technology
[0002] With the development of automated agricultural product processing and intelligent sorting equipment, crop shape feature recognition technology based on machine vision has gradually become an important part of modern food processing. In industrial processes such as garlic deep processing, automatic peeling, grading and packaging, the accurate identification of garlic clove posture and orientation judgment directly determines the action accuracy and processing efficiency of subsequent mechanical execution modules.
[0003] Existing technologies still have significant shortcomings. Most methods do not fully utilize the three-dimensional geometric information of the object's surface and usually ignore the coupling effect of the illumination field and reflection characteristics, which leads to a decrease in the recognition accuracy of garlic clove edges and surface textures under uneven illumination conditions. Existing garlic clove localization methods based on regional distribution and shape moments can often only roughly estimate the main orientation, but it is difficult to accurately locate physiological key points such as the clove tip and root plate from complex shapes, thus limiting the stability of orientation judgment. Summary of the Invention
[0004] In view of the aforementioned existing problems, the inventors have proposed the present invention.
[0005] Therefore, this invention provides a machine vision-based automatic detection method, device, and medium for garlic clove orientation, which solves the problem that most methods do not fully utilize the three-dimensional geometric information of the object's surface and usually ignore the coupling effect of the illumination field and reflection characteristics, resulting in a decrease in the recognition accuracy of garlic clove edges and surface textures under uneven illumination conditions. Existing garlic clove positioning methods based on regional distribution and shape moments can often only roughly estimate the main orientation, but it is difficult to accurately locate physiological key points such as clove tips and root plates from complex shapes, thus limiting the stability of orientation judgment.
[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution:
[0007] In a first aspect, the present invention provides a machine vision-based automatic detection method for the orientation of garlic cloves, comprising,
[0008] Collect garlic clove images and preprocess them, establish a system of linear equations for the pixels, solve for the surface vector, calculate the magnitude of the surface vector, generate an albedo image, normalize the surface vector, and define it as a normal vector.
[0009] The albedo image is binarized to obtain an accurate binary mask. The zeroth and first moments of the accurate binary mask are calculated. Based on the ratio of the first moment to the zeroth moment, the centroid coordinates of the garlic clove region are obtained. The spatial distribution covariance matrix of the foreground region is constructed, and eigenvalue decomposition is performed to define the principal axis direction.
[0010] Calculate the projection distance of the pixel position relative to the centroid along the principal axis, define the candidate region of the lobe tip, calculate the divergence of the horizontal component of the surface normal vector of the pixels in the candidate region of the lobe tip, define the comprehensive decision value, and take the pixel with the maximum comprehensive decision value as the lobe tip coordinate;
[0011] Calculate the vector difference between the clove tip coordinates and the centroid coordinates, define the root plate search region, extract the concavity and texture roughness features within the root plate search region, generate a root plate comprehensive feature response map, calculate the vector difference between the root plate center coordinates and the clove tip coordinates, and convert it into the angle with the principal axis direction to perform anomaly detection on the garlic clove orientation.
[0012] As a preferred embodiment of the machine vision automatic detection method for garlic clove orientation described in this invention, the following steps are included: establishing a system of linear equations for pixels, solving for surface vectors, calculating the magnitude of surface vectors, generating an albedo image, and normalizing the surface vectors to define them as normal vectors, including:
[0013] Based on the Lambertian reflection model and the light source direction vector, a system of linear equations for each pixel is established. The system of equations is then solved using the least squares method to obtain the surface vector.
[0014] Calculate the surface vector magnitude and generate an albedo image;
[0015] The surface vector is normalized and defined as the normal vector.
[0016] As a preferred embodiment of the automatic machine vision detection method for garlic clove orientation described in this invention, the following steps are included: binarizing the albedo image to obtain an accurate binary mask; calculating the zeroth and first moments of the accurate binary mask; obtaining the centroid coordinates of the garlic clove region based on the ratio of the first to the zeroth moment; constructing the spatial distribution covariance matrix of the foreground region; and performing eigenvalue decomposition to define the principal axis direction, including:
[0017] The albedo image is binarized using the Otsu method to obtain an initial binary mask. Morphological opening and closing operations are then performed on the initial binary mask sequentially to obtain an accurate binary mask.
[0018] Calculate the zeroth and first moments of the precise binary mask, and obtain the centroid coordinates of the garlic clove region based on the ratio of the first moment to the zeroth moment.
[0019] Calculate the second-order central moment centered at the centroid, construct the spatial distribution covariance matrix of the foreground region, perform eigenvalue decomposition on the spatial distribution covariance matrix, and define the direction of the eigenvector corresponding to the largest eigenvalue as the principal axis direction of the garlic clove region distribution.
[0020] As a preferred embodiment of the machine vision automatic detection method for garlic clove orientation described in this invention, the following steps are included: calculating the projection distance of a pixel position relative to its centroid along the principal axis, defining a candidate region for the clove tip, calculating the divergence of the horizontal component of the surface normal vector of pixels within the candidate region for the clove tip, defining a comprehensive decision value, and using the pixel with the largest comprehensive decision value as the clove tip coordinates:
[0021] Calculate the minimum bounding rectangle of the mask on the image plane, obtain the coordinate set of the foreground pixels, and calculate the projection distance of the position vector of each pixel in the coordinate set relative to the centroid along the principal axis.
[0022] Filter the maximum and minimum projection distances among all foreground pixels to define the candidate region for the lobe tip;
[0023] Extract the horizontal component of the normal vector and calculate the divergence of the horizontal component of the surface normal vector of each pixel in the candidate region of the lobe tip.
[0024] The absolute value of the divergence is defined as the cusp feature value. Combining the centroid and the cusp feature value, a comprehensive decision value is defined for each pixel in the candidate region of the lobe tip.
[0025] The pixel with the largest comprehensive decision value in the candidate region of the lobe tip is used as the lobe tip coordinate.
[0026] As a preferred embodiment of the machine vision automatic detection method for garlic clove orientation described in this invention, the following steps are included: calculating the vector difference between the clove tip coordinates and the centroid coordinates, defining the root plate search region, extracting the concavity features and texture roughness features within the root plate search region, and generating a root plate comprehensive feature response map:
[0027] Calculate the vector difference between the lobe tip coordinates and the centroid coordinates, construct a vector from the centroid to the lobe tip, calculate the dot product of the vector from the centroid to the lobe tip and the principal axis direction to obtain the projection scalar, and define the root disk search region.
[0028] If the projection scalar is greater than or equal to 0, it indicates that the lobe tip is located on the positive direction side of the principal axis; if the projection scalar is less than 0, it indicates that the lobe tip is located on the negative direction side of the principal axis, thus defining the root disk search area.
[0029] Take any foreground pixel in the root search area as the center point, set a square neighborhood window with a side length of W pixels, extract the vertical component of the normal vector of each pixel in the neighborhood window, and calculate the mean to obtain the average value of the vertical component of the normal vector of the neighborhood.
[0030] Extract the vertical component of the normal vector at the center point, and define the difference between the average value of the vertical components of the normal vectors in the neighborhood and the vertical component of the normal vector at the center point as the concavity feature value.
[0031] Extract the albedo image within the root disk search region and calculate the texture roughness features;
[0032] The concavity feature and texture roughness feature are respectively min-max normalized, and the two normalized features are fused by geometric mean to generate the root disk comprehensive feature response map.
[0033] The pixels of the largest root platen comprehensive feature response map within the root platen search area are selected and defined as the root platen center coordinates.
[0034] As a preferred embodiment of the machine vision automatic detection method for garlic clove orientation described in this invention, the step of calculating the vector difference between the coordinates of the root center and the clove tip, and converting it into an angle with the principal axis direction, to perform anomaly detection for garlic clove orientation includes:
[0035] The vector difference between the coordinates of the root disc center and the valve tip is calculated using vector subtraction and is defined as the reference physiological orientation vector.
[0036] The angle between the reference physiological orientation vector and the principal axis direction is calculated using the cosine function;
[0037] Set an anomaly threshold, filter garlic cloves with an angle greater than the anomaly threshold, and mark them as anomalies.
[0038] As a preferred embodiment of the machine vision automatic detection method for garlic clove orientation described in this invention, the step of constructing a visual interface to display the detection results includes:
[0039] A visual interface is built to display the anomaly detection results.
[0040] As a preferred embodiment of the automatic machine vision detection method for garlic clove orientation described in this invention, the step of collecting and preprocessing garlic clove images includes:
[0041] Three high-brightness LED line light sources are fixedly installed directly above the testing station, and the direction vector of the light sources is calibrated.
[0042] As the conveyor belt carrying garlic cloves passes through the inspection station, the camera simultaneously triggers the collection of three garlic clove images when the three light sources are lit up one by one in sequence, and performs grayscale conversion, noise reduction, and standardization processing.
[0043] In a second aspect, the present invention provides a computer device including a memory and a processor, wherein the memory stores a computer program, wherein when the computer program is executed by the processor, it implements any step of the automatic detection method for garlic clove orientation by machine vision as described in the first aspect of the present invention.
[0044] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the automatic machine vision detection method for garlic clove orientation as described in the first aspect of the present invention.
[0045] The beneficial effects of this invention are as follows: By combining the illumination model with the calculation of surface normal vectors, this invention not only eliminates the influence of illumination changes on the surface reflection characteristics of garlic cloves, but also accurately extracts the intrinsic geometric information of the garlic clove surface, providing stable visual data support under non-uniform illumination conditions. Based on the combination of the divergence characteristics of the normal vectors and the principal axis analysis of the shape distribution, it realizes the accurate extraction of key points of the clove tip and root plate from complex garlic clove morphology, significantly improving the accuracy of orientation judgment. Attached Figure Description
[0046] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a flowchart of the machine vision automatic detection method for the orientation of garlic cloves in Example 1.
[0048] Figure 2 This is an architecture diagram of the machine vision automatic detection method for the orientation of garlic cloves in Example 1. Detailed Implementation
[0049] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0050] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.
[0051] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.
[0052] Example 1, referring to Figure 1 and Figure 2 This is the first embodiment of the present invention, which provides a machine vision automatic detection method for the orientation of garlic cloves, including the following steps:
[0053] S1. Collect garlic clove images and preprocess them, establish a system of linear equations for the pixels, solve the surface vector, calculate the surface vector magnitude, generate an albedo image, normalize the surface vector, and define it as a normal vector.
[0054] Specifically, garlic clove images are collected and preprocessed, including:
[0055] Three high-brightness LED line light sources are fixedly installed directly above the testing station. The direction vector of the light sources is pre-calibrated as follows:
[0056] ,
[0057] ,
[0058] ,
[0059] in , as well as Let be the direction vector of the light source. This is the transpose operator, where x, y, and z are the three coordinate axes.
[0060] As the conveyor belt carrying garlic cloves passes through the inspection station, the camera simultaneously triggers the collection of three garlic clove images when the three light sources are lit up one by one in sequence, and performs grayscale conversion, noise reduction, and standardization processing.
[0061] Furthermore, a system of linear equations for each pixel is established, the surface vector is solved, the magnitude of the surface vector is calculated, an albedo image is generated, and the surface vector is normalized and defined as a normal vector, including:
[0062] Based on the Lambertian reflection model and the light source direction vector (the reflection intensity is proportional to the cosine of the angle between the surface normal vector and the light source direction), a system of linear equations for the pixel is established, as follows:
[0063] ,
[0064] ,
[0065] ,
[0066] in Let x and y be the grayscale value of pixel (x, y) under the illumination of the k-th light source, where k is the index of the light source, taking values of 1, 2, and 3, corresponding to three different light sources, and x and y are the two-dimensional coordinates of the pixel. Let (x, y) be the surface albedo of the garlic clove corresponding to pixel (x, y). Let k be the unit direction vector of the k-th light source in the camera coordinate system. , Let (x, y) be the unit normal vector of the garlic clove surface corresponding to pixel (x, y);
[0067] The system of equations is solved using the least squares method, with the goal of finding a solution that minimizes the sum of squared observation errors. The surface vector is calculated using the following formula:
[0068] ,
[0069] in Let be the surface vector at pixel (x, y). , , as well as surface vector The components in the x, y, and z coordinate axes, L is The light source direction matrix, where each row represents the direction vector of a light source. , Represents a 3x3 matrix space of real numbers. Let (x, y) be the column vector of observed intensities of pixel (x, y) under the three light sources. ;
[0070] Calculate the surface vector magnitude to obtain the surface albedo estimate for that pixel and generate an albedo image.
[0071] The surface albedo estimates of all pixels constitute an albedo image, which reflects the intrinsic reflective properties of the object's surface, eliminates the influence of the lighting direction, and makes the contrast between the foreground (garlic clove) and the background (conveyor belt) more stable, providing an ideal data source for subsequent segmentation.
[0072] The surface vector is normalized and defined as the normal vector, using the following formula:
[0073] ,
[0074] in Let be the normal vector at pixel (x, y). It is the L2 norm (Euclidean norm) of the vector.
[0075] By generating albedo images, the influence of illumination changes on garlic clove surface recognition was successfully eliminated. This not only improved the stability of image contrast but also enhanced the separation effect between the background and foreground. Especially under conditions of uneven illumination or strong reflection, it greatly improved the stability and accuracy of detection. Through optimization using the least squares method, a high-precision garlic clove surface normal vector was obtained, ensuring the accuracy of the surface reflectance estimate. The normalization of the normal vector reduced the errors caused by different angles or directions, enabling the system to work stably even when dealing with environments with varying garlic clove shapes and complex illumination.
[0076] S2. Binarize the albedo image to obtain an accurate binary mask. Calculate the zero-order moment and the first-order moment of the accurate binary mask. Based on the ratio of the first-order moment to the zero-order moment, obtain the centroid coordinates of the garlic clove region. Construct the spatial distribution covariance matrix of the foreground region and perform eigenvalue decomposition to define the principal axis direction.
[0077] Specifically, the albedo image is binarized to obtain an accurate binary mask. The zeroth and first moments of the accurate binary mask are calculated. Based on the ratio of the first to the zeroth moment, the centroid coordinates of the garlic clove region are obtained. The spatial distribution covariance matrix of the foreground region is constructed, and eigenvalue decomposition is performed. The principal axis directions are defined, including:
[0078] The global threshold of the albedo image is calculated using the Otsu method. The albedo image is then binarized to obtain an initial binary mask. Morphological opening and closing operations are then performed on the initial binary mask sequentially to obtain an accurate binary mask.
[0079] The maximum inter-class variance method is used to traverse all possible gray-level thresholds in the image, calculate the inter-class variance of pixels in the foreground and background classes, and select the gray-level value that maximizes the inter-class variance as the global threshold.
[0080] A circular structuring element with a radius of 3 pixels is used to perform a morphological opening operation on the initial binary mask. The opening operation is a composite operation of erosion followed by dilation, and its definition is:
[0081] ,
[0082] in This is the intermediate binary image after the opening operation. For morphological erosion operators, This is a morphological dilation operator, where B is the initial binary mask. This operation can effectively eliminate isolated foreground noise and fine burrs smaller than the structuring element.
[0083] The result of the opening operation is used to perform a morphological closing operation on a circular structuring element with a radius of 5 pixels. The closing operation is a composite operation of dilation followed by erosion, and its definition is:
[0084] ,
[0085] in For precise binary masks, this represents the final, precise binary mask image of the garlic clove foreground obtained after morphological refinement. The area is the region of a single garlic clove to be detected;
[0086] This operation can fill holes smaller than the structuring element inside the foreground region and smooth the outline boundary. After morphological processing, the final output is an accurate and complete garlic clove binary mask image, where the area with a pixel value of 1 represents the garlic clove foreground and the area with a pixel value of 0 represents the background.
[0087] Calculate the zeroth moment of an exact binary mask ( The area and first moment are given by the following formula:
[0088] ,
[0089] in Let p and q be the (p+q)th order moments of the image, where p and q are the orders of the moments, and q are non-negative integers. W and H are the width and height of the image, respectively.
[0090] Based on the ratio of the first moment to the zeroth moment, the centroid coordinates of the garlic clove region are obtained. The formula is:
[0091] ,
[0092] ,
[0093] in and ...
[0094] The formula for calculating the second central moment centered at the centroid is:
[0095] ,
[0096] ,
[0097] ,
[0098] in and These are the second-order central moments (variances) of the region in the x and y directions, respectively. Let be the second central moments (covariance) of the region in the x and y directions;
[0099] The spatial distribution covariance matrix of the foreground region is constructed using the following formula:
[0100] ,
[0101] Where C is the spatial distribution covariance matrix of the foreground region, representing a 2×2 real symmetric covariance matrix;
[0102] Eigenvalue decomposition is performed on the spatial distribution covariance matrix. The direction of the eigenvector corresponding to the largest eigenvalue is defined as the principal axis direction of the garlic clove region distribution, as shown in the formula:
[0103] ,
[0104] in The normalized unit vector along the principal axis. The eigenvector corresponding to the largest eigenvalue;
[0105] Solving for the eigenvalues of the spatial distribution covariance matrix and (satisfy and the corresponding feature vectors and Among them, the largest eigenvalue corresponding feature vector It indicates the direction of the largest variance in the pixel distribution of the foreground region, that is, the main axis direction of the garlic clove shape.
[0106] By performing precise binarization on the albedo image, the system can accurately separate the foreground region of the garlic clove. Morphological opening and closing operations effectively remove small-area noise and stray textures, optimizing the integrity and accuracy of the foreground region of the garlic clove. By calculating the zeroth and first moments of the precise binary mask, the system can stably obtain the centroid coordinates of the garlic clove region, thus providing a solid foundation for subsequent shape analysis and determination of principal axis directions.
[0107] S3. Calculate the projection distance of the pixel position relative to the centroid in the principal axis direction, define the candidate region of the lobe tip, calculate the divergence of the horizontal component of the surface normal vector of the pixel in the candidate region of the lobe tip, define the comprehensive decision value, and take the pixel with the maximum comprehensive decision value as the lobe tip coordinate.
[0108] Specifically, the projected distance of a pixel position relative to its centroid along the principal axis is calculated, a candidate region for the lobe tip is defined, the divergence of the horizontal component of the surface normal vector of pixels within the candidate region is calculated, a comprehensive decision value is defined, and the pixel with the largest comprehensive decision value is used as the lobe tip coordinate, including:
[0109] Calculate the minimum bounding rectangle of the mask on the image plane, obtain the coordinate set of the foreground pixels (the coordinates of their four vertices), and calculate the projection distance of the position vector of each pixel in the coordinate set relative to the centroid along the principal axis. The formula is as follows:
[0110] ,
[0111] in For the first One foreground pixel in the main axis direction Above relative to the center of mass The projection distance, and For the first The coordinates of the foreground pixels, where i is the index of the foreground pixel;
[0112] By filtering out the maximum and minimum projected distances among all foreground pixels, a candidate region for the lobe tip is defined using the following formula:
[0113] ,
[0114] in Candidate region for valve tip and These are the maximum and minimum values of the projected distance. The scaling factor is a constant set by statistically analyzing 85% of the relative position parameters of the actual lobe tip within the overall projected distance range in historical calibration data.
[0115] This condition filters out pixels located in the farthest 15% region along the positive axis, narrowing the search range of the clove tip from the entire clove to its most likely end region.
[0116] The formula for extracting the horizontal component of the normal vector is:
[0117] ,
[0118] in Let x be a two-dimensional vector formed by the x and y components of the surface normal vector at pixel (x, y). and These are the x-component and y-component of the normal vector of the pixel (x,y), respectively.
[0119] The divergence of the horizontal component of the surface normal vector of each pixel within the candidate region of the lobe tip is calculated using the following formula:
[0120] ,
[0121] in Let be the divergence calculated at pixel (x,y). and These are the partial derivatives with respect to x and y, respectively;
[0122] Divergence represents the degree of "divergence" or "convergence" of the horizontal components of the normal vector at a point, and is approximated using the central difference method;
[0123] The absolute value of the divergence is defined as the cusp feature value. Combining the centroid and the cusp feature value, a comprehensive decision value is defined for each pixel within the candidate region of the lobe tip, as shown in the formula:
[0124] ,
[0125] ,
[0126] in This represents the comprehensive decision value for pixel (x, y). The sharpness feature value of the pixel. The maximum Euclidean distance from all foreground pixels to the centroid is used to normalize the distance term.
[0127] The comprehensive decision value consists of two terms added together: the first term, S(x,y), maximizes the local curvature, ensuring that the selected point has a significant "sharp" characteristic; the second term is a normalized distance term, which tends to select points farther from the centroid when the curvature characteristics are similar. This is consistent with the geometric common sense that the tip of the clove is located at the end of the garlic clove. The two terms have the same dimensions (both are dimensionless scalars) and their numerical ranges are comparable, so it is reasonable to add them directly.
[0128] The pixel with the largest comprehensive decision value in the candidate region of the lobe tip is used as the lobe tip coordinate.
[0129] By performing eigenvalue decomposition on the spatial distribution covariance matrix, the system can accurately calculate the principal axis direction of the garlic cloves, thereby precisely determining their orientation. This method effectively avoids the coarse estimation that relies solely on the contour in traditional methods, providing a more detailed directional analysis. By considering the variance of the pixel distribution in the foreground region, the system can more stably and accurately locate the orientation of the garlic cloves, exhibiting higher robustness, especially when dealing with garlic cloves with complex or curved shapes. The precise analysis of the principal axis direction not only optimizes the recognition effect of garlic clove morphology but also provides a more accurate reference for the subsequent positioning of the clove tip and root plate region.
[0130] S4. Calculate the vector difference between the clove tip coordinates and the centroid coordinates, define the root plate search area, extract the concavity features and texture roughness features within the root plate search area, generate the root plate comprehensive feature response map, calculate the vector difference between the root plate center coordinates and the clove tip coordinates, and convert it into the angle with the principal axis direction to perform anomaly detection on the garlic clove orientation.
[0131] Specifically, the vector difference between the lobe tip coordinates and the centroid coordinates is calculated, the root disk search region is defined, the concavity and texture roughness features within the root disk search region are extracted, and a root disk comprehensive feature response map is generated, including:
[0132] The vector difference between the lobe tip coordinates and the centroid coordinates is calculated using vector subtraction. A vector from the centroid to the lobe tip is constructed. The dot product of the vector from the centroid to the lobe tip and the principal axis direction is calculated to obtain the projection scalar of the vector from the centroid to the lobe tip onto the principal axis direction. The root disk search region is then defined.
[0133] If the projection scalar is greater than or equal to 0, it indicates that the lobe tip is located on the positive side of the principal axis. If the projection scalar is less than 0, it indicates that the lobe tip is located on the negative side of the principal axis. The root disk search region is defined as the set of all pixels in the precise binary mask that satisfy the following condition: the projection of the point's position vector relative to the centroid onto the principal axis direction has the opposite sign to the projection scalar. The determination condition is:
[0134] When the projected scalar is greater than or equal to 0 When the projected scalar is less than 0, ,in This is the root disk search area;
[0135] Using any foreground pixel within the root disk search region as the center point, a square neighborhood window with a side length of W pixels is defined using the sliding window method. The vertical component of the normal vector of each pixel in the neighborhood window is extracted, and the mean is calculated to obtain the average value of the vertical component of the normal vector of the neighborhood. The formula is:
[0136] ,
[0137] in For the neighborhood Vertical component of the inner normal vector The average value, This is a local neighborhood window centered at pixel (x, y). The neighborhood contains all pixels that satisfy the following conditions: and The pixel (u, v), where u and v are neighbors. Pixel coordinates within, For the neighborhood The total number of pixels contained within;
[0138] Extract the vertical component of the normal vector at the center point, and define the difference between the average value of the vertical components of the normal vectors in the neighborhood and the vertical component of the normal vector at the center point as the concavity feature value.
[0139] This difference quantifies the degree of "concavity" of the center point relative to its surrounding area. If the concavity feature value is greater than 0, it means that the center point is more "downward" (concave) than the surrounding area. The larger the value, the stronger the sense of concavity.
[0140] The surface of the root plate has a rough texture due to the attachment of roots, and its gray scale changes more drastically than the smooth surface of the petals.
[0141] Extract the albedo image within the root disk search region and calculate the texture roughness features using the following formula:
[0142] ,
[0143] in Let (x, y) be the texture roughness feature value of pixel (x, y). This represents the albedo grayscale value at the neighboring pixel (u,v). For the neighborhood The arithmetic mean of the gray values of the internal albedo;
[0144] Mini-maximum normalization was applied to both the concavity and texture roughness features, linearly mapping their numerical ranges to... For each interval, the geometric mean is used to fuse the two normalized features to generate the root disk comprehensive feature response map. The formula is as follows:
[0145] ,
[0146] in This is the root disk comprehensive feature response map of pixel (x, y). and These are the normalized concavity characteristics and texture roughness characteristics, respectively;
[0147] The pixels of the largest root platen comprehensive feature response map within the root platen search area are selected and defined as the root platen center coordinates.
[0148] By introducing concavity and texture roughness features, the system can identify and distinguish the root plate region of garlic cloves from other parts. Due to the presence of attached roots, the texture roughness and concavity features of the root plate are significantly different, which enables the system to accurately extract this region and further improve the accuracy of orientation detection. By analyzing the geometric and texture features of the root plate and clove tip regions, the system can promptly identify and mark garlic cloves with abnormal shapes. In particular, by calculating the vector difference between the center of the root plate and the clove tip, the system can determine whether the garlic clove has an abnormal orientation, providing support for subsequent automatic sorting and quality control.
[0149] Furthermore, the vector difference between the coordinates of the root disc center and the coordinates of the clove tip is calculated and converted into the angle with the principal axis direction to perform anomaly detection on the clove orientation, including:
[0150] The vector difference between the coordinates of the root plate center and the clove tip is calculated using vector subtraction and defined as the reference physiological orientation vector. According to the botanical structure definition of garlic, the physiological orientation of garlic cloves is the direction from the root plate to the clove tip.
[0151] The angle between the reference physiological orientation vector and the principal axis direction is calculated using the cosine function, with the following formula:
[0152] ,
[0153] in Let cosine be the angle between the baseline physiological orientation vector and the principal axis direction. The angle between the baseline physiological orientation vector and the principal axis direction. Used as the baseline physiological orientation vector;
[0154] The percentile method is used to calculate 95% of the historical normal angles, an anomaly threshold is set, garlic cloves with angles greater than the anomaly threshold are filtered out and marked as anomalies.
[0155] By accurately identifying the main characteristics of garlic cloves and determining their orientation, the system can effectively support automated sorting operations, improve operational efficiency and accuracy, reduce manual intervention, increase production efficiency, provide a reliable basis for detecting abnormal garlic clove orientation, and ensure that the automated sorting system can still work efficiently and accurately under complex conditions.
[0156] This embodiment also provides a computer device applicable to the automatic machine vision detection method for garlic clove orientation, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the automatic machine vision detection method for garlic clove orientation as proposed in the above embodiment.
[0157] The computer device can be a terminal, comprising a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0158] This embodiment also provides a storage medium storing a computer program, which, when executed by a processor, implements the machine vision automatic detection method for garlic clove orientation as proposed in the above embodiment. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0159] In summary, by combining the illumination model with the calculation of surface normal vectors, this invention not only eliminates the influence of illumination changes on the surface reflection characteristics of garlic cloves, but also accurately extracts the intrinsic geometric information of the garlic clove surface, providing stable visual data support under non-uniform illumination conditions. Based on the combination of the divergence characteristics of the normal vectors and the principal axis analysis of the shape distribution, it achieves the accurate extraction of key points of the clove tip and root plate from complex garlic clove morphology, significantly improving the accuracy of orientation judgment.
[0160] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A machine vision-based automatic detection method for the orientation of garlic cloves, characterized in that: include, Collect garlic clove images and preprocess them, establish a system of linear equations for the pixels, solve for the surface vector, calculate the magnitude of the surface vector, generate an albedo image, normalize the surface vector, and define it as a normal vector. The albedo image is binarized to obtain an accurate binary mask. The zeroth and first moments of the accurate binary mask are calculated. Based on the ratio of the first moment to the zeroth moment, the centroid coordinates of the garlic clove region are obtained. The spatial distribution covariance matrix of the foreground region is constructed, and eigenvalue decomposition is performed to define the principal axis direction. Calculate the projection distance of the pixel position relative to the centroid along the principal axis, define the candidate region of the lobe tip, calculate the divergence of the horizontal component of the surface normal vector of the pixels in the candidate region of the lobe tip, define the comprehensive decision value, and take the pixel with the maximum comprehensive decision value as the lobe tip coordinate; Calculate the vector difference between the clove tip coordinates and the centroid coordinates, define the root plate search region, extract the concavity and texture roughness features within the root plate search region, generate a root plate comprehensive feature response map, calculate the vector difference between the root plate center coordinates and the clove tip coordinates, convert it into the angle with the principal axis direction, perform anomaly detection on the clove orientation, and construct a visualization interface to display the detection results.
2. The automatic machine vision detection method for garlic clove orientation as described in claim 1, characterized in that: The process involves establishing a system of linear equations for each pixel, solving for the surface vector, calculating the surface vector magnitude, generating an albedo image, and normalizing the surface vector, defining it as a normal vector. This includes: Based on the Lambertian reflection model and the light source direction vector, a system of linear equations for each pixel is established. The system of equations is then solved using the least squares method to obtain the surface vector. Calculate the surface vector magnitude and generate an albedo image; The surface vector is normalized and defined as the normal vector.
3. The automatic machine vision detection method for garlic clove orientation as described in claim 2, characterized in that: The albedo image is binarized to obtain an accurate binary mask. The zeroth and first moments of the accurate binary mask are calculated. Based on the ratio of the first to the zeroth moment, the centroid coordinates of the garlic clove region are obtained. The spatial distribution covariance matrix of the foreground region is constructed, and eigenvalue decomposition is performed to define the principal axis direction, including: The albedo image is binarized using the Otsu method to obtain an initial binary mask. Morphological opening and closing operations are then performed on the initial binary mask sequentially to obtain an accurate binary mask. Calculate the zeroth and first moments of the precise binary mask, and obtain the centroid coordinates of the garlic clove region based on the ratio of the first moment to the zeroth moment. Calculate the second-order central moment centered at the centroid, construct the spatial distribution covariance matrix of the foreground region, perform eigenvalue decomposition on the spatial distribution covariance matrix, and define the direction of the eigenvector corresponding to the largest eigenvalue as the principal axis direction of the garlic clove region distribution.
4. The automatic machine vision detection method for garlic clove orientation as described in claim 3, characterized in that: The calculation of the projection distance of the pixel position relative to the centroid along the principal axis defines the candidate region for the lobe tip. The divergence of the horizontal component of the surface normal vector of the pixels within the candidate region is calculated. A comprehensive decision value is defined, and the pixel with the largest comprehensive decision value is used as the lobe tip coordinate. This includes: Calculate the minimum bounding rectangle of the mask on the image plane, obtain the coordinate set of the foreground pixels, and calculate the projection distance of the position vector of each pixel in the coordinate set relative to the centroid along the principal axis. Filter the maximum and minimum projection distances among all foreground pixels to define the candidate region for the lobe tip; Extract the horizontal component of the normal vector and calculate the divergence of the horizontal component of the surface normal vector of each pixel in the candidate region of the lobe tip. The absolute value of the divergence is defined as the cusp feature value. Combining the centroid and the cusp feature value, a comprehensive decision value is defined for each pixel in the candidate region of the lobe tip. The pixel with the largest comprehensive decision value in the candidate region of the lobe tip is used as the lobe tip coordinate.
5. The automatic machine vision detection method for garlic clove orientation as described in claim 4, characterized in that: The calculation of the vector difference between the lobe tip coordinates and the centroid coordinates defines the root disk search region. The concavity and texture roughness features within the root disk search region are extracted to generate a root disk comprehensive feature response map, including: Calculate the vector difference between the lobe tip coordinates and the centroid coordinates, construct a vector from the centroid to the lobe tip, calculate the dot product of the vector from the centroid to the lobe tip and the principal axis direction to obtain the projection scalar, and define the root disk search region. If the projection scalar is greater than or equal to 0, it indicates that the lobe tip is located on the positive direction side of the principal axis; if the projection scalar is less than 0, it indicates that the lobe tip is located on the negative direction side of the principal axis, thus defining the root disk search area. Take any foreground pixel in the root search area as the center point, set a square neighborhood window with a side length of W pixels, extract the vertical component of the normal vector of each pixel in the neighborhood window, and calculate the mean to obtain the average value of the vertical component of the normal vector of the neighborhood. Extract the vertical component of the normal vector at the center point, and define the difference between the average value of the vertical components of the normal vectors in the neighborhood and the vertical component of the normal vector at the center point as the concavity feature value. Extract the albedo image within the root disk search region and calculate the texture roughness features; The concavity feature and texture roughness feature are respectively min-max normalized, and the two normalized features are fused by geometric mean to generate the root disk comprehensive feature response map. The pixels of the largest root platen comprehensive feature response map within the root platen search area are selected and defined as the root platen center coordinates.
6. The automatic machine vision detection method for garlic clove orientation as described in claim 5, characterized in that: The calculation of the vector difference between the coordinates of the root center and the clove tip, and its conversion into an angle with the principal axis direction, is used to detect anomalies in the clove orientation, including: The vector difference between the coordinates of the root disc center and the valve tip is calculated using vector subtraction and is defined as the reference physiological orientation vector. The angle between the reference physiological orientation vector and the principal axis direction is calculated using the cosine function; Set an anomaly threshold, filter garlic cloves with an angle greater than the anomaly threshold, and mark them as anomalies.
7. The automatic machine vision detection method for garlic clove orientation as described in claim 6, characterized in that: The construction of a visual interface to display the detection results includes: A visual interface is built to display the anomaly detection results.
8. The automatic machine vision detection method for garlic clove orientation as described in claim 1, characterized in that: The process of collecting and preprocessing garlic clove images includes: Three high-brightness LED line light sources are fixedly installed directly above the testing station, and the direction vector of the light sources is calibrated. As the conveyor belt carrying garlic cloves passes through the inspection station, the camera simultaneously triggers the collection of three garlic clove images when the three light sources are lit up one by one in sequence, and performs grayscale conversion, noise reduction, and standardization processing.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, it implements the steps of the automatic machine vision detection method for garlic clove orientation as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the steps of the automatic machine vision detection method for garlic clove orientation as described in any one of claims 1 to 8.