Cotton grading detection method and system based on machine vision

Through machine vision technology and convolutional neural network model, combined with Sobel operator to calculate gradient strength and connection distance, the problem of subjectivity and insufficient generalization ability of existing cotton grading methods is solved, and cotton grading is automated, intelligent and efficient. change.

CN118570648APending Publication Date: 2024-08-30COMPREHENSIVE TECH CENT FOR INSPECTION & QUARANTINE OF ZHANGJIAGANG ENTRY EXIT INSPECTION & QUARANTINE BUREAU
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410882595.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing cotton grading methods rely on manual judgment, which is subjective, low-efficiency, easy to fatigue, and prone to large errors. Furthermore, cotton grading models based on machine vision have insufficient generalization capabilities under the influence of factors such as illumination, color shift, and background clutter, and cannot Stably detect the quality of different types of cotton.

Method used

A cotton grading detection method based on machine vision is used to obtain cotton images through a macro acquisition terminal, preprocessing and block processing are performed, and the convolutional neural network model and Sobel operator are combined to calculate the gradient intensity and connection distance, and calculate the classification score weight to achieve Automated and intelligent grading of cotton.

Benefits of technology

It improves the accuracy and stability of cotton grading, significantly improves the model's discrimination and adaptability to cotton image features, reduces the impact of illumination and color deviation, and realizes automation, intelligence and efficiency of cotton grading.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570648A
    Figure CN118570648A
Patent Text Reader

Abstract

The invention relates to the technical field of cotton detection, and discloses a cotton grading detection method and system based on machine vision, and the method comprises the steps: obtaining a cotton image, carrying out the preprocessing of the cotton image, carrying out the blocking processing of the preprocessed cotton image, obtaining a plurality of blocking sub-images, training the blocking sub-images through a neural network model, and obtaining a cotton grading detection result. Outputting a classification score of each block sub-image, converting the classification scores into probability values, and performing cotton classification according to the probability values; the technology of image preprocessing, classification score weight calculation, a convolutional neural network model, probability calculation and the like is combined, and the purpose is to achieve automation, intelligence and high efficiency of cotton grading.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cotton detection, and in particular to a cotton grading detection method and system based on machine vision. Background Art

[0002] In modern agriculture and textile industry, accurate grading of cotton quality is a crucial link. Traditional cotton grading mainly relies on manual visual inspection, and experts use their experience to judge the color, maturity, fiber length and other characteristics of cotton to determine the grade of cotton. However, this manual grading method has many limitations, such as subjectivity, low efficiency, fatigue and large errors, which makes it difficult to meet the needs of modern industrial production. In recent years, with the development of machine vision technology and artificial intelligence, research on automatic cotton grading using image processing and deep learning models has gradually emerged. Machine vision technology can provide an objective, fast and continuous means of cotton quality evaluation, while deep learning models, especially convolutional neural networks (CNNs), have become a hot topic in the field of cotton grading due to their powerful feature extraction capabilities and high-precision classification performance. Although the cotton grading detection method based on machine vision has made some progress, the image quality of cotton is affected by many factors, including lighting, color shift, background clutter, etc. These factors may lead to insufficient model training or limited generalization ability; there are many varieties of cotton, and there are large differences in characteristics such as fiber length, color and density. The existing model cannot guarantee strong stability for grading detection of different types of cotton, which leads to reduced prediction accuracy of the model and errors in the prediction results. Summary of the invention In order to solve the above technical problems, the present invention provides a cotton grading detection method and system based on machine vision to achieve automation, intelligence and efficiency of cotton grading.

[0003] The present invention provides a cotton grading detection method based on machine vision, comprising: Step S1, using a macro acquisition terminal to obtain a cotton image; Step S2, preprocessing the cotton image; Step S3, dividing the preprocessed cotton image into blocks to obtain a plurality of block sub-images; Step S4, training the sub-block images through a neural network model, calculating the classification score weight of each sub-block image in a softmax classification layer, and outputting the classification score of each sub-block image; Step S41, using the Sobel operator to calculate the gradient strength of the pre-processed cotton image and the block sub-image; Step S42, obtaining the first center point of the preprocessed cotton image and the second center point of the divided sub-image; Step S43, calculating the connection distance between the second center point and the first center point of each block sub-image, and combining the connection distances into a connection distance data set; Step S44, filtering out the maximum distance according to the connection distance data set; Step S45, calculating the classification score weight according to the gradient strength, connection distance, and maximum distance; Step S5, converting the classification scores into probability values, and classifying the cotton according to the probability values.

[0004] Furthermore, the preprocessing includes: performing color correction and data enhancement on the cotton image.

[0005] Furthermore, the connection distance between the second center point and the first center point of each block sub-image is calculated, and the connection distances are combined into a connection distance data set, which specifically includes the following steps: Step S43a, obtaining the feature vector I2 of the second center point, and obtaining the feature vector I1 of the first center point; Step S43b, obtaining the component I2(i, j) of the feature vector I2, and obtaining the component I1(i, j) of the feature vector I1; Step S43c, calculating the connection distance according to the component I2 (i, j) and the component I1 (i, j); Step S43d, arranging the calculated connection distances from high to low to form a connection distance data set {D1, ..., D z}, z represents the number of sub-images.

[0006] Furthermore, D1 in the connection distance data set is the maximum distance.

[0007] Furthermore, the classification scores are converted into probability values, and cotton is graded according to the probability values, including: Step S5a, obtaining a comprehensive score of each sub-block image according to the classification score and classification score weight of each sub-block image; Step S5b, using the softmax function to convert the comprehensive score of each sub-block image into a probability value; Step S5c, calculating a comprehensive probability value according to the probability value; Step S5d, determining the cotton classification according to the comprehensive probability value.

[0008] Furthermore, the calculation formula of the classification score weight is: ; In the formula, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of all sub-block images is Representatives in The connection distance between the second center and the first center of the z-th sub-block image in pixel coordinates, Represents the maximum distance, is a balance parameter.

[0009] Furthermore, the calculation formula of the connection distance is: ; Where i represents the pixel row coordinate of the i-th row of the sub-block image, j represents the pixel column coordinate of the j-th row of the sub-block image, n represents the maximum number of sub-block image rows, and t represents the maximum number of sub-block image columns. represents the component of the first center point eigenvector, represents the components of the second center point eigenvector, and p and q are control coefficients.

[0010] Further, the calculation formula of the comprehensive score is: ; In the formula, represents the comprehensive score of the z-th sub-block image, represents the classification score of the z-th sub-block image, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate.

[0011] The present invention also provides a cotton grading detection system based on machine vision, which is used to execute the above-mentioned cotton grading detection method based on machine vision, and includes the following modules: Cotton image acquisition module: used to acquire cotton images using a macro acquisition terminal; Preprocessing module: connected with the cotton image acquisition module, used for preprocessing the cotton image; Block processing module: connected to the preprocessing module, used for performing block processing on the preprocessed cotton image to obtain a number of block sub-images; Classification score prediction module: connected to the block processing module, used to train the block sub-images through the neural network model, calculate the classification score weight of each block sub-image in the softmax classification layer, and output the classification score of each block sub-image; Cotton grading module: connected to the classification score prediction module, used to convert the classification scores into probability values ​​and grade cotton according to the probability values.

[0012] The embodiments of the present invention have the following technical effects: 1. The present invention combines technologies such as image preprocessing, classification score weight calculation, convolutional neural network model and probability calculation, aiming to realize the automation, intelligence and efficiency of cotton grading.

[0013] 2. The present invention obtains high-definition cotton images through a macro acquisition terminal, and combined with preprocessing steps, effectively eliminates the influence of factors such as ambient light and color deviation on image quality, laying a solid foundation for subsequent image analysis. The Sobel operator is used to calculate the gradient intensity, which enhances the extraction of edge and texture features, further improves the discrimination of image features, and thus significantly improves the accuracy of cotton grading.

[0014] 3. Through block processing, the present invention divides the preprocessed image into multiple sub-images and trains these sub-images using a neural network model. During the training process, not only the classification score of each sub-image is considered, but also factors such as gradient strength, connection distance and maximum distance are introduced to calculate the classification score weight. This multi-dimensional weight calculation strategy enables the model to understand the local and global features of the image more comprehensively, and enhances the adaptability and robustness of the model to image changes. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0016] Figure 1 is a flow chart of a cotton grading detection method based on machine vision provided by an embodiment of the present invention; Figure 2 It is a structural diagram of a cotton grading detection system based on machine vision provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0017] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described clearly and completely below. 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 creative work belong to the scope of protection of the present invention.

[0018] Figure 1 is a flow chart of a cotton grading detection method based on machine vision provided by an embodiment of the present invention. Figure 1 , specifically including: Step S1, using a macro acquisition terminal to obtain a cotton image; Cotton images were acquired using a high-resolution camera equipped with a macro lens to ensure that the microstructure of the cotton fibers was captured. The camera was set to automatic white balance and fixed exposure time to ensure image consistency and repeatability.

[0019] Step S2, preprocessing the cotton image; Since the cotton image features are greatly affected by external lighting and acquisition equipment, in one embodiment of the present invention, the gray world method is used to perform color correction on the cotton image; the corrected cotton image can also be data enhanced, which not only expands the sample images, but also improves the robustness and generalization ability of the model. In one embodiment of the present invention, the data enhancement uses horizontal flipping, vertical flipping, and adding salt and pepper noise to keep the cotton image training sample size within a specified range.

[0020] It should be noted that the above preprocessing method is only an example. The preprocessing may also use contrast broadening, logarithmic transformation, density stratification, histogram equalization, Gaussian filtering, Laplace filtering and other methods, which do not limit the scope of protection of the present invention.

[0021] Step S3, dividing the preprocessed cotton image into blocks to obtain a plurality of block sub-images; Since the macroscopic structure of cotton has self-similar characteristics, in order to obtain more image features and training sample volume, it is necessary to segment the preprocessed cotton image to obtain several block sub-images, and then use bilinear interpolation to unify the size pixels of each block sub-image. Specifically, this embodiment uses a 3×3 block method for image segmentation.

[0022] Step S4, training the sub-block images through a neural network model, calculating the classification score weight of each sub-block image in a softmax classification layer, and outputting the classification score of each sub-block image; A deep learning model based on convolutional neural network (CNN) was constructed to train the sub-images to identify the quality characteristics of cotton fibers. A fully connected layer was set up before the output layer of the model to map the features to the cotton grade. A softmax function was used in the output layer to convert the classification scores into probability distributions, output the probability that each sub-image belongs to a different cotton grade, and effectively identify the cotton grade.

[0023] The convolutional neural network uses several block sub-images after block processing and the calibrated grade labels as training sets to train the model, obtain the trained convolutional neural network model, and realize cotton grade classification.

[0024] During prediction, the cotton image to be predicted is input into the model, the classification score is output, and the comprehensive probability is obtained by combining the classification score weight to identify the predicted cotton grade.

[0025] Furthermore, the calculation process of the classification score weight is: Step S41, using the Sobel operator to calculate the gradient strength of the pre-processed cotton image and the block sub-image; The Sobel operator is a widely used edge detection operator used in image processing to extract the gradient information of an image, that is, to calculate the gradients of the image in the horizontal and vertical directions, thereby highlighting the boundaries and edges in the image. The Sobel operator can be applied to the entire image or to a local area of ​​the image, such as a sub-image, to calculate its gradient strength: The Sobel operator consists of a pair of 3x3 convolution kernels, which are used to calculate the gradient of the image in the horizontal and vertical directions respectively.

[0026] Horizontal gradient operator: ; Vertical gradient operator: ; Use the gradient operator of the Sobel operator to convolve the cotton image to obtain the gradient image in the horizontal direction , the gradient image in the vertical direction ; In this embodiment, the horizontal direction refers to the row direction of the image, and the vertical direction refers to the column direction of the image.

[0027] Finally, according to the gradient image in the horizontal direction , the gradient image in the vertical direction , calculate the gradient strength of the image: ; Representatives in The gradient strength of the sub-image block at pixel coordinates.

[0028] Step S42, obtaining the first center point of the preprocessed cotton image and the second center point of the divided sub-image; The midpoint of the preprocessed cotton image is taken as the first center point, and the midpoint of each block image is taken as the second center point.

[0029] Step S43, calculating the connection distance between the second center point and the first center point of each block sub-image, and combining the connection distances into a connection distance data set; Specifically: Step S43a, obtaining the feature vector I2 of the second center point, and obtaining the feature vector I1 of the first center point; Determine the coordinates of the center point: In this embodiment, the size of the preprocessed cotton image is W×H, and the coordinates of the first center point (the center of the preprocessed cotton image) are (2 / W, 2 / H). For each block sub-image, the coordinates of its second center point (i.e., the center of the block sub-image) can be calculated by the position and size of the block sub-image in the preprocessed cotton image.

[0030] The coordinates of the first center point and the second center point of each block sub-image are regarded as components of the feature vector.

[0031] Step S43b, obtaining the component I2(i, j) of the feature vector I2, and obtaining the component I1(i, j) of the feature vector I1; Extract the corresponding coordinate component x from the eigenvectors x and y respectively i and i , that is, the row and column coordinates of the center point of each block sub-image.

[0032] Step S43c, calculating the connection distance according to the component I2 (i, j) and the component I1 (i, j); ; Where i represents the pixel row coordinate of the i-th row of the sub-block image, j represents the pixel column coordinate of the j-th row of the sub-block image, n represents the maximum number of sub-block image rows, and t represents the maximum number of sub-block image columns. represents the component of the first center point eigenvector, represents the components of the second center point eigenvector, and p and q are control coefficients.

[0033] Specifically, Specifically, it refers to the pixel value of the first center in the i-th row and j-th column of the block sub-image. Specifically, it refers to the pixel value of the second center in the i-th row and j-th column in the sub-block image. The connection distance based on the difference in pixel values ​​can capture the detail differences of the image and help improve the accuracy of image matching and classification. Especially for the recognition of cotton in this embodiment, the difference measurement based on the pixel level is very critical.

[0034] Furthermore, the first center is preferably a block sub-image at the center of the cotton image. It is to calculate the connection distance between the edge block sub-images except the central block image and the central block image.

[0035] The p and q in the above formula are used to control the metric difference between the sub-images through the control system adjusted by the actual data. , .

[0036] The calculation of the connection distance introduces a logarithmic function to reduce the contribution of eigenvalues ​​with large differences to the total distance. This is particularly important in image analysis. Noise or outliers in the image may cause huge differences between eigenvectors. Using this formula can reduce the impact of these outliers on the final distance calculation, making the distance metric more stable and robust.

[0037] This embodiment calculates the connection distance so that the model can perceive the position of each block sub-image in the overall cotton image, thereby taking spatial information into account during classification.

[0038] Step S43d, arranging the calculated connection distances from high to low to form a connection distance data set {D1, ..., D z}, z represents the number of sub-images. , .

[0039] Step S44, filtering out the maximum distance according to the connection distance data set; D1 in the connection distance data set is the maximum distance D max .

[0040] Step S45, calculating the classification score weight according to the gradient strength, connection distance, and maximum distance; ; In the formula, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of all sub-block images is Representatives in The connection distance between the second center and the first center of the z-th sub-block image in pixel coordinates, Represents the maximum distance, is the balance parameter, .

[0041] Based on the weight calculation of gradient strength and connection distance, the contribution of each block sub-image to the final classification result can be dynamically adjusted, so that the model can pay more attention to areas containing rich information while reducing the impact of blurred edge areas.

[0042] The gradient and distance-based weight mechanism enhances the robustness of the model, enabling it to maintain high classification accuracy in the face of image quality variations, inconsistent lighting conditions, or local damage.

[0043] The block sub-images in the central area contain more details and key features. Introducing the connection distance into the classification score weight can give the central area a higher weight, which can enhance the model's ability to recognize core features and thus improve recognition accuracy.

[0044] The sub-image blocks far from the center point contain less information, or are the edge areas of the image. These areas will be affected by the boundary effect, resulting in feature distortion. By adjusting the weights according to the connection distance, the influence of the edge areas can be effectively suppressed, reducing their negative impact on the classification results.

[0045] The classification score weight of each sub-block image is affected not only by its own features, but also by its relative position in the image. This dual consideration enables the model to analyze the local features of the image more carefully and improves the accuracy of feature extraction.

[0046] Step S5, converting the classification scores into probability values, and classifying the cotton according to the probability values.

[0047] Specifically include: Step S5a, obtaining a comprehensive score of each sub-block image according to the classification score and classification score weight of each sub-block image; ; In the formula, represents the comprehensive score of the z-th sub-block image, represents the classification score of the z-th sub-block image, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate.

[0048] Each block sub-image is assigned a comprehensive score not only according to its classification score but also according to its relative importance in the image.

[0049] Step S5b, using the softmax function to convert the comprehensive score of each sub-block image into a probability value; The softmax function can convert a set of real numbers into a probability distribution, that is, each number is converted into a value between 0 and 1, and the sum of all values ​​is 1. By converting the comprehensive score of each sub-image through the softmax function, the probability of each sub-image belonging to a different cotton grade can be obtained. For example, S=[S1,S2,...,Sz] is the comprehensive score vector of all sub-images, then the normalized probability of the z-th sub-image is: ; Among them, Y represents the probability value, c represents the cotton classification level, and Q represents the maximum number of cotton classification levels.

[0050] Step S5c, calculating a comprehensive probability value according to the probability value; First, the cotton grades predicted in this embodiment include four categories: Excellent: long, strong, white, and few impurities. Good: The fiber length and strength are inferior to the excellent, but still maintain good quality. Qualified: Meet basic industrial uses, the fiber length and strength are average, and there may be a small amount of impurities. Unqualified: The fiber is short, fragile, poor in color, and has many impurities, which is not suitable for conventional textile uses.

[0051] The present embodiment is preferably a four-classification model, which predicts the comprehensive probability values ​​of cotton belonging to the four grades of "excellent", "good", "qualified" and "unqualified".

[0052] The probability values ​​of each sub-image are weighted averaged to obtain the comprehensive probability value of the entire image.

[0053] Step S5d, determining the cotton classification according to the comprehensive probability value.

[0054] The grade to which the highest comprehensive probability value belongs is taken as the predicted cotton grade, and the cotton grade is output.

[0055] Figure 2 is a structural diagram of a cotton grading detection system based on machine vision provided by an embodiment of the present invention. Figure 2 , including the following modules: Cotton image acquisition module: used to acquire cotton images using a macro acquisition terminal; Preprocessing module: connected with the cotton image acquisition module, used for preprocessing the cotton image; Block processing module: connected to the preprocessing module, used for performing block processing on the preprocessed cotton image to obtain a number of block sub-images; Classification score prediction module: connected to the block processing module, used to train the block sub-images through the neural network model, calculate the classification score weight of each block sub-image in the softmax classification layer, and output the classification score of each block sub-image; Cotton grading module: connected to the classification score prediction module, used to convert the classification scores into probability values ​​and grade cotton according to the probability values.

[0056] This embodiment can more accurately identify and distinguish different grades of cotton, especially when dealing with subtle differences, thereby improving the accuracy and consistency of identification.

[0057] This embodiment also provides an electronic device, which includes one or more processors and a memory.

[0058] The processor may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.

[0059] The memory may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor may run the program instructions to implement a cotton grading detection method based on machine vision and / or other desired functions of any embodiment of the present application described above. Various contents such as initial external parameters, thresholds, etc. may also be stored in the computer-readable storage medium.

[0060] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected through a bus system and / or other forms of connection mechanisms (not shown). The input device may include, for example, a keyboard, a mouse, etc. The output device may output various information to the outside, including early warning information, braking force, etc. The output device may include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, etc.

[0061] In addition, the electronic device may further include any other appropriate components according to specific application scenarios.

[0062] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of a cotton grading detection method based on machine vision provided in any embodiment of the present application.

[0063] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0064] In addition, an embodiment of the present application may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the steps of a cotton grading detection method based on machine vision provided in any embodiment of the present application.

[0065] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0066] It should be noted that the terms used in the present invention are only for describing specific embodiments, rather than limiting the scope of the present application. As shown in the present specification, unless the context clearly indicates an exception, the words "one", "a", "a kind of" and / or "the" do not specifically refer to the singular, but may also include the plural. The terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method or device. In the absence of more restrictions, the elements defined by the sentence "include one..." do not exclude the presence of other identical elements in the process, method or device including the elements.

[0067] It should also be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. Unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", etc. should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the technical solutions of the embodiments of the present invention.

Claims

1. A cotton grading detection method based on machine vision, characterized in that: include: Step S1, using a macro acquisition terminal to obtain a cotton image; Step S2, preprocessing the cotton image; Step S3, dividing the preprocessed cotton image into blocks to obtain a plurality of block sub-images; Step S4, training the sub-block images through a neural network model, calculating the classification score weight of each sub-block image in a softmax classification layer, and outputting the classification score of each sub-block image; Step S41, using the Sobel operator to calculate the gradient strength of the pre-processed cotton image and the block sub-image; Step S42, obtaining the first center point of the preprocessed cotton image and the second center point of the divided sub-image; Step S43, calculating the connection distance between the second center point and the first center point of each block sub-image, and combining the connection distances into a connection distance data set; Step S44, filtering out the maximum distance according to the connection distance data set; Step S45, calculating the classification score weight according to the gradient strength, connection distance, and maximum distance; Step S5, converting the classification scores into probability values, and classifying the cotton according to the probability values.

2. The method for detecting cotton grading based on machine vision according to claim 1, characterized in that: The preprocessing includes: color correction and data enhancement of the cotton image.

3. The method for cotton grading detection based on machine vision according to claim 2, characterized in that: Calculating the connection distance between the second center point and the first center point of each block sub-image and combining the connection distances into a connection distance data set specifically includes the following steps: Step S43a, obtaining the feature vector I2 of the second center point, and obtaining the feature vector I1 of the first center point; Step S43b, obtaining the component I2(i, j) of the feature vector I2, and obtaining the component I1(i, j) of the feature vector I1; Step S43c, calculating the connection distance according to the component I2 (i, j) and the component I1 (i, j); Step S43d, arranging the calculated connection distances from high to low to form a connection distance data set {D1, ..., D z }, z represents the number of sub-images.

4. The method for cotton grading detection based on machine vision according to claim 3, characterized in that: D1 in the connection distance data set is the maximum distance.

5. The method for cotton grading detection based on machine vision according to claim 4, characterized in that: The classification scores are converted into probability values, and cotton is graded according to the probability values, including: Step S5a, obtaining a comprehensive score of each sub-block image according to the classification score and classification score weight of each sub-block image; Step S5b, using the softmax function to convert the comprehensive score of each sub-block image into a probability value; Step S5c, calculating a comprehensive probability value according to the probability value; Step S5d, determining the cotton classification according to the comprehensive probability value.

6. The method for detecting cotton grading based on machine vision according to claim 5, characterized in that: The calculation formula of the classification score weight is: ; In the formula, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of the z-th sub-block image at the pixel coordinate, Representatives in The gradient strength of all sub-block images is Representatives in The connection distance between the second center and the first center of the z-th sub-block image in pixel coordinates, Represents the maximum distance, is a balance parameter.

7. The method for detecting cotton grading based on machine vision according to claim 6, characterized in that: The calculation formula of the connection distance is: ; Where i represents the pixel row coordinate of the i-th row of the sub-block image, j represents the pixel column coordinate of the j-th row of the sub-block image, n represents the maximum number of rows of the sub-block image, and t represents the maximum number of columns of the sub-block image. represents the component of the first center point eigenvector, represents the components of the second center point eigenvector, and p and q are control coefficients.

8. The method for cotton grading detection based on machine vision according to claim 5, characterized in that: The calculation formula of the comprehensive score is: ; In the formula, represents the comprehensive score of the z-th sub-block image, represents the classification score of the z-th sub-block image, Representatives in The classification score weight of the z-th sub-block image at the pixel coordinate.

9. The method for detecting cotton grading based on machine vision according to claim 8, characterized in that: The size of the block sub-image is 3×3.

10. A cotton grading detection system based on machine vision, used to execute the cotton grading detection method based on machine vision according to any one of claims 1 to 9, characterized in that: Includes the following modules: Cotton image acquisition module: used to acquire cotton images using a macro acquisition terminal; Preprocessing module: connected with the cotton image acquisition module, used for preprocessing the cotton image; Block processing module: connected to the preprocessing module, used for performing block processing on the preprocessed cotton image to obtain a number of block sub-images; Classification score prediction module: connected to the block processing module, used to train the block sub-images through the neural network model, calculate the classification score weight of each block sub-image in the softmax classification layer, and output the classification score of each block sub-image; Cotton grading module: connected to the classification score prediction module, used to convert the classification scores into probability values ​​and grade cotton according to the probability values.

Citation Information

Cited By

  • Imported American cotton grading detection method and system based on neural network

    CN118968201A

  • Method for detecting flowering process and flowering quality of peach tree

    CN119827489A