Rice field weed identification analysis method and system based on image recognition
By obtaining a binary rotational image of the paddy field and constructing coordinate points for filtering, the process of identifying weeds in the paddy field is simplified, the identification efficiency is improved, and weeds between rows of rice seedlings can be accurately identified.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CROP INST SICHUAN PROVINCE ACAD OF AGRI SCI
- Filing Date
- 2025-10-15
- Publication Date
- 2026-07-03
AI Technical Summary
Existing weed identification technologies in rice fields have failed to establish suitable detection methods based on the rice growing environment, resulting in cumbersome and complex identification processes that make it difficult to identify weeds efficiently.
By obtaining a binary rotational image of the paddy field, constructing coordinate points and filtering them, it is possible to determine whether there are abnormal plant areas, thus simplifying the weed identification process.
It improves the efficiency of weed identification, simplifies the identification process, and can accurately identify whether there are weeds growing in the blank areas between rows of rice seedlings.
Smart Images

Figure CN121392573B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of weed identification technology in rice fields, specifically to a method and system for weed identification and analysis in rice fields based on image recognition. Background Technology
[0002] In rice cultivation, weeds are one of the important factors affecting rice yield and quality. Traditional weed identification methods mainly rely on manual observation and experience, which is not only time-consuming and labor-intensive, but also inefficient when applied to large-scale rice fields, making it difficult to identify the types and distribution of weeds in a timely and accurate manner. With the continuous development of science and technology, the application of image recognition technology in the agricultural field has gradually attracted attention. Image recognition technology collects image information from rice fields and uses computer algorithms to extract and analyze features in the images, thereby achieving automatic weed identification.
[0003] Existing weed identification technologies rely on model training and recognition of weeds. However, the diversity of weed species and their similar color to rice seedlings make the overall process of weed identification complex. Weeds significantly impact rice yield, especially in the early stages of rice cultivation, and weeding during this period promotes better rice growth. To facilitate rice growth and management, rice is planted in rows. Therefore, the rows of seedlings and the spaces between them are clearly distinguishable, and weeds often grow in these spaces. Analyzing these spaces can simplify weed identification methods. For example, patent application CN119648790A discloses a method, device, equipment, and medium for detecting and locating weeds in rice fields using drones. This method uses different types of weeds for model training to identify them, but it is cumbersome and complex. Existing rice field weed identification technologies fail to establish suitable weed detection methods based on the rice growing environment, resulting in a cumbersome and complex overall identification process. Summary of the Invention
[0004] This invention aims to at least partially solve one of the technical problems in the prior art by obtaining a binary rotated image based on a binary image of rice; constructing coordinates from the first coordinate point to the f-th coordinate point based on the binary rotated image; filtering coordinates from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point; and determining whether abnormal plant areas appear based on the first filtered coordinate point to the f-th filtered coordinate point. This solves the problem that existing rice field weed identification technologies fail to set appropriate weed detection methods based on the rice growth environment, resulting in a cumbersome and complex overall identification process.
[0005] To achieve the above objectives, this application provides a method for identifying and analyzing weeds in rice paddies based on image recognition, comprising the following steps:
[0006] Acquire images of rice paddies in the seedling stage and label them as rice paddy images;
[0007] The paddy field was processed to obtain a grayscale image of the paddy field;
[0008] A first rice grayscale threshold and a second rice grayscale threshold are obtained based on a first number of rice seedling images;
[0009] A binary image of rice is obtained based on the grayscale image of paddy field, the first grayscale threshold of rice, and the second grayscale threshold of rice.
[0010] Obtaining a binary rotated image based on a rice binary image;
[0011] Construct the coordinates from the first coordinate point to the f-th coordinate point based on the binarized rotation graph;
[0012] Filter the coordinates from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point;
[0013] Determine whether there are abnormal plant areas based on the first filter coordinate point to the fth filter coordinate point.
[0014] Furthermore, obtaining a grayscale image of the paddy field by performing grayscale processing includes the following sub-steps:
[0015] Obtain the RGB value of each pixel in the paddy field image and mark it as the paddy field RGB value; use the grayscale conversion formula to convert the paddy field RGB value to grayscale value and mark it as the paddy field grayscale value; replace the paddy field RGB value of each pixel in the paddy field image with the corresponding paddy field grayscale value to obtain the paddy field grayscale image.
[0016] Furthermore, obtaining the first rice grayscale threshold and the second rice grayscale threshold based on a first number of rice seedling images includes the following sub-steps:
[0017] The first number of rice images in the seedling stage are marked as historical rice images; the historical rice images are then converted to grayscale to obtain historical rice grayscale images.
[0018] Obtain the grayscale values of pixels in a historical rice grayscale image and mark them as historical grayscale values;
[0019] Obtain the minimum and maximum values of historical grayscale values, and mark them as the first and second grayscale thresholds for rice, respectively.
[0020] Furthermore, obtaining the binarized image of rice based on the paddy field grayscale image, the first rice grayscale threshold, and the second rice grayscale threshold includes the following sub-steps:
[0021] The gray values of rice that are greater than or equal to the first rice gray value threshold and less than or equal to the second rice gray value threshold are set to 0, and the gray values of rice that are less than the first rice gray value threshold or greater than the second rice gray value threshold are set to 255, thus obtaining a rice binarized image.
[0022] Furthermore, obtaining a binarized rotated image based on the rice binarized image includes the following sub-steps:
[0023] Establish a Cartesian coordinate system and label it as the image reference coordinate system; place the binarized rice image in the first quadrant of the image reference coordinate system;
[0024] Mark the pixels with a grayscale value of 0 in the binarized image of rice as plant pixels;
[0025] Create a square region consisting of N×N pixels, and mark it as the initial square region;
[0026] Obtain an initial square region composed entirely of plant pixels, and mark it as the final square region;
[0027] Obtain the plant pixel in the center of the final square area and mark it as a line pixel;
[0028] Draw a straight line that passes through the pixel of the straight line and mark it as the rotated line;
[0029] Rotate the rotating line 180° around the line pixel as the rotation center. During the rotation, obtain the number of plant pixels that the rotating line passes through in real time and mark it as the rotation count. Adjust the rotating line to the position when the rotation count is maximum and mark the rotating line at this position as the reference line.
[0030] Next, rotate the binarized rice image and the reference line simultaneously around the line's pixel point. Stop when the reference line is parallel to the Y-axis in the image's reference coordinate system. Obtain the binarized rice image at this point and mark it as the binarized rotated image.
[0031] Furthermore, constructing the coordinates from the first coordinate point to the f-th coordinate point based on the binarized rotation graph includes the following sub-steps:
[0032] Obtain the line segment that intersects the reference line with the binary rotated image, and mark it as the reference line segment;
[0033] Obtain the ordinate of the center point of the reference line segment and mark it as the starting abscissa; obtain the coordinate point on the Y-axis whose ordinate is the starting abscissa and mark it as the starting coordinate point;
[0034] Starting from the initial coordinate point, draw a second number of coordinate points with an interval of M along the positive and negative directions of the Y-axis, and mark them as reference coordinate points;
[0035] Create a line segment of length L that is parallel to the X-axis and mark it as the search line segment;
[0036] Starting from any reference coordinate point, move the search line segment in the positive direction of the X-axis; successively obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the first coordinate point; then obtain the left endpoint of the search line segment just appearing but not touching the plant pixel, and mark it as the second coordinate point; then obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the third coordinate point; and so on, until the f-th coordinate point is obtained; where f is a positive integer;
[0037] Get the coordinates from the first coordinate point to the fth coordinate point of all reference coordinate points.
[0038] Furthermore, the process of filtering from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point includes the following sub-steps:
[0039] Obtain the x-coordinate of any one of the coordinate points from the first coordinate point to the f-th coordinate point, and mark it as the target x-coordinate;
[0040] Obtain the range of the target's x-coordinate; divide the range of the target data evenly into g parts, and mark them as the division ranges;
[0041] Obtain the frequency of the target's x-coordinate within each division range and mark it as the division frequency;
[0042] Mark the minimum value of the divided range as the starting value of the range, and mark the maximum value of the divided range as the ending value of the range;
[0043] Sort the corresponding frequency divisions according to the starting value of the range from small to large to obtain the frequency sequence number, which is a positive integer starting from 1.
[0044] Furthermore, the process of filtering from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point also includes the following sub-steps:
[0045] Get the sum of all the frequencies of each partition and label it Z;
[0046] The first frequency threshold is calculated as: Py = u × (Z ÷ f); where Py is the first frequency threshold, and u ranges from 0 to 1;
[0047] Classify the frequencies that are less than or equal to the first frequency threshold as abnormal frequencies;
[0048] Deleting abnormal frequencies by frequency sequence number from smallest to largest, stopping when a frequency division result is found that is not an abnormal frequency; deleting abnormal frequencies by frequency sequence number from largest to smallest, stopping when a frequency division result is found that is not an abnormal frequency.
[0049] After stopping deletion, obtain the starting value of the range corresponding to the smallest frequency sequence number and mark it as the first horizontal axis threshold; obtain the ending value of the range corresponding to the largest frequency sequence number and mark it as the second horizontal axis threshold.
[0050] Delete the coordinate points corresponding to the target x-coordinate that are less than the first x-coordinate threshold or greater than the second x-coordinate threshold;
[0051] After filtering the coordinates from the first coordinate point to the fth coordinate point, mark them as the first filtered coordinate point to the fth filtered coordinate point.
[0052] Furthermore, determining whether an abnormal plant area exists based on the first screening coordinate point to the f-th screening coordinate point includes the following steps:
[0053] The first to the f-th selected coordinate points are fitted with functions respectively to obtain the first to the f-th fitted functions;
[0054] Obtain all intervals between the (2×i)th fitted function and the (2×i+1)th fitted function, and mark them as the target interval; where i is a positive integer and (2×i+1) is less than f;
[0055] The system acquires independent regions composed of plant pixels within the target range and marks them as abnormal plant regions. If an abnormal plant region is found, a signal indicating the presence of abnormal plants is emitted.
[0056] This application also provides a rice field weed identification and analysis system based on image recognition, including: an image acquisition module, a grayscale conversion module, a grayscale threshold acquisition module, a binarization module, a rotation module, a coordinate point acquisition module, a coordinate point filtering module, and an anomaly judgment module;
[0057] The image acquisition module is used to acquire images of rice paddies in the seedling stage and label them as rice paddy images;
[0058] The grayscale module is used to perform grayscale processing on the paddy field to obtain a grayscale image of the paddy field.
[0059] The grayscale threshold acquisition module is used to acquire a first rice grayscale threshold and a second rice grayscale threshold based on a first number of rice images at the seedling stage.
[0060] The binarization module is used to obtain a rice binarized image based on the paddy field grayscale image, the first rice grayscale threshold, and the second rice grayscale threshold.
[0061] The rotation module is used to obtain a binary rotated image based on the rice binary image;
[0062] The coordinate point acquisition module is used to construct coordinate points from the first coordinate point to the fth coordinate point based on the binary rotation diagram;
[0063] The coordinate point filtering module is used to filter the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point;
[0064] The anomaly detection module is used to determine whether an abnormal plant area exists based on the first screening coordinate point to the fth screening coordinate point.
[0065] The beneficial effects of this invention are as follows: This invention obtains a binarized rotated image based on a rice binarized image; constructs coordinates from the first coordinate point to the f-th coordinate point based on the binarized rotated image; filters coordinates from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point; and determines whether abnormal plant areas appear based on the first filtered coordinate point to the f-th filtered coordinate point. The advantage is that it can handle weed identification methods during the rice seedling stage, and this method is simpler and more suitable than the model training process for weeds, thus improving the efficiency of weed identification.
[0066] This invention constructs coordinates from the first coordinate point to the f-th coordinate point based on a binary rotation image. The advantage is that constructing coordinates from the first coordinate point to the f-th coordinate point facilitates the subsequent identification of the target region. The target region is the blank area between seedling rows. If plants appear in the blank area between seedling rows, the plants are very likely to be weeds. This method improves the efficiency of weed identification. Attached Figure Description
[0067] Figure 1 This is a schematic diagram of the system of the present invention;
[0068] Figure 2 This is a schematic diagram illustrating the positional relationship between the binarized rotated image and the image reference coordinate system of the present invention;
[0069] Figure 3 This is a schematic diagram of the distance from the first coordinate point to the f-th coordinate point in this invention;
[0070] Figure 4 This is a schematic diagram of the target area of the present invention;
[0071] Figure 5 This is a flowchart of the steps of the method of the present invention. Detailed Implementation
[0072] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0073] Example 1, please refer to Figure 1As shown, this application provides an image recognition-based rice paddy weed identification and analysis system, including:
[0074] The system includes an image acquisition module, a grayscale conversion module, a grayscale threshold acquisition module, a binarization module, a rotation module, a coordinate point acquisition module, a coordinate point filtering module, and an anomaly detection module.
[0075] The image acquisition module is used to acquire images of rice paddies during the seedling stage and label them as rice paddy images; rice paddy images can be obtained by drones taking aerial photos.
[0076] The grayscale module is used to perform grayscale processing on paddy fields to obtain a grayscale image of the paddy fields;
[0077] The grayscale module is configured with grayscale strategies, which include:
[0078] Obtain the RGB value of each pixel in the paddy field image and mark it as the paddy field RGB value; use the grayscale conversion formula to convert the paddy field RGB value to grayscale value and mark it as the paddy field grayscale value; replace the paddy field RGB value of each pixel in the paddy field image with the corresponding paddy field grayscale value to obtain the paddy field grayscale image;
[0079] In practical applications, for example, the RGB value of a paddy field is (52, 122, 52). There are various grayscale conversion formulas. Based on the grayscale conversion formula of the human eye's sensitivity to different colors, the grayscale value of the paddy field is calculated as: 0.299×52+0.578×122+0.114×52=92. The calculation result is kept as an integer. The RGB value of each pixel in the paddy field image is replaced with the corresponding grayscale value to obtain the grayscale image of the paddy field.
[0080] The grayscale threshold acquisition module is used to acquire a first rice grayscale threshold and a second rice grayscale threshold based on a first number of rice seedling images;
[0081] The grayscale threshold acquisition module is configured with a grayscale threshold acquisition strategy, which includes:
[0082] A first number of rice seedling images are marked as historical rice images; the historical rice images are converted to grayscale to obtain historical rice grayscale images; the first number of historical rice images can more accurately obtain the distribution range of pixel grayscale values after the rice image is converted, for example, the first number is set to 10;
[0083] Obtain the grayscale values of pixels in a historical rice grayscale image and mark them as historical grayscale values;
[0084] Obtain the minimum and maximum values of historical grayscale values, and label them as the first grayscale threshold and the second grayscale threshold of rice, respectively; obtaining the first grayscale threshold and the second grayscale threshold of rice facilitates subsequent binarization processing;
[0085] In practical applications, the first and second grayscale thresholds for rice are 92 to 152, respectively; the range between the first and second grayscale thresholds represents the distribution range of the grayscale values of rice.
[0086] The binarization module is used to obtain a binarized image of rice based on the grayscale image of paddy fields, the first grayscale threshold of rice, and the second grayscale threshold of rice.
[0087] The binarization module is configured with binarization strategies, which include:
[0088] The gray values of rice that are greater than or equal to the first rice gray value threshold and less than or equal to the second rice gray value threshold are set to 0, and the gray values of rice that are less than the first rice gray value threshold or greater than the second rice gray value threshold are set to 255 to obtain a rice binarized image. It should be noted that since weeds and rice seedlings are similar in color, the pixels with a gray value of 0 here may also include the pixels of weeds.
[0089] In practical applications, rice gray values greater than or equal to 92 and less than or equal to 152 are set to 0, while rice gray values less than 92 or greater than 152 are set to 255 to obtain a binary image of rice.
[0090] The rotation module is used to obtain a binary rotated image based on a rice binarized image;
[0091] The rotation module is configured with rotation strategies, which include:
[0092] Establish a Cartesian coordinate system and label it as the image reference coordinate system; place the binarized image of rice in the first quadrant of the image reference coordinate system; establishing the image reference coordinate system facilitates positional analysis.
[0093] Mark the pixels with a grayscale value of 0 in the binarized image of rice as plant pixels;
[0094] Create a square region consisting of N×N pixels, and mark it as the initial square region. The initial square region is set to obtain pixels that are biased towards the center of the seedling. If the initial square region consists of plant pixels, the pixels will be biased towards the center of the seedling. Therefore, the larger N is, the more accurate the pixels obtained will be. However, it cannot exceed the range of the seedling's pixel outline. Therefore, N should not be too large, but moderate. For example, N is 5.
[0095] Obtain an initial square region composed entirely of plant pixels, and mark it as the final square region;
[0096] Obtain the plant pixel in the center of the final square area and mark it as a line pixel;
[0097] Draw a straight line that passes through the pixel of the straight line and mark it as the rotated line;
[0098] Rotate the rotating line 180° around the line pixel as the rotation center. During the rotation, obtain the number of plant pixels that the rotating line passes through in real time and mark it as the rotation count. Adjust the rotating line to the position when the rotation count is maximum and mark the rotating line at this position as the reference line.
[0099] The benefits of obtaining a reference line are as follows: the pixels of the line are the pixels of the rice field. Since rice is planted in rows, when the number of rotations is maximized, the reference line is in the same column direction as the rice is planted. Therefore, the orientation of the reference line can be determined as the column direction of the rice field. Since the angle of the rice field image obtained by the drone is different, the angle of the rice field image can be adjusted by using the reference line to unify the angle of the rice binarized image to be analyzed, which facilitates subsequent processing of the rice binarized image.
[0100] Next, rotate the rice binarized image and the reference line simultaneously around the line's pixel point as the rotation center. Stop when the reference line is parallel to the Y-axis in the image reference coordinate system. Obtain the rice binarized image at this point and mark it as the binarized rotated image. Make the column direction of the rice planting parallel to the Y-axis in the image reference coordinate system to facilitate subsequent analysis of the binarized rotated image.
[0101] For practical applications, please refer to [link / reference]. Figure 2 As shown, after obtaining the binarized rotated image, the position of the plant pixel points in the image reference coordinate system is shown.
[0102] The coordinate point acquisition module is used to construct coordinate points from the first coordinate point to the fth coordinate point based on the binary rotated image;
[0103] The coordinate point acquisition module is configured with coordinate point strategies, which include:
[0104] Obtain the line segment that intersects the reference line with the binary rotated image, and mark it as the reference line segment;
[0105] Obtain the ordinate of the center point of the reference line segment and mark it as the starting abscissa; obtain the coordinate point on the Y-axis whose ordinate is the starting abscissa and mark it as the starting coordinate point;
[0106] Starting from the initial coordinate point, draw a second number of coordinate points with an interval of M along the positive and negative directions of the Y-axis, and mark them as reference coordinate points. The setting of the second number and M is based on the minimum length of the rice column in the obtained paddy field image. This is because if there is an angle between the side length of the obtained paddy field image and the column direction when the rice is planted, the length of the rice column in the paddy field image will be different. In order not to affect subsequent operations, the length formed by the reference coordinate points should be less than the minimum length of the rice column.
[0107] In practical applications, please refer to Figure 3. The second quantity is 5. Starting from the initial coordinate point, draw 5 coordinate points with a spacing of 5cm along the positive and negative directions of the Y-axis respectively, and mark them as reference coordinate points.
[0108] Create a line segment of length L parallel to the X-axis and mark it as the search line segment. The setting of L should be smaller than the blank distance between rice columns and larger than the gap between the leaves of a rice plant in the rice binarized image. For example, L is 6cm. This way, the first coordinate point to the f-th coordinate point of all subsequent reference coordinate points will correspond to the same rice column.
[0109] For practical applications, please refer to [link / reference]. Figure 3 As shown, the search line segment is drawn.
[0110] Starting from any reference coordinate point, move the search line segment in the positive direction of the X-axis; sequentially obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the 1st coordinate point; then obtain the left endpoint of the search line segment just appearing but not touching the plant pixel, and mark it as the 2nd coordinate point; then obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the 3rd coordinate point; and so on, until the f-th coordinate point is obtained; where f is a positive integer; obtain the 1st to f-th coordinate points of all reference coordinate points;
[0111] In practical applications, please refer to Figure 3 to obtain the coordinates from the 1st point to the fth point, where f is 12.
[0112] The coordinate point filtering module is used to filter the coordinate points from the first coordinate point to the fth coordinate point to obtain the first filtered coordinate point to the fth filtered coordinate point;
[0113] The coordinate point filtering module is configured with coordinate point filtering strategies, which include:
[0114] Get the x-coordinate of any coordinate point from the first coordinate point to the f-th coordinate point, and mark it as the target x-coordinate; filter out data that are abnormally large or small based on the target x-coordinate.
[0115] Obtain the range of the target x-coordinate; divide the range of the target data evenly into g parts, and mark them as the division ranges; the division ranges are used to observe the distribution of the target x-coordinate values; for example, g is 5;
[0116] Obtain the frequency of the target's x-coordinate within each division range and mark it as the division frequency;
[0117] Mark the minimum value of the divided range as the starting value of the range, and mark the maximum value of the divided range as the ending value of the range;
[0118] Sort the corresponding frequency divisions according to the starting value of the range from small to large to obtain the frequency sequence number, which is a positive integer starting from 1;
[0119] Get the sum of all the frequencies of each partition and label it Z;
[0120] The first frequency threshold is calculated as: Py = u × (Z ÷ f); where Py is the first frequency threshold, and u ranges from 0 to 1; the first frequency threshold is set to obtain the division frequency, so u should be set to be less than 1, for example, u is specifically 0.5;
[0121] Classify the frequencies that are less than or equal to the first frequency threshold as abnormal frequencies;
[0122] Deleting abnormal frequencies by frequency sequence number from smallest to largest, stopping when a frequency division result is found that is not an abnormal frequency; deleting abnormal frequencies by frequency sequence number from largest to smallest, stopping when a frequency division result is found that is not an abnormal frequency.
[0123] After stopping deletion, obtain the starting value of the range corresponding to the smallest frequency sequence number and mark it as the first horizontal axis threshold; obtain the ending value of the range corresponding to the largest frequency sequence number and mark it as the second horizontal axis threshold.
[0124] Delete the coordinate points corresponding to the target x-coordinate that are less than the first x-coordinate threshold or greater than the second x-coordinate threshold;
[0125] After filtering the coordinates from the first coordinate point to the fth coordinate point, mark them as the first filtered coordinate point to the fth filtered coordinate point;
[0126] The beneficial effects of obtaining the first filter coordinate point to the f-th filter coordinate point are: not only can the subsequent function fitting obtain the first to the f-th fitting functions more closely to the edge of the rice column, but also when weeds appear between the rice columns, the influence of each filter coordinate point between the first and the f-th filter coordinate points not being in the same rice column can be eliminated.
[0127] In practical applications, taking the x-coordinate of the first filter point as the target x-coordinate as an example, the range of the target x-coordinate is obtained as 21.2 to 22.2; divided into 5 parts: 21.2 to 21.4, 21.4 to 21.6, ..., 22.0 to 22.2; the obtained frequencies are 1, 4, 7, 6, and 2 respectively; the obtained Z is 20, and the first frequency threshold is calculated as: Py = 0.5 × (20 ÷ 5) = 2; therefore, the first frequency threshold is 2; the frequencies less than or equal to 2 are marked as abnormal frequencies; therefore, 1 and 2 are abnormal frequencies; after deletion, the first x-coordinate threshold is obtained as 21.4, and the second x-coordinate threshold is obtained as 22.0. The first coordinate points corresponding to the target x-coordinates less than 21.4 or greater than 22.0 are deleted, and the remaining first coordinate points are marked as the first filter point. Similarly, the first to f filter points are obtained; please refer to Figure 4 As shown, obtain the search coordinates from the first filter point to the fth filter point.
[0128] The anomaly detection module is used to determine whether there are abnormal plant areas based on the first filter coordinate point to the fth filter coordinate point;
[0129] The exception detection module is configured with exception detection strategies, which include:
[0130] The first to the f-th selected coordinate points are fitted with functions respectively to obtain the first to the f-th fitted functions;
[0131] Obtain all intervals between the (2×i)th fitted function and the (2×i+1)th fitted function, and mark them as the target interval; where i is a positive integer and (2×i+1) is less than f;
[0132] The system acquires independent regions composed of plant pixels within the target area and marks them as abnormal plant regions. If an abnormal plant region is found, a signal indicating the presence of abnormal plants is emitted.
[0133] For practical applications, please refer to Figure 4 As shown, the first to the f-th fitting functions are obtained. Since f is 12, the target intervals are the intervals between the second and third fitting functions, the intervals between the fourth and fifth fitting functions, ..., the intervals between the tenth and eleventh fitting functions. Here, the target interval is the blank interval between the rice columns. No rice is planted in the blank intervals between the rice columns. If an independent region composed of plant pixels appears, that is, plants grow in the blank intervals between the rice columns where no rice is planted, in order to ensure that the rice planted in the rice columns grows normally, the plants growing in the target interval can be identified as weeds.
[0134] Example 2, please refer to Figure 5As shown, this application provides a method for identifying and analyzing weeds in rice paddies based on image recognition, including the following steps:
[0135] Step S1: Obtain an image of the rice paddy during the seedling stage and label it as a rice paddy image.
[0136] Step S2 involves converting the paddy field to grayscale to obtain a grayscale image of the paddy field. Step S2 includes the following sub-steps:
[0137] Step S201: Obtain the RGB value of each pixel in the paddy field image and mark it as the paddy field RGB value; use the grayscale conversion formula to convert the paddy field RGB value to a grayscale value and mark it as the paddy field grayscale value; replace the paddy field RGB value of each pixel in the paddy field image with the corresponding paddy field grayscale value to obtain the paddy field grayscale image.
[0138] Step S3: Obtain a first rice grayscale threshold and a second rice grayscale threshold based on a first number of rice seedling images; Step S3 includes the following sub-steps:
[0139] Step S301: Mark the first number of rice seedling images as historical rice images; perform grayscale processing on the historical rice images to obtain historical rice grayscale images;
[0140] Step S302: Obtain the grayscale values of pixels in the historical rice grayscale image and mark them as historical grayscale values;
[0141] Step S303: Obtain the minimum and maximum values of historical grayscale values, and mark them as the first rice grayscale threshold and the second rice grayscale threshold, respectively.
[0142] Step S4: Obtain a binarized image of rice based on the paddy field grayscale image, the first rice grayscale threshold, and the second rice grayscale threshold; Step S4 includes the following sub-steps:
[0143] Step S401: Set the gray values of rice that are greater than or equal to the first rice gray value threshold and less than or equal to the second rice gray value threshold to 0, and set the gray values of rice that are less than the first rice gray value threshold or greater than the second rice gray value threshold to 255, thereby obtaining a rice binarized image.
[0144] Step S5: Obtain a binarized rotated image based on the rice binarized image; Step S5 includes the following sub-steps:
[0145] Step S501: Establish a Cartesian coordinate system and mark it as the image reference coordinate system; place the binarized rice image in the first quadrant of the image reference coordinate system;
[0146] Step S502: Mark the pixels with a gray value of 0 in the rice binarized image as plant pixels;
[0147] Step S503: Create a square region constructed from N×N pixels and mark it as the initial square region;
[0148] Step S504: Obtain an initial square region composed entirely of plant pixels and mark it as the final square region;
[0149] Step S505: Obtain the plant pixel in the middle of the final square area and mark it as a straight line pixel;
[0150] Draw a straight line that passes through the pixel of the straight line and mark it as the rotated line;
[0151] Step S506: Rotate the rotating line 180° around the line pixel as the rotation center. During the rotation, obtain the number of plant pixels that the rotating line passes through in real time and mark it as the rotation count. Adjust the rotating line to the position when the rotation count is the maximum and mark the rotating line at this position as the reference line.
[0152] Step S507: Then rotate the rice binarized image and the reference line simultaneously with the line pixel as the rotation center. Stop when the reference line is parallel to the Y-axis in the image reference coordinate system. Obtain the rice binarized image at this time and mark it as the binarized rotated image.
[0153] Step S6: Construct the coordinates from the first coordinate point to the f-th coordinate point based on the binarized rotated image; Step S6 includes the following sub-steps:
[0154] Step S601: Obtain the line segment where the reference line intersects with the binary rotated image, and mark it as the reference line segment;
[0155] Step S602: Obtain the ordinate of the center point of the reference line segment and mark it as the starting abscissa; obtain the coordinate point on the Y-axis whose ordinate is the starting abscissa and mark it as the starting coordinate point;
[0156] Step S603: Starting from the initial coordinate point, draw a second number of coordinate points with an interval of M along the positive and negative directions of the Y-axis respectively, and mark them as reference coordinate points;
[0157] Step S604: Create a line segment of length L that is parallel to the X-axis and mark it as the search line segment;
[0158] Step S605: Starting from any reference coordinate point, move the search line segment in the positive direction of the X-axis; sequentially obtain the right endpoint of the search line segment that just touches the plant pixel and mark it as the first coordinate point; then obtain the left endpoint of the search line segment that just appears but does not touch the plant pixel and mark it as the second coordinate point; then obtain the right endpoint of the search line segment that just touches the plant pixel and mark it as the third coordinate point; and so on, until the f-th coordinate point is obtained; where f is a positive integer;
[0159] Step S606: Obtain the first coordinate point to the f-th coordinate point of all reference coordinate points.
[0160] Step S7 involves filtering the coordinates from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point; Step S7 includes the following sub-steps:
[0161] Step S701: Obtain the x-coordinate of any one of the coordinate points from the first coordinate point to the f-th coordinate point, and mark it as the target x-coordinate;
[0162] Step S702: Obtain the range of the target x-coordinate; divide the range of the target data evenly into g parts and mark them as the division ranges;
[0163] Step S703: Obtain the frequency of the target x-coordinate within each division range and mark it as the division frequency;
[0164] Step S704: Mark the minimum value of the divided range as the starting value of the range, and mark the maximum value of the divided range as the ending value of the range;
[0165] Step S705: Sort the corresponding frequency divisions according to the starting value of the range from small to large to obtain the frequency sequence number, which is a positive integer starting from 1.
[0166] Step S706: Obtain the sum of all partition frequencies and label it as Z;
[0167] Step S707, calculate the first frequency threshold as: Py = u × (Z ÷ f); where Py is the first frequency threshold, and u ranges from 0 to 1;
[0168] Step S708: Mark the division frequencies that are less than or equal to the first frequency threshold as abnormal frequencies;
[0169] Step S709: Delete abnormal frequencies according to the frequency sequence number from smallest to largest, and stop when the frequency division is not an abnormal frequency; delete abnormal frequencies according to the frequency sequence number from largest to smallest, and stop when the frequency division is not an abnormal frequency.
[0170] Step S710: After stopping deletion, obtain the starting value of the range corresponding to the smallest frequency sequence number and mark it as the first horizontal axis threshold; obtain the ending value of the range corresponding to the largest frequency sequence number and mark it as the second horizontal axis threshold.
[0171] Step S711: Delete the coordinate points corresponding to the target horizontal coordinate that are less than the first horizontal coordinate threshold or greater than the second horizontal coordinate threshold;
[0172] Step S712: After filtering the coordinates from the first coordinate point to the f coordinate point, mark them as the first filtered coordinate point to the f filtered coordinate point.
[0173] Step S8: Determine whether an abnormal plant area exists based on the first screening coordinate point to the f-th screening coordinate point; Step S8 includes the following sub-steps:
[0174] Step S801: Perform function fitting on the first selected coordinate point to the f-th selected coordinate point respectively to obtain the first fitting function to the f-th fitting function;
[0175] Step S802: Obtain all intervals between the (2×i)th fitting function and the (2×i+1)th fitting function, and mark them as the target interval; where i is a positive integer and (2×i+1) is less than f;
[0176] Step S803: Obtain the independent region composed of plant pixels in the target interval and mark it as an abnormal plant region; if an abnormal plant region appears, issue an abnormal plant signal.
[0177] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0178] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings or direct couplings or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
Claims
1. A method for identifying and analyzing weeds in rice paddies based on image recognition, characterized in that, Includes the following steps: Acquire images of rice paddies in the seedling stage and label them as rice paddy images; The paddy field was processed to obtain a grayscale image of the paddy field; A first rice grayscale threshold and a second rice grayscale threshold are obtained based on a first number of rice seedling images; A binary image of rice is obtained based on the grayscale image of paddy field, the first grayscale threshold of rice, and the second grayscale threshold of rice. Obtaining a binary rotated image based on a rice binary image; Construct the coordinates from the first coordinate point to the f-th coordinate point based on the binarized rotation graph; Filter the coordinates from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point; Determine whether an abnormal plant area appears based on the first filter coordinate point to the f-th filter coordinate point; Constructing the path from the first coordinate point to the f-th coordinate point based on the binarized rotated image includes the following sub-steps: Obtain the line segment that intersects the reference line with the binary rotated image, and mark it as the reference line segment; Obtain the ordinate of the center point of the reference line segment and mark it as the starting abscissa; obtain the coordinate point on the Y-axis whose ordinate is the starting abscissa and mark it as the starting coordinate point; Starting from the initial coordinate point, draw a second number of coordinate points with an interval of M along the positive and negative directions of the Y-axis, and mark them as reference coordinate points; Create a line segment of length L that is parallel to the X-axis and mark it as the search line segment; Starting from any reference coordinate point, move the search line segment in the positive direction of the X-axis; successively obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the first coordinate point; then obtain the left endpoint of the search line segment just appearing but not touching the plant pixel, and mark it as the second coordinate point; then obtain the right endpoint of the search line segment just touching the plant pixel, and mark it as the third coordinate point; and so on, until the f-th coordinate point is obtained; where f is a positive integer; Obtain the coordinates from the first coordinate point to the f-th coordinate point of all reference coordinate points; Filtering from the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point includes the following sub-steps: Obtain the x-coordinate of any one of the coordinate points from the first coordinate point to the f-th coordinate point, and mark it as the target x-coordinate; Obtain the range of the target's x-coordinate; divide the range of the target data evenly into g parts, and mark them as the division ranges; Obtain the frequency of the target's x-coordinate within each division range and mark it as the division frequency; Mark the minimum value of the divided range as the starting value of the range, and mark the maximum value of the divided range as the ending value of the range; Sort the corresponding frequency divisions according to the starting value of the range from small to large to obtain the frequency sequence number, which is a positive integer starting from 1; Get the sum of all the frequencies of each partition and label it Z; The first frequency threshold is calculated as: Py = u × (Z ÷ f); where Py is the first frequency threshold, and u ranges from 0 to 1; Classify the frequencies that are less than or equal to the first frequency threshold as abnormal frequencies; Deleting abnormal frequencies according to the frequency sequence number from smallest to largest, stopping when a frequency division is found that is not an abnormal frequency; Delete abnormal frequencies according to the frequency sequence number from largest to smallest, and stop when the frequency division does not result in an abnormal frequency; After stopping deletion, obtain the starting value of the range corresponding to the smallest frequency sequence number and mark it as the first horizontal axis threshold; Obtain the end value of the range corresponding to the sequence number with the highest frequency, and mark it as the second horizontal axis threshold; Delete the coordinate points corresponding to the target x-coordinate that are less than the first x-coordinate threshold or greater than the second x-coordinate threshold; After filtering the coordinates from the first coordinate point to the fth coordinate point, mark them as the first filtered coordinate point to the fth filtered coordinate point; Determining whether an abnormal plant region exists based on the first filter coordinate point to the f-th filter coordinate point includes the following steps: The first to the f-th selected coordinate points are fitted with functions respectively to obtain the first to the f-th fitted functions; Obtain all intervals between the (2×i)th fitted function and the (2×i+1)th fitted function, and mark them as the target interval; Where i is a positive integer, and (2×i+1) is less than f; Obtain independent regions composed of plant pixels within the target range and mark them as abnormal plant regions; If an area with abnormal plants is detected, a signal indicating the presence of abnormal plants will be sent.
2. The method for identifying and analyzing weeds in rice paddies based on image recognition according to claim 1, characterized in that, Obtaining a grayscale image of a paddy field by performing grayscale processing includes the following sub-steps: Obtain the RGB value of each pixel in the paddy field image and mark it as the paddy field RGB value; use the grayscale conversion formula to convert the paddy field RGB value to grayscale value and mark it as the paddy field grayscale value; replace the paddy field RGB value of each pixel in the paddy field image with the corresponding paddy field grayscale value to obtain the paddy field grayscale image.
3. The method for identifying and analyzing weeds in rice paddies based on image recognition according to claim 2, characterized in that, Obtaining the first and second rice grayscale thresholds based on a first number of rice seedling images includes the following sub-steps: The first number of rice images in the seedling stage are marked as historical rice images; the historical rice images are then converted to grayscale to obtain historical rice grayscale images. Obtain the grayscale values of pixels in a historical rice grayscale image and mark them as historical grayscale values; Obtain the minimum and maximum values of historical grayscale values, and mark them as the first and second grayscale thresholds for rice, respectively.
4. The method for identifying and analyzing weeds in rice paddies based on image recognition according to claim 3, characterized in that, Obtaining a binarized image of rice based on the grayscale image of paddy fields, a first rice grayscale threshold, and a second rice grayscale threshold includes the following sub-steps: The gray values of rice that are greater than or equal to the first rice gray value threshold and less than or equal to the second rice gray value threshold are set to 0, and the gray values of rice that are less than the first rice gray value threshold or greater than the second rice gray value threshold are set to 255, thus obtaining a rice binarized image.
5. The method for identifying and analyzing weeds in rice paddies based on image recognition according to claim 4, characterized in that, Obtaining a binarized rotated image based on a rice binarized image includes the following sub-steps: Establish a Cartesian coordinate system and label it as the image reference coordinate system; place the binarized rice image in the first quadrant of the image reference coordinate system; Mark the pixels with a grayscale value of 0 in the binarized image of rice as plant pixels; Create a square region consisting of N×N pixels, and mark it as the initial square region; Obtain an initial square region composed entirely of plant pixels, and mark it as the final square region; Obtain the plant pixel in the center of the final square area and mark it as a line pixel; Draw a straight line that passes through the pixel of the straight line and mark it as the rotated line; Rotate the rotating line 180° around the line pixel as the rotation center. During the rotation, obtain the number of plant pixels that the rotating line passes through in real time and mark it as the rotation count. Adjust the rotating line to the position when the rotation count is maximum and mark the rotating line at this position as the reference line. Next, rotate the binarized rice image and the reference line simultaneously around the line's pixel point. Stop when the reference line is parallel to the Y-axis in the image's reference coordinate system. Obtain the binarized rice image at this point and mark it as the binarized rotated image.
6. A rice paddy weed identification and analysis system based on image recognition, used to implement the rice paddy weed identification and analysis method based on image recognition as described in any one of claims 1-5, characterized in that, It includes an image acquisition module, a grayscale conversion module, a grayscale threshold acquisition module, a binarization module, a rotation module, a coordinate point acquisition module, a coordinate point filtering module, and an anomaly detection module; The image acquisition module is used to acquire images of rice paddies in the seedling stage and label them as rice paddy images; The grayscale module is used to perform grayscale processing on the paddy field to obtain a grayscale image of the paddy field. The grayscale threshold acquisition module is used to acquire a first rice grayscale threshold and a second rice grayscale threshold based on a first number of rice images at the seedling stage. The binarization module is used to obtain a rice binarized image based on the paddy field grayscale image, the first rice grayscale threshold, and the second rice grayscale threshold. The rotation module is used to obtain a binary rotated image based on the rice binary image; The coordinate point acquisition module is used to construct coordinate points from the first coordinate point to the fth coordinate point based on the binary rotation diagram; The coordinate point filtering module is used to filter the first coordinate point to the f-th coordinate point to obtain the first filtered coordinate point to the f-th filtered coordinate point; The anomaly detection module is used to determine whether an abnormal plant area exists based on the first screening coordinate point to the fth screening coordinate point.
Citation Information
Patent Citations
Method, device and equipment for detecting and positioning weeds in rice field based on unmanned aerial vehicle, and medium
CN119648790A
Weed recognition method and device, computing equipment and storage medium
CN113807130A
Method for automatically identifying field weeds in crop seeding-stage using site and grain characteristic
CN1936919A