Computer-aided agricultural product quality detection and grading method and system
The final outer contour edge line of agricultural products is obtained through computer-aided methods, which solves the problems of inefficient and subjective impact of agricultural product quality evaluation in the prior art, and achieves rapid and accurate classification of agricultural product quality.
Patent Information
- Application Number
- CN202510764397.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-06-10
AI Technical Summary
The prior art is inefficient in the evaluation of agricultural product quality and is susceptible to subjective factors, making it difficult to accurately obtain the outer contour lines of agricultural products, resulting in inaccurate grading.
Using a computer-aided method, the initial outer contour edge line is obtained, chain code operation is performed to identify abnormal edges, and the concave hull algorithm is used to fill the depression area, and the final outer contour edge line is calculated for grading.
It realizes rapid and accurate classification of agricultural product quality, improves classification efficiency, reduces subjective influence, and ensures the objectivity and accuracy of classification.
Smart Images

Figure CN120279342B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and in particular relates to a computer-aided agricultural product quality detection and grading method and system. Background Art
[0002] With the advancement of agricultural modernization, the yield and quality of agricultural products have significantly improved. However, the quality evaluation of agricultural products still relies primarily on manual experience, which is not only inefficient but also easily influenced by subjective factors. To achieve rapid and accurate grading of agricultural products and improve their market competitiveness, it is particularly important to develop a computer-aided agricultural product quality inspection and grading method and system.
[0003] To quickly select the highest-quality produce from a batch of harvested agricultural products, it's necessary to accurately capture the outer contours of the produce and calculate the roundness of the area enclosed by the outer contours. However, conventional methods for capturing the outer contours of agricultural products have flaws: if non-fruit portions of the produce (such as green leaves and stalks) are included, the roundness of the produce cannot be accurately calculated; if the non-fruit portions are removed entirely, depressions will form in the non-fruit areas, where the fruit actually resides. Directly identifying the outer contours of agricultural products in the presence of depressions will result in flawed contours, making it impossible to accurately grade the produce. Summary of the Invention
[0004] The present invention provides a computer-aided agricultural product quality inspection and grading method and system, which can accurately obtain the final outer contour edge line of the agricultural product, and use the distance between each pixel point and the center point on the final outer contour edge line to calculate the roundness of the final outer contour edge line, and grade the agricultural products according to the roundness.
[0005] The computer-aided agricultural product quality detection and grading method of the present invention adopts the following technical solutions:
[0006] Acquire images of agricultural products to be inspected;
[0007] Extracting the skin portion of the agricultural product image to be detected as an initial agricultural product image, and obtaining an initial outer contour edge line of the initial agricultural product image;
[0008] Perform chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain the chain code sequence of the initial outer contour edge line in a clockwise direction;
[0009] Calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values;
[0010] The abnormal edge is formed by the pixel points corresponding to the abnormal chain code value, and the incomplete edge line is obtained after deleting the abnormal edge from the initial outer contour edge line;
[0011] Filling the incomplete edge line to obtain the final outer contour edge line of the epidermis;
[0012] The center point of the area enclosed by the final outer contour edge line is obtained, and the roundness of the final outer contour edge line is calculated using the distance between each pixel point on the final outer contour edge line and the center point. Agricultural products are graded according to the roundness.
[0013] Furthermore, the step of calculating the roundness of the final outer contour edge line using the distance between each pixel point and the center point on the final outer contour edge line includes:
[0014] Establish a coordinate system with the center point of the area enclosed by the final outer contour edge line as the origin;
[0015] Calculate the distance between each pixel point on the final outer contour edge line and the center point, form a distance set from all the obtained distance values, and use the average of all the obtained distances as the virtual radius;
[0016] Calculate the standard deviation of all distance values in the distance set, and use the ratio of the standard deviation to the virtual radius as the first eigenvalue;
[0017] Calculate the aspect ratio of the final outer contour edge line according to the intersection of the final outer contour edge line with the horizontal axis and the vertical axis of the coordinate system, and use the aspect ratio of the final outer contour edge line as the second eigenvalue;
[0018] The product of the first eigenvalue and the second eigenvalue is used as the roundness of the final outer contour edge line.
[0019] Furthermore, the step of calculating the aspect ratio of the final outer contour edge line according to the intersection of the final outer contour edge line with the horizontal axis and the vertical axis of the coordinate system includes:
[0020] Obtain the first intersection point of the final outer contour edge line with the positive semi-axis of the horizontal axis of the coordinate system and the second intersection point with the negative semi-axis of the horizontal axis of the coordinate system;
[0021] Add the absolute value of the abscissa of the first intersection point and the absolute value of the abscissa of the second intersection point to obtain the width of the final outer contour edge line;
[0022] Obtain the third intersection point of the final outer contour edge line with the positive semi-axis of the coordinate system longitudinal axis and the fourth intersection point with the negative semi-axis of the coordinate system longitudinal axis;
[0023] Add the absolute value of the ordinate of the third intersection point and the absolute value of the ordinate of the fourth intersection point to obtain the length of the final outer contour edge line;
[0024] Calculate the aspect ratio of the final outer contour edge line.
[0025] Furthermore, the steps of grading agricultural products according to roundness include:
[0026] When the roundness is greater than a preset second threshold, the agricultural product to be tested is determined to be a low-quality agricultural product;
[0027] When the roundness is less than or equal to a preset second threshold, the agricultural product to be tested is determined to be a high-quality agricultural product.
[0028] Furthermore, the step of extracting the skin portion of the agricultural product image to be detected as the initial agricultural product image includes:
[0029] Perform color clustering on the agricultural product image to be detected and extract the skin part of the image as the initial agricultural product image.
[0030] Furthermore, the step of filling the incomplete edge line to obtain the final outer contour edge line of the epidermis includes:
[0031] The convex hull algorithm is used to fill the incomplete edge line to obtain the final outer contour edge line of the epidermis.
[0032] Computer-aided agricultural product quality inspection and grading system, including:
[0033] An image acquisition module, used to acquire images of agricultural products to be inspected;
[0034] An initial outer contour edge line acquisition module is used to extract the skin portion of the agricultural product image to be detected as the initial agricultural product image and obtain the initial outer contour edge line of the initial agricultural product image;
[0035] A chain code sequence acquisition module is used to perform a chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain the chain code sequence of the initial outer contour edge line in a clockwise direction;
[0036] An abnormal chain code value selection module is used to calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values;
[0037] The final outer contour edge line acquisition module is used to form an abnormal edge from the pixel points corresponding to the abnormal chain code value, delete the abnormal edge from the initial outer contour edge line to obtain an incomplete edge line; and fill the incomplete edge line to obtain the final outer contour edge line of the epidermis;
[0038] A roundness calculation module is used to obtain the center point of the area enclosed by the final outer contour edge line, and calculate the roundness of the final outer contour edge line using the distance between each pixel point on the final outer contour edge line and the center point;
[0039] The grading module is used to grade agricultural products according to their roundness.
[0040] The beneficial effects of the present invention are:
[0041] The present invention provides a computer-aided agricultural product quality detection and grading method and system. First, an initial agricultural product image containing only a skin portion is preliminarily obtained, and an initial outer contour edge line of the initial agricultural product image is simultaneously obtained. Since the non-fruit portion is deleted from the initial agricultural product image, the area containing green leaves in the initial outer contour edge line will be deleted, thereby causing a depression in the initial outer contour edge line. The depressed position of the initial outer contour edge line will also exist, so the depressed position in the initial outer contour edge line is an abnormal position. In order to obtain the abnormal position of the initial outer contour edge line, a chain code operation is performed on the initial outer contour edge line to obtain a chain code sequence of the initial outer contour edge line. The abnormal chain code value is selected according to the difference between two adjacent chain code values in the chain code sequence.
[0042] The abnormal edge is composed of the pixel points corresponding to the abnormal chain code value. After deleting the abnormal edge in the initial outer contour edge line, an incomplete edge line is obtained. The convex hull algorithm is used to fill the incomplete edge line to obtain the final outer contour edge line of the agricultural product. In the final outer contour edge line obtained, the non-fruit part is removed and the complete fruit area edge line of the agricultural product is obtained. After obtaining the final outer contour edge line, the distance between each pixel point and the center point on the final outer contour edge line is used to calculate the roundness of the final outer contour edge line, and the agricultural products are graded according to the roundness. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 A flowchart of the overall steps of an embodiment of the computer-aided agricultural product quality detection and grading method of the present invention;
[0045] Figure 2 Schematic diagram of the distance from any edge point K to the center point on the final outer contour edge line in the present invention;
[0046] Figure 3 This is a schematic diagram of high-quality agricultural products in the present invention;
[0047] Figure 4 Schematic diagram of low-quality agricultural products in the present invention. DETAILED DESCRIPTION
[0048] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0049] The embodiment of the computer-aided agricultural product quality detection and grading method of the present invention is as follows: Figure 1 As shown, the method includes:
[0050] S1. Obtain images of agricultural products to be inspected.
[0051] The present invention is applicable to a variety of agricultural products, including but not limited to apples, pears, peaches, citrus fruits, tomatoes, etc. These agricultural products occupy an important position in the market, and the quality of these products directly affects consumers' willingness to buy and the economic benefits of agricultural products. Take apples as an example. As the king of fruits, they are sweet and have high nutritional value. They combine the advantages of fruits, vegetables and medicines. They are a green, environmentally friendly and health-promoting food. However, there are differences in the quality of apples, and their taste and sales prices are also different. The quality of apples is closely related to their appearance. Apples with a rounded appearance, a rounded tail, and an overall short and fat shape are more mature, and have better taste and quality. On the contrary, apples with a slender appearance and a distinct tapered tail have lower moisture and sugar content, a relatively bland taste, and poor quality. Similarly, other agricultural products such as pears, peaches, citrus fruits, tomatoes, etc. also have similar situations, and their quality is closely related to their appearance characteristics.
[0052] In this method, harvested agricultural products (using apples as an example) are placed on a conveyor belt with a pure white background. A camera is used directly above the conveyor belt to capture a full-area image of the agricultural products to be tested. This captured full-area image is then converted to grayscale. The Otsu adaptive threshold segmentation method is then used to extract the agricultural product region from the full-area image to serve as the agricultural product image to be tested. The agricultural product image to be tested is then transmitted to a computer, which processes the captured image. The following steps describe the specific computer processing steps.
[0053] S2. Extract the skin portion of the agricultural product image to be detected as an initial agricultural product image, and obtain an initial outer contour edge line of the initial agricultural product image.
[0054] The step of extracting the epidermis portion of the agricultural product image to be detected as the initial agricultural product image includes: performing color clustering on the agricultural product image to be detected and extracting the epidermis portion of the image as the initial agricultural product image.
[0055] The step of obtaining the initial outer contour edge line of the initial agricultural product image includes: binarizing the obtained initial agricultural product image to obtain a binary agricultural product image, and connecting the outer contour edge pixel points in the binary agricultural product image to obtain the outer contour edge line.
[0056] In step S1, a color image of the agricultural product to be tested has been obtained. However, since a large number of leaves (not fruit parts) exist in the color image of the agricultural product to be tested, which interferes with the recognition and judgment of the agricultural product morphology, it is necessary to remove the interference of the leaves from the image of the agricultural product to be tested, and fill the edge defects of the removed agricultural product image to restore it to its original smooth contour, and finally obtain a final edge containing only the agricultural product fruit and being smooth.
[0057] In order to obtain the final outer contour edge line of the agricultural product, it is first necessary to use the color clustering algorithm to extract the non-fruit part of the agricultural product image to be detected to reduce the interference caused by the non-fruit part. The specific operation is: use the KMeans pixel clustering method, which is a classic algorithm for solving clustering problems and is simpler and more efficient. It is an unsupervised algorithm and does not require preparation of a training set; the algorithm idea is very simple. For a given sample set, the Euclidean distance is used as the standard to measure the similarity between objects. The greater the similarity, the shorter the distance; the purpose is to extract the green leaves.
[0058] 1. Data preparation: sample set at input , determine the number of clusters in a cluster (In order to distinguish between leaves and agricultural products themselves, two clusters are set for classification: red and green. Red represents red apples and green represents green apple leaves.) The output is the cluster division. .
[0059] 2. For unclustered datasets, first start with the sample dataset K samples are randomly selected as the initial K centroids, that is, two centroids.
[0060] 3. Find the distance from each sample data to the center point, and cluster according to the center point closest to itself.
[0061] 4. Based on the results of the previous clustering, find the new center point (the average value is the mean vector of the cluster).
[0062] 5. Repeat the third and fourth steps for continuous iteration. When the change of the center point meets the convergence condition (the set number of iterations is reached or the mean vector no longer changes), the final clustering result is obtained. The above steps divide the agricultural product image to be detected into two parts, green and red. The green pixel part is extracted, and the remaining part is used as the initial agricultural product image. The median filter operation is used on the initial agricultural product image to remove the interference of noise in the image. The median filter method is a nonlinear smoothing technology. The grayscale value of each pixel is set to the median of the grayscale values of all pixels in a certain neighborhood window of the point. It can achieve a good filtering effect without causing significant blurring of the image and at the same time maintain the original edge features of the agricultural product image without losing contour information, making the surrounding pixels closer to the true value, thereby eliminating isolated noise points; after obtaining the denoised image, the denoised image is binarized to obtain a binary agricultural product image, and the outer contour edge pixels in the binary agricultural product image are connected to obtain the initial outer contour edge line.
[0063] S3. Perform a chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain a chain code sequence of the initial outer contour edge line in a clockwise direction.
[0064] A chain code operation is performed on the initial outer contour edge line using the Freeman chain code, which is a method of describing a curve or boundary using the coordinates of the curve's starting point and the boundary point direction code. It is a coding representation of the boundary. This step uses the chain code to determine the smoothness of the initial outer contour edge line, that is, the degree of abnormality of the initial outer contour edge line.
[0065] Starting from any pixel point on the initial outer contour edge line, traverse each pixel point on the initial outer contour edge line in a clockwise direction and record the direction of the next pixel point relative to the previous pixel point.
[0066] The relative direction is quantified into a specific value. Since there are 8 adjacent points around any pixel, and the eight-connected chain code just conforms to the actual situation of the pixel point, it can accurately describe the information of the central pixel point and its adjacent points. Therefore, the eight-connected chain code is used to judge the smoothness of the edge. Any edge point on the initial outer contour edge line is selected as the starting point S. The chain code starts from the starting point S of the initial outer contour edge line and obtains the direction of the initial outer contour edge line in a clockwise direction to form a chain code sequence of the outer contour edge line.
[0067] S4. Calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values.
[0068] After obtaining the chain code sequence, the difference between each of the two adjacent chain code values in the chain code sequence and the previous adjacent chain code value is calculated; wherein, the previous adjacent chain code value of the first chain code value in the chain code sequence is the last chain code value in the chain code sequence; when the absolute value of the difference is less than or equal to a preset first threshold, the two chain code values corresponding to the difference are selected as abnormal chain code values, and similarly, all abnormal chain code values are selected.
[0069] When the initial outer contour edge is relatively smooth and there is no abnormal mutation, the absolute value of the difference between the latter and previous chain code values in the obtained chain code sequence is not greater than 1. Therefore, the preset first threshold is set to 1, and the obtained chain code sequence set is ,but , the calculation formula for the difference between two adjacent chain code values is:
[0070]
[0071] in, Indicates the first chain code value; Indicates the first chain code values; the difference between two adjacent chain code values is calculated according to the formula; when the absolute value of the difference is less than or equal to the preset first threshold, the two chain code values corresponding to the difference are selected as abnormal chain code values, and all abnormal chain code values are selected.
[0072] S5. Abnormal edges are formed by the pixel points corresponding to the abnormal chain code values, and the abnormal edges are deleted from the initial outer contour edge line to obtain an incomplete edge line.
[0073] After obtaining the abnormal chain code value, the pixel points corresponding to the abnormal chain code value form an abnormal edge, that is, the abnormal edge that needs to be deleted due to green leaf interference is obtained. After finding the abnormal edge where the depression exists, the abnormal edge is deleted from the initial outer contour edge line to obtain an incomplete edge line.
[0074] S6. Fill the incomplete edge line to obtain the final outer contour edge line of the epidermis.
[0075] After deleting the abnormal edges in the initial outer contour edge line, an incomplete edge line is obtained. The incomplete edge line needs to be filled. The convex hull algorithm is used to fill the incomplete edge line to obtain the final outer contour edge line of the epidermis.
[0076] When filling incomplete edge lines, the edges of agricultural products can be expressed as follows: put the pixel points around the incomplete edge line in a set D, and find its minimum point set E so that the polygonal shape formed by connecting E can contain all the pixel points in D. For the concave part of the edge of the agricultural product, find the surrounding pixel points and then form a convex hull. The specific operation is obtained using the classic Graham scanning method. The idea of this scanning method is to first find a point on the convex hull, and then start from this point and find points on the convex hull one by one in a counterclockwise direction to fill the convex hull. After the convex hull is filled, the final outer contour edge line of the epidermis is obtained. The final outer contour edge line is the ideal edge of the agricultural product image. Then, based on the final outer contour edge line obtained, further geometric analysis is performed.
[0077] S7. Obtain the center point of the area enclosed by the final outer contour edge line, calculate the roundness of the final outer contour edge line using the distance between each pixel point on the final outer contour edge line and the center point, and grade the agricultural products according to the roundness.
[0078] The steps of calculating the roundness of the final outer contour edge line using the distance between each pixel point and the center point on the final outer contour edge line include: establishing a coordinate system with the center point of the area enclosed by the final outer contour edge line as the origin; calculating the distance between each pixel point and the center point on the final outer contour edge line, forming a distance set from all the obtained distance values, and taking the mean of all the obtained distances as the virtual radius; calculating the standard deviation of all the distance values in the distance set, and taking the ratio of the standard deviation to the virtual radius as the first eigenvalue; calculating the aspect ratio of the final outer contour edge line based on the intersection of the final outer contour edge line with the horizontal axis and the vertical axis of the coordinate system, and taking the aspect ratio of the final outer contour edge line as the second eigenvalue; and taking the product of the first eigenvalue and the second eigenvalue as the roundness of the final outer contour edge line.
[0079] The steps of calculating the aspect ratio of the final outer contour edge line based on the intersection points of the final outer contour edge line with the horizontal and vertical axes of the coordinate system include: obtaining a first intersection point of the final outer contour edge line with the positive semi-axis of the horizontal axis of the coordinate system and a second intersection point with the negative semi-axis of the horizontal axis of the coordinate system; adding the absolute value of the horizontal coordinate of the first intersection point to the absolute value of the horizontal coordinate of the second intersection point as the width of the final outer contour edge line; obtaining a third intersection point of the final outer contour edge line with the positive semi-axis of the vertical axis of the coordinate system and a fourth intersection point with the negative semi-axis of the vertical axis of the coordinate system; adding the absolute value of the vertical coordinate of the third intersection point to the absolute value of the vertical coordinate of the fourth intersection point as the length of the final outer contour edge line; and calculating the aspect ratio of the final outer contour edge line.
[0080] The step of grading agricultural products according to the degree of roundness includes: when the degree of roundness is greater than a preset second threshold, the agricultural products to be tested are determined to be low-quality agricultural products; when the degree of roundness is less than or equal to the preset second threshold, the agricultural products to be tested are determined to be high-quality agricultural products.
[0081] After obtaining the final outer contour edge line, the center point of the final outer contour edge line is found through the OTSU algorithm. Then, the coordinate axis is established with the center point O as the origin to obtain the distance from each edge point to the center point on the final outer contour edge line. The coordinates of the center point are known to be (0,0), such as Figure 2 As shown in the figure, it is a schematic diagram of the distance from any edge point K to the center point on the final outer contour edge line; any edge point K on the final outer contour edge line ( , ) to the center point d1 is calculated as:
[0082]
[0083] in, Indicates any edge point K on the final outer contour edge line ( , ) to the center point; Represents the horizontal coordinate of any edge point K on the final outer contour edge line; Represents the ordinate of any edge point K on the final outer contour edge line; the set of edge points on the final outer contour edge line is , and thus the distance from the ideal edge point K to the center point O is calculated in turn, and the distance set D can be expressed as , get the first intersection point of the final outer contour edge line and the positive semi-axis of the horizontal axis of the coordinate system as The second intersection of the final outer contour edge line and the negative semi-axis of the horizontal axis of the coordinate system At the same time, the third intersection point of the final outer contour edge line and the positive semi-axis of the vertical axis of the coordinate system is obtained and the negative half axis of the vertical axis of the coordinate system The fourth intersection of . Starting from the point, we traverse each edge point and their distance from the center point O in a clockwise direction in the order of (Q1, P1, Q2, P2). According to the shape of the final outer contour edge line, we evaluate the roundness of the agricultural products and then analyze the quality of the agricultural products.
[0084] According to the distance d corresponding to each edge point K on the final outer contour edge line, the curved contours of agricultural products of different qualities are drawn respectively. The image contours drawn by the distance from each edge point to the center point are relatively rounded, and there are also relatively more elliptical contours. The roundness of the final outer contour edge line is evaluated, and the difference between the final outer contour edge line and the standard circle is compared (the smaller the difference, the better the quality).
[0085] First, obtain the set D of distances from all edge points on the final outer contour edge line to the center point. Calculate the mean of all values in set D, i.e., the average distance between the edge points and the center point, and use this as the virtual radius of the reference circle. Then calculate the standard deviation of all values in set D and the ratio of the standard deviation to the virtual radius. The standard deviation is chosen because it reflects the degree of dispersion of a data set, i.e., the degree of variation in the curve, thereby determining the roundness of the final outer contour edge line. Calculate the standard deviation of all distance values in the distance set and use the ratio of the standard deviation to the virtual radius as the first eigenvalue. Calculate the aspect ratio of the final outer contour edge line based on the intersection of the final outer contour edge line with the horizontal and vertical axes of the coordinate system and use this as the second eigenvalue. The product of the first and second eigenvalues is used as the roundness of the final outer contour edge line. A greater roundness of the final outer contour edge line indicates a more rounded agricultural product to be tested; a lower roundness indicates a less rounded agricultural product to be tested. According to the appearance and quality characteristics of agricultural products, the rounder and more mature the product is, the more water and sugar it contains. Conversely, the longer and thinner the product is, the worse its taste will be, and the less water and sugar it contains.
[0086] The following details:
[0087] It is known that the set of edge points on the final outer contour edge line and the distance from the center point is D= , and the calculation formula of its mean is:
[0088] =
[0089] in, Represents the mean of all distance values in set D; Represents the total number of distance values contained in the set D; Indicates the first distance values; calculate the standard deviation of all distance values in set D , the mean of all distances obtained is taken as the virtual radius, and the ratio of the standard deviation to the virtual radius is taken as the first eigenvalue S. The calculation formula of the first eigenvalue S is:
[0090]
[0091] in, represents the first eigenvalue; Represents the standard deviation of all distance values in set D; Indicates the virtual radius.
[0092] The ratio of the length and width of the final outer contour edge line is used as an important reference. The smaller the ratio, the more uniform and coordinated the contour distribution is, and the greater the possibility of being judged as high-quality agricultural products; the larger the ratio, the more obvious the difference in length and width of the contour, and the more likely it is to be a low-quality agricultural product.
[0093] Calculate the aspect ratio of the final outer contour edge line:
[0094]
[0095] in, represents the second eigenvalue; Indicates the third intersection point of the final outer contour edge line and the positive semi-axis of the vertical axis of the coordinate system; Indicates the fourth intersection point of the final outer contour edge line and the negative semi-axis of the vertical axis of the coordinate system; Indicates the first intersection point of the final outer contour edge line and the positive semi-axis of the horizontal axis of the coordinate system; Indicates the second intersection point of the final outer contour edge line and the negative semi-axis of the horizontal axis of the coordinate system.
[0096] The product of the first eigenvalue and the second eigenvalue is used as the roundness of the final outer contour edge line. The calculation formula is:
[0097]
[0098] in, Indicates the roundness of the final outer contour edge line; represents the first eigenvalue; Represents the second eigenvalue. When the final outer contour edge line is closer to the standard circle, the ratio of the length and width of the curve approaches 1, and the ratio of the standard deviation of the curve to the virtual radius is smaller; as the values of S and C gradually increase, the roundness of the final outer contour edge line will gradually decrease, so the smaller S and C are, the more likely it is a high-quality agricultural product, such as Figure 3 The diagram shows a high-quality agricultural product. The larger the S and C are, the more likely it is that the agricultural product is of low quality. Figure 4 Shown is a schematic diagram of low-quality agricultural products.
[0099] The agricultural products are classified using the second threshold, and the second threshold is set to G=2. The second threshold here is set based on experience.
[0100] When S*C > G, the agricultural products to be tested are judged to be low-quality agricultural products.
[0101] On the contrary, if S*C < G, the agricultural products to be tested are judged to be high-quality agricultural products.
[0102] Finally, the quality of agricultural products can be classified and intelligently graded.
[0103] Computer-aided agricultural product quality inspection and grading system, including:
[0104] An image acquisition module, used to acquire images of agricultural products to be inspected;
[0105] An initial outer contour edge line acquisition module is used to extract the skin portion of the agricultural product image to be detected as the initial agricultural product image and obtain the initial outer contour edge line of the initial agricultural product image;
[0106] A chain code sequence acquisition module is used to perform a chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain the chain code sequence of the initial outer contour edge line in a clockwise direction;
[0107] An abnormal chain code value selection module is used to calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values;
[0108] The final outer contour edge line acquisition module is used to form an abnormal edge from the pixel points corresponding to the abnormal chain code value, delete the abnormal edge from the initial outer contour edge line to obtain an incomplete edge line; and fill the incomplete edge line to obtain the final outer contour edge line of the epidermis;
[0109] A roundness calculation module is used to obtain the center point of the area enclosed by the final outer contour edge line, and calculate the roundness of the final outer contour edge line using the distance between each pixel point on the final outer contour edge line and the center point;
[0110] The grading module is used to grade agricultural products according to their roundness.
[0111] In summary, the present invention provides a computer-aided agricultural product quality inspection and grading method and system, which can accurately obtain the final outer contour edge line of the agricultural product, and use the distance between each pixel point and the center point on the final outer contour edge line to calculate the roundness of the final outer contour edge line, and grade the agricultural products according to the roundness.
[0112] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A computer-aided agricultural product quality detection and grading method, characterized in that: The method includes: Acquire images of agricultural products to be inspected; Extracting the skin portion of the agricultural product image to be detected as an initial agricultural product image, and obtaining an initial outer contour edge line of the initial agricultural product image; Perform chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain the chain code sequence of the initial outer contour edge line in a clockwise direction; Calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values; The abnormal edge is formed by the pixel points corresponding to the abnormal chain code value, and the incomplete edge line is obtained after deleting the abnormal edge from the initial outer contour edge line; Filling the incomplete edge line to obtain the final outer contour edge line of the epidermis; Obtain the center point of the area enclosed by the final outer contour edge line, calculate the roundness of the final outer contour edge line using the distance between each pixel point on the final outer contour edge line and the center point, and grade the agricultural products according to the roundness; The steps of calculating the roundness of the final outer contour edge line using the distance between each pixel point and the center point on the final outer contour edge line include: Establish a coordinate system with the center point of the area enclosed by the final outer contour edge line as the origin; Calculate the distance between each pixel point on the final outer contour edge line and the center point, form a distance set from all the obtained distance values, and use the average of all the obtained distances as the virtual radius; Calculate the standard deviation of all distance values in the distance set, and use the ratio of the standard deviation to the virtual radius as the first eigenvalue; Calculate the aspect ratio of the final outer contour edge line according to the intersection of the final outer contour edge line with the horizontal axis and the vertical axis of the coordinate system, and use the aspect ratio of the final outer contour edge line as the second eigenvalue; The product of the first eigenvalue and the second eigenvalue is used as the roundness of the final outer contour edge line.
2. The computer-aided agricultural product quality detection and grading method according to claim 1, characterized in that: The steps of calculating the aspect ratio of the final outer contour edge line according to the intersection of the final outer contour edge line and the horizontal axis and the vertical axis of the coordinate system include: Obtain the first intersection point of the final outer contour edge line with the positive semi-axis of the horizontal axis of the coordinate system and the second intersection point with the negative semi-axis of the horizontal axis of the coordinate system; Add the absolute value of the abscissa of the first intersection point and the absolute value of the abscissa of the second intersection point to obtain the width of the final outer contour edge line; Obtain the third intersection point of the final outer contour edge line with the positive semi-axis of the coordinate system longitudinal axis and the fourth intersection point with the negative semi-axis of the coordinate system longitudinal axis; Add the absolute value of the ordinate of the third intersection point and the absolute value of the ordinate of the fourth intersection point to obtain the length of the final outer contour edge line; Calculate the aspect ratio of the final outer contour edge line.
3. The computer-aided agricultural product quality detection and grading method according to claim 1, characterized in that: The steps for grading produce based on roundness include: When the roundness is greater than a preset second threshold, the agricultural product to be tested is determined to be a low-quality agricultural product; When the roundness is less than or equal to a preset second threshold, the agricultural product to be tested is determined to be a high-quality agricultural product.
4. The computer-aided agricultural product quality detection and grading method according to claim 1, characterized in that: The steps of extracting the skin portion of the agricultural product image to be detected as the initial agricultural product image include: Perform color clustering on the agricultural product image to be detected and extract the skin part of the image as the initial agricultural product image.
5. The computer-aided agricultural product quality detection and grading method according to claim 1, characterized in that: The steps of filling the incomplete edge line to obtain the final outer contour edge line of the epidermis include: The convex hull algorithm is used to fill the incomplete edge line to obtain the final outer contour edge line of the epidermis.
6. A computer-aided agricultural product quality inspection and grading system, implementing the method as claimed in claim 1, characterized in that: include: An image acquisition module, used to acquire images of agricultural products to be inspected; An initial outer contour edge line acquisition module is used to extract the skin portion of the agricultural product image to be detected as the initial agricultural product image and obtain the initial outer contour edge line of the initial agricultural product image; A chain code sequence acquisition module is used to perform a chain code operation on the initial outer contour edge line starting from any pixel point on the initial outer contour edge line, and obtain the chain code sequence of the initial outer contour edge line in a clockwise direction; An abnormal chain code value selection module is used to calculate the difference between two adjacent chain code values in the chain code sequence, and select two adjacent chain code values whose absolute value of the difference is less than or equal to a preset first threshold as abnormal chain code values; The final outer contour edge line acquisition module is used to form an abnormal edge from the pixel points corresponding to the abnormal chain code value, delete the abnormal edge from the initial outer contour edge line to obtain an incomplete edge line; and fill the incomplete edge line to obtain the final outer contour edge line of the epidermis; A roundness calculation module is used to obtain the center point of the area enclosed by the final outer contour edge line, and calculate the roundness of the final outer contour edge line using the distance between each pixel point on the final outer contour edge line and the center point; The grading module is used to grade agricultural products according to their roundness.
Citation Information
Patent Citations
Test and classification method
CN101322969A
Nuclear magnetic resonance tumor region extraction method
CN115797356A