A forage feed detection method based on machine vision
Through dynamic illumination correction and multi-level feature extraction algorithms, the problems of illumination changes and single features in forage feed detection are solved, high-precision forage freshness assessment is achieved, and the objectivity and reliability of detection are enhanced.
Patent Information
- Application Number
- CN202510950088.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-07-10
AI Technical Summary
Existing forage feed detection methods rely on manual observation and are easily affected by changes in ambient light. Single color features cannot accurately characterize the freshness of forage, and texture features are insufficiently quantified, resulting in limited detection accuracy.
An image preprocessing algorithm based on dynamic illumination correction is adopted, and the color greenness and global average contrast are combined to generate a freshness index. The influence of illumination is eliminated by a dynamic illumination correction factor, and the color dynamic entropy and global contrast are used to quantify the forage characteristics, thus generating a multi-level feature extraction algorithm.
It improves the objectivity and consistency of test results, accurately distinguishes between fresh and aged forage, enhances detection accuracy and reliability, and provides multi-dimensional forage quality assessment.
Smart Images

Figure CN120451162B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of forage and feed detection, and in particular to a forage and feed detection method based on machine vision. Background Art
[0002] With the continuous advancement of agricultural modernization, the demand for refined management in agricultural production is increasing, especially in the quality monitoring and management of forage feed. The quality of forage feed is directly related to the production efficiency of animal husbandry, the health of animals and the quality of the final product. Traditional forage feed quality detection methods generally rely on manual inspection and traditional laboratory analysis, which are not only inefficient but also easily affected by human factors. The reliability and consistency of the test results are poor, and it is difficult to achieve automation and intelligence. It cannot be seamlessly connected with modern agricultural machinery and equipment. In order to improve the accuracy, efficiency and automation level of forage feed detection, machine vision-based detection technology has emerged as an efficient, accurate and non-destructive detection method.
[0003] Machine vision uses computers, sensors, and image processing to simulate the human eye's observation and analysis of target objects, and then uses algorithms to perform analysis and judgment. In forage and feed testing, machine vision technology can not only identify and analyze the appearance of forage, but also extract various parameters related to the forage through precise image processing techniques. This enables rapid and accurate forage and feed testing, and real-time assessment of forage quality and type. This avoids the interference of human factors in traditional forage and feed quality testing methods, improves the efficiency and accuracy of forage and feed testing, and becomes a very promising testing technology. In the future, with the continuous advancement of image processing, artificial intelligence, and big data technologies, machine vision will play an increasingly important role in forage and feed testing, providing more accurate and efficient quality control methods for agricultural production.
[0004] However, the above-mentioned existing forage feed detection methods lack objectivity and rely on manual observation or subjective judgment. In image-based detection technology, changes in ambient lighting are a common problem, which may cause image color distortion or inaccurate feature extraction. Focusing only on a single indicator makes it difficult to fully characterize the forage status, resulting in limited detection accuracy. Summary of the Invention
[0005] The present invention provides a forage forage detection method based on machine vision to solve the technical problems that color distortion caused by uneven illumination of the original image; a single color feature cannot accurately characterize the freshness of the forage; and insufficient quantization of texture features affects the assessment of the freshness of the forage.
[0006] The present invention provides a forage and feed detection method based on machine vision, which specifically includes the following technical solutions:
[0007] A forage fodder detection method based on machine vision comprises the following steps:
[0008] S1. Obtain a forage sample, generate an original image, and preprocess the original image using an image preprocessing algorithm based on dynamic illumination correction to obtain a preprocessed image;
[0009] S2. Use the grass freshness feature extraction algorithm to extract features related to grass freshness from the preprocessed image, including color greenness and global average contrast, and generate a freshness index based on the color greenness and global average contrast.
[0010] Preferably, the S1 specifically includes:
[0011] The image preprocessing algorithm based on dynamic illumination correction measures the brightness level of the original image by introducing a dynamic illumination correction factor. The dynamic illumination correction factor accumulates the total brightness values of all pixels in the original image to obtain the total brightness of the entire original image. By introducing a theoretical maximum brightness value, the average illumination intensity of the original image is evaluated, and the total brightness of the original image is divided by the product of the total number of pixels and the theoretical maximum brightness to obtain the dynamic illumination correction factor.
[0012] Preferably, the S1 specifically includes:
[0013] After calculating the dynamic lighting correction factor, the red, green, and blue channel values of each pixel are processed separately, and the original value of each channel is divided by the dynamic lighting correction factor to obtain the preprocessed channel value, including the preprocessed red channel value, the preprocessed green channel value, and the processed blue channel value, and each pixel of the original image is adjusted.
[0014] Preferably, the S2 specifically includes:
[0015] In the implementation process of the forage freshness feature extraction algorithm, based on the preprocessed red, green and blue channel values of the preprocessed image, the red and blue channel weight factors are introduced for each pixel, and the product of the red and blue channel weight factors and the sum of the red and blue channel values is subtracted from the green channel value to obtain a difference. The difference values of all pixels are summed up, and the sum of the preprocessed green channel values in the preprocessed image is calculated and normalized. The sum of the difference values is divided by the sum of the preprocessed green channel values to obtain the basic green bias.
[0016] Preferably, the S2 specifically includes:
[0017] In the implementation of the forage freshness feature extraction algorithm, the preprocessed green channel value is normalized into a probability distribution. The number of pixels appearing in the preprocessed image is counted and divided by the total number of pixels to obtain the occurrence probability of the preprocessed green channel value. The color dynamic entropy is calculated based on the occurrence probability of the preprocessed green channel value.
[0018] Preferably, the S2 specifically includes:
[0019] In the process of implementing the forage freshness feature extraction algorithm, the color dynamic entropy is used to dynamically adjust the basic greenness, and the difference between the color dynamic entropy and a benchmark entropy is calculated and taken in exponential form to obtain an exponential term. The exponential term is added by one and the reciprocal is taken to form a Function, the basic greenness and the The function values are multiplied to produce a final greenish color.
[0020] Preferably, the S2 specifically includes:
[0021] In the implementation of the forage freshness feature extraction algorithm, the contrast analysis technology based on image processing is used to calculate the local contrast in the neighborhood of each pixel in the preprocessed image, and the local contrast is integrated into the global average contrast. The texture characteristics of the forage surface are quantified by the global average contrast.
[0022] Preferably, the S2 specifically includes:
[0023] In the implementation process of the forage freshness feature extraction algorithm, an exponential decay term is designed based on the color greenness and global average contrast. The color greenness is multiplied by the exponential decay term and input into the inverse tangent function as an input to finally obtain the freshness index.
[0024] The beneficial effects of the technical solution of the present invention are:
[0025] 1. The image preprocessing algorithm based on dynamic illumination correction eliminates the impact of ambient lighting conditions on the quality of the original image, making subsequent feature extraction unaffected by external lighting changes. It is suitable for forage detection in different scenarios. The preprocessed image can truly reflect the color and texture characteristics of the forage, laying a reliable foundation for subsequent freshness analysis. By introducing a dynamic illumination correction factor, it avoids misjudgments caused by brightness deviations and enhances the objectivity and consistency of the detection results.
[0026] 2. Dynamically adjust the basic greenness using color dynamic entropy to generate the final greenness, which can accurately distinguish fresh grass from aged grass and objectively quantify the freshness of the grass.
[0027] 3. Global average contrast reflects the roughness of forage by quantifying the texture characteristics of the forage surface. Its negative correlation with the freshness of the forage provides a multi-dimensional basis for forage quality assessment.
[0028] 4. The multi-level feature extraction of the forage freshness feature extraction algorithm ensures the scientific quantification of forage freshness, avoids the misjudgment that may be caused by a single feature, and enhances the detection accuracy and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a flow chart of a forage feed detection method based on machine vision described in the present invention. DETAILED DESCRIPTION
[0030] In order to further illustrate the technical means and effects adopted by the present invention to achieve the predetermined purpose of the invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. 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 shall fall within the scope of protection of the present invention.
[0031] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0032] The following describes in detail a specific scheme of a forage and feed detection method based on machine vision provided by the present invention with reference to the accompanying drawings.
[0033] Refer to the attached Figure 1 , which shows a flow chart of a forage detection method based on machine vision provided by an embodiment of the present invention, the method comprising the following steps:
[0034] S1. Obtain a forage sample, generate an original image, and preprocess the original image using an image preprocessing algorithm based on dynamic illumination correction to obtain a preprocessed image;
[0035] A high-resolution RGB camera is used to capture forage samples, generating a raw image containing three color channels: red, green, and blue. The color value of each pixel is composed of three channels, and each channel has a value range of 0 to 255, reflecting the intensity of the pixel at the corresponding color. The size of the raw image is determined by its width and height, and the total number of pixels is the product of the width and height. The raw image is preprocessed using an image preprocessing algorithm based on dynamic illumination correction to calculate a preprocessed image.
[0036] The image preprocessing algorithm based on dynamic illumination correction introduces a dynamic illumination correction factor for measuring the brightness level of the entire original image. The dynamic illumination correction factor accumulates the total brightness values of all pixels in the original image to obtain the total brightness of the entire original image. In order to evaluate the average illumination intensity of the original image, a brightness normalization technique based on image processing is used. Specifically, a theoretical maximum brightness value is used as a reference, and the total brightness of the entire original image is divided by the product of the total number of pixels and the theoretical maximum brightness to obtain a ratio, namely the dynamic illumination correction factor. The value of the dynamic illumination correction factor reflects the overall illumination condition of the original image: if the original image is dark, the dynamic illumination correction factor is less than 1; if the original image is bright, the dynamic illumination correction factor may be close to or greater than 1.
[0037] After calculating the dynamic lighting correction factor, the red, green, and blue channel values of each pixel are processed separately. The original value of each channel is divided by the dynamic lighting correction factor to obtain the pre-processed channel value. Each pixel of the entire original image is adjusted one by one to ensure that the brightness of all pixels is scaled to a consistent standard level.
[0038] The calculation formula for the pixel value of the preprocessed image is:
[0039] ,
[0040] in, Represents the pixel value of the preprocessed image, which is the total brightness of the pixel after illumination correction. Each channel is preprocessed separately to obtain the preprocessed red channel value , green channel value after preprocessing And the processed blue channel value ; Indicates the dynamic illumination correction factor, which is used to standardize the brightness of the original image and eliminate the uneven brightness caused by lighting conditions (such as strong light or dark light) during shooting; Represents the sum of the brightness of all pixels in the original image, which is obtained by summing the total brightness of all pixels in the original image; Indicates the total number of pixels; Indicates the theoretical maximum brightness value. As part of the denominator, it reflects the theoretical upper limit of brightness and is used for standardization.
[0041] Dynamic illumination correction optimizes the original image, providing a reliable basis for forage and fodder detection. This eliminates illumination interference, supports physical property analysis, enhances robustness, and improves detection accuracy.
[0042] S2. Using a grass freshness feature extraction algorithm, extract features related to grass freshness from the preprocessed image, including color greenness and global average contrast, and generate a freshness index based on the color greenness and global average contrast;
[0043] A grass freshness feature extraction algorithm is used to extract features related to grass freshness from the preprocessed image, including color greenness and global average contrast, and generate a freshness index.
[0044] The freshness of forage is usually positively correlated with its greenness, while aged or spoiled forage may appear yellow-brown or gray. The forage freshness feature extraction algorithm calculates the basic greenness and introduces color dynamic entropy to dynamically adjust the greenness.
[0045] The calculation of the basic green bias is based on RGB color analysis technology, which quantifies the degree of green deviation by the difference between the green channel and the red and blue channels. Specifically, based on the preprocessed RGB channel values of the preprocessed image, a red and blue channel weight factor is introduced for each pixel to balance the contribution of the red and blue channels to the prominence of green. The value range is ; Subtract the product of the red and blue channel weight factor and the sum of the preprocessed red channel value and the preprocessed blue channel value from the preprocessed green channel value to obtain a difference value, which reflects the degree of green deviation of the pixel. The difference values of all pixels are summed to obtain a difference sum, which represents the total degree of green deviation of the entire preprocessed image. The sum of the preprocessed green channel values in the preprocessed image is calculated for normalization processing. The difference sum is divided by the sum of the preprocessed green channel values to obtain the basic green bias.
[0046] In order to further improve the representation ability of color features, the forage freshness feature extraction algorithm is based on the Shannon entropy theory in information theory. The color dynamic entropy of the preprocessed green channel is calculated to quantify the uncertainty of the color distribution. Specifically, the preprocessed green channel value is normalized to a probability distribution. For each possible value of the green channel, the number of pixels appearing in the preprocessed image is counted and divided by the total number of pixels to obtain the probability of occurrence of the preprocessed green channel value. The color dynamic entropy is calculated based on the probability of occurrence of the preprocessed green channel value, that is, the logarithm of the probability value of the occurrence of each preprocessed green channel value is taken (base After being e), it is multiplied by the probability of occurrence of the preprocessed green channel value and the sum is taken, and then the negative number is taken. In order to avoid errors in the logarithmic calculation when the probability is zero, a small positive number is added to the probability of occurrence value, and finally the color dynamic entropy is obtained, which is used to reflect the distribution complexity of the preprocessed green channel value. The concentration of the preprocessed green channel value determines the level of color dynamic entropy. When the preprocessed green channel value is concentrated in a few values (such as the bright green of fresh grass), the color dynamic entropy is low; when the preprocessed green channel value distribution is dispersed (such as the multiple colors of aging or deteriorated grass), the color dynamic entropy is high.
[0047] The calculation formula of color dynamic entropy is:
[0048] ,
[0049] in, represents the color dynamic entropy, which is used to measure the distribution complexity of the green channel value after preprocessing and is negatively correlated with the freshness of the forage; Represents all possible green channel values after preprocessing Perform summation and traverse the distribution of preprocessed green channel values; Represents a small positive number, used to ensure numerical stability, with a value range of [ ]; represents the natural logarithm (base e), which is used to calculate the amount of information. The information is calculated by the probability distribution and logarithm of the preprocessed green channel value, and is used to reflect the uncertainty or complexity of the color distribution. Represents the green channel value after preprocessing The probability of occurrence of is in the range of , reflecting the green channel value after preprocessing The distribution ratio in the preprocessed image, Represents the possible value of the green channel after preprocessing, ranging from ; represents the indicator function, when The probability of the green channel value after preprocessing is 1, otherwise it is 0, which is used to count the green channel value after preprocessing. The number of pixels; Indicates that the green channel value is The total number of pixels; Indicates the total number of pixels, used for normalization;
[0050] The basic green degree is dynamically adjusted using the color dynamic entropy to generate the final color green degree. Specifically, the difference between the color dynamic entropy and a reference entropy is calculated and the exponential form is taken to obtain an exponential term. The exponential term is added to the Then take the reciprocal to form a Function, used to suppress or amplify the basic green bias, the basic green bias and the Multiply the function values to get the final green color, ensuring that the output range is within At the same time, the green feature is dynamically adjusted by the color dynamic entropy. When the color dynamic entropy is low (fresh grass), the color greenness is close to the basic greenness; when the color dynamic entropy is high (aged grass), the color greenness is suppressed.
[0051] The calculation formula for the greenness of the color is:
[0052] ,
[0053] in, Indicates the greenness of the color. By combining the basic greenness and color dynamic entropy, it accurately reflects the freshness of the forage. Indicates the basic greenness, which is used to preliminarily quantify the green characteristics of forage as a direct reflection of forage freshness; express Function, the value range is , used to dynamically adjust the size of the basic greenness; It represents the baseline entropy, reflecting the entropy cutoff point between fresh and aged forage. It can be set according to the specific implementation scenario and is not limited here. Indicates entropy deviation, which is used to measure the difference between the current color dynamic entropy and the baseline entropy. A negative value indicates fresh grass, and a positive value indicates aging of grass.
[0054] Fresh grass usually has a smooth surface texture, while aged or deteriorated grass has a rough surface texture. Therefore, the grass freshness feature extraction algorithm is used to quantify the texture characteristics of the grass surface by calculating the global average contrast, which reflects the roughness of the grass and is negatively correlated with the freshness of the grass.
[0055] Using contrast analysis technology based on image processing, for each pixel in the preprocessed image, the local contrast in the neighborhood is calculated, and the local contrast is integrated into the global average contrast. Specifically, the maximum and minimum pixel values in the neighborhood are found, and the difference between the two is calculated to obtain the local contrast. The difference is divided by the gradient mean plus a small positive number to obtain a normalized local contrast value. The normalized local contrast values of all pixels in the preprocessed image are averaged to obtain the global average contrast. The texture of the fresh grass surface is smooth, the local contrast is low, and the global average contrast is low, while the texture of the aged or deteriorated grass surface is rough, the local contrast is high, and the global average contrast is high.
[0056] The calculation formula for global average contrast is:
[0057] ,
[0058] in, represents the global average contrast; Represents local contrast, which is used to quantify the intensity of texture changes in each pixel neighborhood; Used to define the neighborhood range; Indicates the maximum value of the pixel value in the pixel neighborhood; Indicates the minimum value of the pixel value in the pixel neighborhood; represents the gradient mean, which reflects the overall texture change level of the preprocessed image. The calculation method is well known to those skilled in the art and will not be described in detail here.
[0059] Generate the final freshness index based on the greenness of the color and the global average contrast;
[0060] The forage freshness feature extraction algorithm designs an exponential decay term to comprehensively consider the influence of color greenness and global average contrast. Specifically, an interaction term is calculated, which is the product of color greenness and global average contrast, and multiplied by an interaction adjustment factor to consider the nonlinear coupling effect of color greenness and global average contrast, thereby enhancing the sensitivity to abnormal conditions (such as green but rough forage). After adding 1 to the interaction term, it is multiplied by the global average contrast and a contrast decay factor to obtain an exponential decay term. The color greenness is multiplied by the exponential decay term and input into the inverse tangent function as an input term to obtain a value in the range of In order to map the result to The range, multiplied by The final freshness index value is The higher the value, the fresher the grass.
[0061] The calculation formula of freshness index is:
[0062] ,
[0063] in, Represents the freshness index, reflecting the freshness of the forage feed. The output value range is When the freshness index is closer to 1, the grass is fresher, and vice versa, the grass is older or deteriorated. Represents the normalization factor used to scale the output of the inverse tangent function from Zoom to ; Represents the inverse tangent function, introduces nonlinear mapping, and converts the input Compressed to a limited range and enhanced discrimination capability through S-shaped curve characteristics; The contribution of color features is dynamically adjusted, meaning that the freshness index depends not only on the greenness of the forage but is also dynamically modulated by the surface texture. This allows the freshness index to comprehensively consider the physical properties of color and texture, thereby quantifying the freshness of the forage more scientifically. represents the exponential decay term, and introduces nonlinear decay to reflect the inhibitory effect of the grass surface texture on the freshness index; Represents the contrast attenuation factor, which is used to adjust the degree of suppression of the global average contrast on the freshness index. The value range is , can be set according to the specific implementation scenario and is not limited here; represents the interactive adjustment term, which introduces the nonlinear coupling effect of color greenness and global average contrast, and enhances the sensitivity to abnormal conditions (such as green but rough); Represents the interaction adjustment factor, which is used to control the degree of coupling between grass color and texture. Its value range is , can be set according to the specific implementation scenario and is not limited here;
[0064] By calculating the freshness index, the freshness of forage feed can be scientifically and objectively quantified, providing a core indicator for forage quality assessment, which is of great significance for ensuring livestock health and optimizing forage feed utilization efficiency.
[0065] In summary, a forage feed detection method based on machine vision was completed.
[0066] The order in which the embodiments of the invention are presented is for illustrative purposes only and does not necessarily represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0067] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
[0068] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A forage and feed detection method based on machine vision, characterized in that: The following steps are involved: S1. Obtain a forage sample, generate an original image, and preprocess the original image using an image preprocessing algorithm based on dynamic illumination correction to obtain a preprocessed image; The image preprocessing algorithm based on dynamic illumination correction measures the brightness level of the original image by introducing a dynamic illumination correction factor. The dynamic illumination correction factor accumulates the total brightness values of all pixels in the original image to obtain the total brightness of the entire original image. By introducing the theoretical maximum brightness value, the average light intensity of the original image is evaluated. The dynamic illumination correction factor is obtained by dividing the total brightness of the original image by the product of the total number of pixels and the theoretical maximum brightness. After calculating the dynamic illumination correction factor, the red, green, and blue channel values of each pixel are processed separately. The original value of each channel is divided by the dynamic illumination correction factor to obtain the preprocessed channel value, including the preprocessed red channel value, the preprocessed green channel value, and the processed blue channel value, and each pixel of the original image is adjusted; S2. Use the grass freshness feature extraction algorithm to extract features related to grass freshness from the preprocessed image, including color greenness and global average contrast, and generate a freshness index based on the color greenness and global average contrast.
2. The forage and feed detection method based on machine vision according to claim 1, characterized in that: Said S2 specifically includes: In the implementation process of the forage freshness feature extraction algorithm, based on the preprocessed red, green and blue channel values of the preprocessed image, the red and blue channel weight factors are introduced for each pixel, and the product of the red and blue channel weight factors and the sum of the red and blue channel values is subtracted from the green channel value to obtain a difference. The difference values of all pixels are summed up, and the sum of the preprocessed green channel values in the preprocessed image is calculated and normalized. The sum of the difference values is divided by the sum of the preprocessed green channel values to obtain the basic green bias.
3. The forage and feed detection method based on machine vision according to claim 2, characterized in that: Said S2 specifically includes: In the implementation of the forage freshness feature extraction algorithm, the preprocessed green channel value is normalized into a probability distribution. The number of pixels appearing in the preprocessed image is counted and divided by the total number of pixels to obtain the occurrence probability of the preprocessed green channel value. The color dynamic entropy is calculated based on the occurrence probability of the preprocessed green channel value.
4. The forage and feed detection method based on machine vision according to claim 3, characterized in that: Said S2 specifically includes: In the process of implementing the forage freshness feature extraction algorithm, the color dynamic entropy is used to dynamically adjust the basic greenness, and the difference between the color dynamic entropy and a benchmark entropy is calculated and taken in exponential form to obtain an exponential term. The exponential term is added by one and the reciprocal is taken to form a Function, the basic greenness and the The function values are multiplied to produce a final greenish color.
5. The forage and feed detection method based on machine vision according to claim 4, characterized in that: Said S2 specifically includes: In the implementation of the forage freshness feature extraction algorithm, the contrast analysis technology based on image processing is used to calculate the local contrast in the neighborhood of each pixel in the preprocessed image, and the local contrast is integrated into the global average contrast. The texture characteristics of the forage surface are quantified by the global average contrast.
6. The forage and feed detection method based on machine vision according to claim 5, characterized in that: Said S2 specifically includes: In the implementation process of the forage freshness feature extraction algorithm, an exponential decay term is designed based on the color greenness and global average contrast. The color greenness is multiplied by the exponential decay term and input into the inverse tangent function as an input to finally obtain the freshness index.
Citation Information
Patent Citations
Weed detection method based on YOLOX deep learning
CN118279737A
Crop and weed separation identification method and system based on image processing and machine vision
CN119027809A