A rice appearance detection method and system
Through dynamic area division of the convex hull and maximum inscribed rectangle of rice grains and multi-threshold analysis of the HSV color space, combined with rice grain posture recognition, the problems of low efficiency, strong subjectivity and chemical staining risks in existing rice detection technologies are solved, and fast and accurate skin and embryo detection are achieved to meet the detection needs of different rice varieties.
Patent Information
- Application Number
- CN202510897608.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-07-01
AI Technical Summary
Existing rice testing technology has the disadvantages of low efficiency, strong subjectivity, poor repeatability, and chemical dyeing pretreatment is time-consuming and poses safety risks. It is difficult to meet the real-time quality control needs of modern industrial production, especially when distinguishing different rice varieties, the test results are unstable.
A dynamic area partitioning method based on the convex hull and maximum inscribed rectangle of rice grains is adopted, combined with multi-threshold analysis of the HSV color space and rice grain posture recognition. By acquiring color images at different angles, the skin and embryo remaining areas are accurately located, chemical staining is avoided, and rapid detection is performed using machine vision and geometric modeling technology.
It achieves the rapid and accurate detection of rice with husk and germ retained without chemical dyeing, improves the detection efficiency and accuracy, reduces costs, ensures the objectivity and consistency of the test results, and adapts to the natural color difference characteristics of different rice varieties.
Smart Images

Figure SMS_15
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to a method and system for detecting the appearance of rice. Background Art
[0002] In rice processing, accurate detection of the degree of husk and germ retention is a key indicator for evaluating rice milling quality. Traditional detection methods rely primarily on manual visual inspection or physical weighing, which are subject to inefficiency, subjectivity, and poor repeatability. These methods are particularly inadequate for meeting the stringent real-time quality control requirements of modern industrial production. In recent years, machine vision-based detection technologies have emerged. These use image analysis to quantify characteristics such as color and morphology, making it possible to objectively determine whether husk and germ are retained. However, existing techniques typically require pre-dyeing of rice kernels to effectively extract color features. For example, chemical dyeing is used to enhance the color contrast between the husk (yellow-brown) and germ regions. While these methods improve detection accuracy, the dyeing process involves multiple steps, including soaking, rinsing, and drying. This process is time-consuming, involving several hours of soaking, rinsing, and drying, and can also lead to the risk of chemical residues, severely limiting its application in large-scale production. Furthermore, the pre-dyeing rice kernels cannot be directly processed or consumed, further limiting the practicality of this technology.
[0003] Existing non-staining detection schemes are mostly based on single color models (such as RGB) or simple threshold segmentation. However, due to subtle differences in rice grain surface color, significant lighting interference, and diverse morphological varieties, detection results are unstable and difficult to distinguish between subtle color differences between rice kernels with husk, germ, and normal rice. This is especially true for different rice varieties (such as brown rice and pearl rice), where the hue distribution and germ morphology of the husk vary significantly. Existing algorithms have limited generalization capabilities and cannot adapt to multi-scenario detection requirements. Furthermore, traditional methods are poorly adaptable to the different positions (front / side) of rice kernels, leading to errors in region segmentation and increased misjudgment rates. Summary of the Invention
[0004] To solve the above problems, the present invention proposes a method and system for detecting the appearance of rice.
[0005] The main contents of the present invention include:
[0006] A rice appearance detection method comprises the following steps:
[0007] Obtain several original color images of single grains of rice at different angles;
[0008] Performing edge detection on the original color image to obtain corresponding edge information;
[0009] Obtain the convex hull of the rice grains based on the corresponding edge information;
[0010] According to the rice type and the convex hull of the rice grain, obtain the corresponding inscribed rectangle;
[0011] According to the inscribed rectangle of the partition, the original color image is divided into two end areas and a middle area;
[0012] Convert the two end areas and the middle area of the original color image to HSV space respectively to obtain the corresponding hue information and saturation information;
[0013] Calculate the area of the bag occupied by the skin in the middle region and the area of the bag occupied by the embryo in the two end regions according to the preset corresponding first threshold range and second threshold range;
[0014] Marking whether a single grain of rice is rice with the husk left in and / or rice with the germ left in, based on the rice type and the corresponding preset thresholds for the percentage of husk left in the bag and the percentage of germ left in the bag;
[0015] When a single grain of rice in one of the original color images is marked as rice with husk and / or rice with germ, the corresponding single grain of rice is determined to be rice with husk and / or rice with germ;
[0016] The first threshold range includes a skin-retaining hue threshold range and a skin-retaining saturation threshold range; the second threshold range includes a germ-retaining hue threshold range and a germ-retaining saturation threshold range.
[0017] Preferably, obtaining the corresponding inscribed rectangle of the partition according to the rice type and the convex hull of the rice grains includes the following steps:
[0018] According to the convex hull of the rice grain, obtain the corresponding maximum inscribed rectangle;
[0019] According to the type of rice, obtain the corresponding pre-set scaling factor;
[0020] The maximum inscribed matrix is multiplied by the corresponding scaling factor to obtain the inscribed rectangle of the partition.
[0021] Preferably, obtaining the corresponding maximum inscribed rectangle according to the convex hull of the rice grain includes the following steps:
[0022] According to the convex hull of the rice grain, obtain the convex hull vertex set;
[0023] According to the reference line L, the reference line L is rotated at a preset angle step so that it intersects with the convex hull of the rice grain at two dynamic intersection points, which are recorded as and ;
[0024] Get the adjacent vertices of ρc and ρd on the convex hull of the rice grain, denoted as and ;
[0025] According to the two dynamic intersection points and their corresponding adjacent vertices, the corresponding candidate rectangle is determined, and the area of the candidate rectangle is calculated;
[0026] Record the area, vertex coordinates and direction parameters of the candidate rectangle at all rotation angles;
[0027] Select the candidate rectangle with the largest area as the candidate result;
[0028] The candidate result is calculated by using the coordinate extreme value to find a rectangle whose left and right sides are parallel to the y-axis and whose upper and lower sides are parallel to the x-axis. It is verified that it is completely inside the convex hull of the rice grain and is selected as the maximum inscribed rectangle.
[0029] Preferably, the method for obtaining the reference line L includes:
[0030] According to the convex hull vertex set, obtain the Euclidean distance between all vertex pairs, and select the two vertices with the largest distance as the initial key point pair, which is recorded as and ;
[0031] connect and , generate the reference straight line L.
[0032] Preferably, according to the preset corresponding first threshold range and second threshold range, calculating the area of the bag occupied by the peel in the middle region and the area of the bag occupied by the embryo in the two end regions comprises the following steps:
[0033] According to the rice type, set the skin hue threshold range, skin saturation threshold range, embryo hue threshold range and embryo saturation threshold range;
[0034] Pixels in the middle area that fall within both the skin-retaining hue threshold range and the skin-retaining saturation threshold range are recorded as skin-retaining pixels; the number of skin-retaining pixels is counted, and the skin-retaining area is calculated according to the formula: skin-retaining area = number of skin-retaining pixels / total number of pixels in the middle area;
[0035] The pixels that fall into both the embryo-retaining hue threshold range and the embryo-retaining saturation threshold range in the two end areas are the embryo-retaining pixels; the number of embryo-retaining pixels is counted, and the embryo-retaining area is obtained according to the formula: the embryo-retaining area = the number of embryo-retaining pixels / the sum of the pixels in the two end areas.
[0036] Preferably, for the two end regions, a rice grain posture recognition and detection method is used to identify the posture of a single grain of rice in the original color image of the single grain of rice, where the posture of the single grain of rice includes two postures: front and side.
[0037] When the posture of the single grain of rice is sideways, the original color image of the single grain of rice is converted into HSV space and then the embryo-retained rice is identified;
[0038] When the posture of a single grain of rice is frontal, morphological operations are performed on the two end regions of the original color image of the single grain of rice to extract the head region and verify whether the head is circular. If so, the single grain of rice is marked as embryo-retained rice.
[0039] Preferably, the rice grain posture recognition and detection method comprises the following steps:
[0040] According to the convex hull of the rice grain, obtain the minimum circumscribed rectangle of the convex hull of the rice grain;
[0041] According to the rotation angle of the minimum circumscribed rectangle relative to the vertical coordinate axis, the original color image is rotated in the opposite direction to obtain a straightened rice grain image;
[0042] Use a pre-trained machine learning model to classify the straightened rice grain image and obtain the posture of a single rice grain.
[0043] A rice appearance detection system includes an acquisition module for obtaining an original color image of a single grain of rice and a processing module for executing the above-mentioned rice appearance detection method.
[0044] The beneficial effects of the rice appearance detection method and system proposed by the present invention are:
[0045] (1) The dynamic region division method based on the convex hull of rice grains and the maximum inscribed rectangle, combined with the rice variety-specific scaling coefficient, can accurately locate the middle region (skin detection) and the two end regions (embryo detection), effectively solving the region division deviation problem caused by the diversity of rice grain morphology and posture changes. Combined with the experience of rice processing, the probability of the middle region of rice retaining skin is higher than that of its two end regions, especially when the ventral groove of the two end regions has skin, the ventral groove of the middle region will also inevitably retain skin. The present invention divides the convex hull of rice grains into regions in advance, and then only performs skin detection on the middle region and embryo detection on the two end regions. Compared with the prior art, which requires processing a large number of pixels for the overall recognition of rice images, the present invention performs recognition by region, and fewer pixels are processed in each step, and both skin detection and embryo detection only require corresponding threshold comparison. Compared with the prior art, the detection and recognition algorithm of the present invention is simpler, the detection speed is faster, and the requirements for the processor are lower, which improves the detection efficiency to a certain extent and reduces the detection cost.
[0046] (2) Through multi-threshold collaborative analysis of the HSV color space, the hue and saturation ranges of the rice with the skin (yellow-brown) and the germ left are adaptively extracted based on the natural color difference characteristics of different rice varieties. This allows the target areas to be distinguished without chemical dyeing, avoiding the time cost and safety risks of dyeing pretreatment while ensuring the objectivity and consistency of the detection results. In addition, the front or side of the rice grain head is identified by the rice grain posture, and different germ-retaining recognition methods are used for different postures, taking into account both detection efficiency and accuracy. DETAILED DESCRIPTION
[0047] The technical solution protected by the present invention is described in detail below.
[0048] The present invention provides a rice appearance inspection method and system. Combining machine vision and geometric modeling techniques, the system can rapidly mark rice with husks and / or embryos left in place without dyeing the rice grains. The system includes an acquisition module and a processing module. The acquisition module is configured to acquire color images of single rice grains. Specifically, the acquisition module uses an industrial camera to capture multiple original color images of single rice grains at different angles under a uniform light source, ensuring that the rice grain surface is shadow-free and the image is clear, and that the color brightness of subsequent HSV conversion remains consistent. In one embodiment, three industrial cameras can be configured to capture original color images of single rice grains at three angles, respectively. The processing module processes and identifies the three obtained single rice color images, marking them as husks and / or embryos left in place. When a single rice grain in one of the original color images is marked as husks and / or embryos left in place, the corresponding single rice grain is determined to be husks and / or embryos left in place.
[0049] The processing steps of the processing module are as follows:
[0050] First, the processing module performs edge detection on the original color image of a single grain of rice to obtain the convex hull of the rice grain. Specifically, the original image is converted into a grayscale image, and the Canny edge detection algorithm is used to extract the outline of the rice grain to obtain an edge point set P = {(xi,yi)|i=1,2,...,n}; based on the edge point set P, the Andrew convex hull algorithm is used to generate the minimum convex polygon of the rice grain, and the convex hull vertex set C = {(xj,yj)|j=1,2,...,m} is output.
[0051] Next, the original color image is divided into two end areas and a middle area using the obtained inscribed rectangle, and corresponding identification marks are made on the two end areas and the middle area respectively. The germ will appear at the head of the rice grain, and the middle area is the area where the skin is most likely to remain. By dividing the areas and identifying them separately, not only can the processing time cost be reduced and the detection efficiency be improved, but also the detection accuracy can be improved.
[0052] In one embodiment, the inscribed rectangle of the zoning is obtained by multiplying the maximum inscribed rectangle of the convex hull of the rice grain by the scaling factor of the corresponding rice variety; by setting the scaling factor, the middle area and the two end areas can be accurately located, and the problem of regional division deviation caused by the diversity of rice grain morphology and posture changes can be effectively solved; for example, the Xichang shapes of indica rice, pearl rice and ordinary rice are different, so directly using the maximum inscribed rectangle (middle part position area) has different effects on the two end part position intervals (germ area), and the corresponding scaling factor can be obtained by detecting and sampling a certain amount of data of a certain type of rice and calculating the weighted average length range of the middle area.
[0053] The corresponding maximum inscribed rectangle is obtained as follows:
[0054] (1) Traverse the convex hull vertex set C, calculate the Euclidean distance between all vertex pairs, and select the two points with the largest distance ρa=(xa,ya) and ρb=(xb,yb) as the initial key point pair; by connecting ρa and ρb, generate the reference line L, whose equation can be expressed as , where the slope .
[0055] (2) With the reference line L as the initial direction, rotate the line according to the preset angle step (such as 1°). After each rotation, adjust the position of the line so that it intersects with the convex hull at two dynamic intersection points. and , and get its adjacent vertices and ;
[0056] (3) According to the two dynamic intersection points and their corresponding adjacent vertices, the corresponding candidate rectangle is determined and the area of the candidate rectangle is calculated. Specifically, the relevant parameters of the candidate rectangle are calculated according to the following formula:
[0057]
[0058] Among them, h is the height value of the candidate rectangle, l is the length value of the candidate rectangle, A is the area of the candidate rectangle, and θ is the vector and The angle between
[0059] (4) By recording the area, vertex coordinates and direction parameters of all candidate rectangles, the candidate rectangle with the largest area is selected and converted into an axis-parallel rectangle (with sides parallel to the coordinate axes). The maximum inscribed rectangle is then verified to be completely inside the convex hull by using the extreme values of the coordinates.
[0060] Finally, the two end areas and the middle area of the original color image are converted to the HSV space respectively. According to the corresponding preset color temperature threshold range, the area of the middle area with the husk retained and the area of the two end areas with the germ retained are calculated; then, according to the corresponding preset thresholds of the husk retained and the area of the germ retained, the single grain of rice is marked as rice with the husk and / or rice with the germ retained.
[0061] Specifically, the process of skin-retention testing is as follows:
[0062] For the middle area, set the hue threshold range and saturation threshold range corresponding to the rice type;
[0063] Count the number of pixels that meet the conditions simultaneously, that is, the number of pixels in the middle area that fall into the skin-retaining hue threshold range and the skin-retaining saturation threshold range at the same time, that is, the number of skin-retaining pixels. According to the formula of skin-retaining area = number of skin-retaining pixels / sum of pixels in the middle area, the skin-retaining area is obtained. Then compare the calculated skin-retaining area with the corresponding skin-retaining threshold. If it meets the requirements, the single grain of rice is marked as skin-retaining rice.
[0064] The steps for embryo retention testing are as follows:
[0065] First, we perform posture recognition on Mi Li to determine whether its head is facing forward or sideways. Specifically:
[0066] Calculate the minimum enclosing rectangle of the convex hull of the rice grain, determine the rotation angle, and reversely rotate the original image to align the rice grain vertically; then use the pre-trained CNN model for classification, such as outputting labels such as "front" or "side".
[0067] Different processing is then performed for different postures. For example, for rice grains classified as front-facing, morphological operations (erosion, dilation, and circularization) are performed on the two end regions to extract the head region and verify its roundness. If the roundness is near-circular, it is marked as embryo-retained rice.
[0068] For rice kernels with a sideways orientation, we set a germ-retaining hue threshold range and a germ-retaining saturation threshold range, count the number of pixels that meet these criteria, and calculate the germ-retaining area of the hull. Specifically, we count the number of germ-retaining pixels and calculate the germ-retaining area of the hull using the formula: germ-retaining area = number of germ-retaining pixels / sum of pixels in the two end regions. The calculated germ-retaining area is then compared with the corresponding germ-retaining threshold. If it meets the requirements, the kernel is marked as germ-retaining.
[0069] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A rice appearance detection method, characterized in that, The steps include: Obtain several original color images of a single grain of rice at different angles; Performing edge detection on the original color image to obtain corresponding edge information; Obtain the convex hull of the rice grains based on the corresponding edge information; According to the rice type and the convex hull of the rice grain, obtain the corresponding inscribed rectangle; According to the inscribed rectangle of the partition, the original color image is divided into two end areas and a middle area; Convert the two end areas and the middle area of the original color image to HSV space respectively to obtain the corresponding hue information and saturation information; Calculate the area of the bag occupied by the skin in the middle region and the area of the bag occupied by the embryo in the two end regions according to the preset corresponding first threshold range and second threshold range; Marking whether a single grain of rice is rice with the husk left in and / or rice with the germ left in, based on the rice type and the corresponding preset thresholds for the percentage of husk left in the bag and the percentage of germ left in the bag; When a single grain of rice in one of the original color images is marked as rice with the husk left and / or rice with the embryo left, the corresponding single grain of rice is determined to be rice with the husk left and / or rice with the embryo left; The first threshold range includes a skin-retaining hue threshold range and a skin-retaining saturation threshold range; the second threshold range includes a germ-retaining hue threshold range and a germ-retaining saturation threshold range.
2. a rice appearance detection method according to claim 1, is characterized in that, Obtain the corresponding inscribed rectangle based on the rice type and the convex hull of the rice grains, including the following steps: According to the convex hull of the rice grain, obtain the corresponding maximum inscribed rectangle; According to the type of rice, obtain the corresponding pre-set scaling factor; The maximum inscribed matrix is multiplied by the corresponding scaling factor to obtain the inscribed rectangle of the partition.
3. a rice appearance detection method according to claim 2, is characterized in that, According to the convex hull of the rice grain, the corresponding maximum inscribed rectangle is obtained, including the following steps: According to the convex hull of the rice grain, obtain the convex hull vertex set; According to the reference line L, the reference line L is rotated at a preset angle step so that it intersects with the convex hull of the rice grain at two dynamic intersection points, which are recorded as and ; Get and The adjacent vertices on the convex hull of the rice grain are denoted as and ; According to the two dynamic intersection points and their corresponding adjacent vertices, the corresponding candidate rectangle is determined, and the area of the candidate rectangle is calculated; Record the area, vertex coordinates and direction parameters of the candidate rectangle at all rotation angles; Select the candidate rectangle with the largest area as the candidate result; The candidate result is calculated by using the coordinate extreme value to find a rectangle whose left and right sides are parallel to the y-axis and whose upper and lower sides are parallel to the x-axis. It is verified that it is completely inside the convex hull of the rice grain and is selected as the maximum inscribed rectangle.
4. a rice appearance detection method according to claim 3, is characterized in that, The method for obtaining the reference line L includes: According to the convex hull vertex set, obtain the Euclidean distance between all vertex pairs, and select the two vertices with the largest distance as the initial key point pair, which is recorded as and ; connect and , generate the reference straight line L.
5. a rice appearance detection method according to claim 1, is characterized in that, Calculating the area of the bag occupied by the skin in the middle region and the area of the bag occupied by the embryo in the two end regions according to the preset corresponding first threshold range and second threshold range, including the following steps: According to the rice type, set the skin hue threshold range, skin saturation threshold range, embryo hue threshold range and embryo saturation threshold range; Pixels in the middle area that fall within both the skin-retaining hue threshold range and the skin-retaining saturation threshold range are recorded as skin-retaining pixels; the number of skin-retaining pixels is counted, and the skin-retaining area is calculated according to the formula: skin-retaining area = number of skin-retaining pixels / total number of pixels in the middle area; The pixels that fall into both the embryo-retaining hue threshold range and the embryo-retaining saturation threshold range in the two end areas are the embryo-retaining pixels; the number of embryo-retaining pixels is counted, and the embryo-retaining area is obtained according to the formula: the embryo-retaining area = the number of embryo-retaining pixels / the sum of the pixels in the two end areas.
6. A rice appearance detection method according to claim 5, characterized in that, For the two end regions, a rice grain posture recognition and detection method is used to identify the posture of a single rice grain in the original color image of the single rice grain, where the posture of the single rice grain includes two postures: front and side. When the posture of the single grain of rice is sideways, the original color image of the single grain of rice is converted into HSV space and then the embryo-retained rice is identified; When the posture of a single grain of rice is frontal, morphological operations are performed on the two end regions of the original color image of the single grain of rice to extract the head region and verify whether the head is circular. If so, the single grain of rice is marked as embryo-retained rice.
7. A rice appearance detection method according to claim 6, characterized in that, The rice grain posture recognition and detection method comprises the following steps: According to the convex hull of the rice grain, obtain the minimum circumscribed rectangle of the convex hull of the rice grain; According to the rotation angle of the minimum circumscribed rectangle relative to the vertical coordinate axis, the original color image is rotated in the opposite direction to obtain a straightened rice grain image; Use a pre-trained machine learning model to classify the straightened rice grain image and obtain the posture of a single rice grain.
8. A rice appearance detection system, characterized in that, The invention comprises an acquisition module for obtaining an original color image of a single grain of rice and a processing module for executing the rice appearance detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Corn plant type parameter measurement method, system and device and storage medium
CN114170148A
Vision-based germ remaining degree detection method for germ remaining rice
CN114419059A