A rice quality detection method and system based on image recognition
By constructing the ellipticity model of rice and comparing it with the template rice, the problems of overfitting and data dependence in rice quality detection in the prior art are solved, and the accuracy and efficiency of rice quality detection are achieved.
Patent Information
- Application Number
- CN202510055031.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2045-01-14
AI Technical Summary
In the prior art, machine learning is prone to overfitting in rice quality detection, and cannot accurately identify rice quality, and requires a large amount of data as a training set. Missing data will lead to inaccurate identification.
By obtaining the minimum circumferential rectangle of the grayscale image of rice samples in different batches of rice, building an ellipse, calculating the ellipse of the rice area and the ellipse, and comparing it with the ellipse of the template rice, the appearance defect rate of the rice is determined.
It improves the accuracy of rice quality inspection, can accurately identify the appearance defects of rice, and reduces dependence on large amounts of data.
Smart Images

Figure CN119478927B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of rice quality detection, and more specifically, to a rice quality detection method and system based on image recognition. Background Art
[0002] With the improvement of living standards, the quality of rice, as one of the main food crops, directly affects people's health and quality of life.
[0003] The quality of rice includes six categories: milling quality, appearance quality, nutritional quality, cooking quality, taste quality and hygiene quality. Among them, appearance quality is the first impression of rice, including the color, transparency, gloss, etc. High-quality rice is usually beige, white, shiny, translucent, and the rice grains are uniform in size, plump and smooth.
[0004] Therefore, it is particularly important to evaluate the appearance quality and classify the rice appearance quality into grades.
[0005] In recent years, with the rapid development of computer vision and image recognition technology, automated detection methods based on image processing have gradually become a research hotspot. These new technologies can efficiently and accurately analyze the appearance characteristics of rice, such as color, shape, texture, etc., thereby achieving rapid evaluation of rice quality.
[0006] In the related art, such as the patent application document with publication number CN113240653A and titled "Rice quality detection method, device, server and system", it trains an image detection model by acquiring a color image consisting of multiple grains of rice of the same appearance type and a color image consisting of multiple grains of rice of different appearance types, and uses the image detection model to determine the quality type of rice to be detected.
[0007] The above scheme obtains images of rice samples (color images of rice of the same appearance type and different appearance types) and combines them with machine learning technology for classification and judgment. Although it can improve the efficiency of rice quality detection, it is prone to overfitting problems, making it impossible to accurately identify the quality of rice. At the same time, it is necessary to obtain a large amount of rich rice data as a training set. Once there is missing data in the training set, it is difficult to accurately identify the quality of rice. Summary of the invention
[0008] The object of the present invention is to propose a rice quality detection method and system based on image recognition, so as to solve the problem that overfitting exists in machine learning in the prior art and rice quality identification cannot be accurately performed; to this end, the present invention provides solutions in the following two aspects.
[0009] In a first aspect, the present invention provides a rice quality detection method based on image recognition, comprising:
[0010] Obtain the minimum bounding rectangle and rice area of the grayscale image of each rice in the rice samples in different batches of rice;
[0011] Construct the ellipses of each minimum circumscribed rectangle;
[0012] Calculate the ellipticity of the rice area and the corresponding ellipse of any rice , specifically: ; K represents the number of edge pixels in the rice region of the mth grain of rice, The vector of the edge point corresponding to the shortest distance from the kth edge pixel point in the rice region of the mth grain of rice to the ellipse, Representation vector The model, Representation vector The angle with the positive x-axis where the major axis of the ellipse is located The cosine of ;
[0013] Calculating the deviation of the ovality of each rice and the template rice, and in response to the deviation being greater than or equal to a threshold, indicating that the rice is defective;
[0014] The ratio of the number of defective rice to the total number of the rice sample is taken as the appearance defect rate of the rice sample to complete the quality inspection of the corresponding batch of rice.
[0015] The above scheme first obtains the ellipticity of the corresponding rice according to the appearance characteristics of different varieties of rice, and detects the appearance of the rice itself to determine whether the shape of the rice itself conforms to the theoretical elliptical shape; secondly, the rice is compared with the standard template, that is, based on the difference in ellipticity and the ellipticity of the template rice, the difference between the appearance of the current rice and the standard appearance can be determined, whether the appearance of the rice is defective, and the detection of different batches of rice is completed. That is, the scheme of the present invention accurately detects the quality of different batches of rice from two parts, thereby improving the accuracy of rice quality detection.
[0016] Optionally, the process of constructing the ellipses of the minimum circumscribed rectangles is:
[0017] The corresponding ellipse is constructed with the center point of the minimum circumscribed rectangle of each grain of rice as the coordinate origin, the length of the minimum circumscribed rectangle as the major axis of the ellipse, and the width as the minor axis of the ellipse.
[0018] Optionally, the rice area is acquired through edge detection.
[0019] The above scheme can obtain the contour information of rice.
[0020] Optionally, the deviation for: , is the ellipticity of the mth grain of rice, is the ellipticity of the nth template rice grain.
[0021] The above scheme provides a specific means of calculating the deviation.
[0022] Optionally, before calculating the deviation of the ellipticity of each rice and the template rice, the step of screening the template rice to obtain the best template rice is further included, specifically:
[0023] Obtain the length, width and area of the minimum bounding rectangle of the current rice and the standard length, standard width and standard area of the standard minimum bounding rectangle of each template rice; calculate the Euclidean distance between the minimum bounding rectangle of the current rice and the minimum bounding rectangle of each template rice based on the length, width and area of the two; select the template rice corresponding to the standard minimum bounding rectangle with the smallest Euclidean distance as the best template rice.
[0024] When different batches of rice are tested simultaneously and there are many template rices, the above scheme can improve the efficiency and accuracy of subsequent comparisons by screening the best template rice.
[0025] Optionally, before constructing the ellipses of the minimum circumscribed rectangles, a step of preliminary screening of the rice samples is also included, specifically:
[0026] Broken rice with a length-to-width ratio smaller than the standard length-to-width ratio is recorded as defective rice;
[0027] Rice with a length shorter than the standard length and a width shorter than the standard width is marked as defective rice, and an unmarked remaining rice sample is obtained; wherein the standard length, standard width and standard length-to-width ratio are determined by each template rice.
[0028] The above scheme improves the efficiency of subsequent detection of rice with less obvious defects by first screening out rice with obvious defects.
[0029] Optionally, the method further includes performing Gaussian noise reduction filtering on the grayscale images of each rice in the rice sample.
[0030] In a second aspect, a rice quality detection system based on image recognition comprises:
[0031] processor;
[0032] The memory stores a computer instruction for rice quality detection based on image recognition. When the computer instruction is executed by the processor, the system executes the above-mentioned rice quality detection method based on image recognition.
[0033] The beneficial effects of the present invention are:
[0034] The solution of the present invention can improve the accuracy of rice quality detection by analyzing the shape of the rice itself and analyzing the difference between the shape of the rice and the template rice. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0036] Figure 1 A flowchart of the steps of a rice quality detection method based on image recognition in this embodiment is schematically shown;
[0037] Figure 2 The structural block diagram of a rice quality detection system based on image recognition in this embodiment is schematically shown. DETAILED DESCRIPTION
[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 those skilled in the art without creative work are within the scope of protection of the present invention.
[0039] The invention performs quality detection on a batch of rice to determine whether the batch of rice is qualified.
[0040] Specifically, Figure 1 As shown, a rice quality detection method based on image recognition in this embodiment comprises the following steps:
[0041] Step S1, obtaining the minimum circumscribed rectangle of the grayscale image of each grain of rice in rice samples from different batches of rice.
[0042] In one embodiment, a small portion of a batch of rice is randomly selected as rice samples, and the minimum bounding rectangle of the grayscale image of each rice in the rice samples is obtained.
[0043] Exemplarily, about 100-200 grains of rice samples are randomly taken out and evenly spread on a black detection table, ensuring that there is enough spacing between each grain of rice to avoid mutual obstruction, deploying an image acquisition device and a light source above the black detection table, adjusting the shooting parameters of the image acquisition device and the intensity of the light source to ensure that each grain of rice in the captured image is clear, complete and without shadow, converting the acquired rice sample image into a rice sample grayscale image and performing Gaussian noise reduction filtering.
[0044] After obtaining the grayscale image of the rice sample, the edge of the grayscale image of the area where each grain of rice is located is extracted to obtain the contour information of the rice; the rectangle of the contour is determined, and the minimum circumscribed rectangle is obtained by rotating the rectangle. Since the acquisition of the minimum circumscribed rectangle is a prior art, it will not be described in detail here.
[0045] In this embodiment, the Canny operator is used to detect the edge of the grayscale image of the area where each grain of rice is located.
[0046] As other implementation methods, an adaptive threshold or Otsu threshold method can also be used to perform threshold segmentation on the acquired rice grayscale image to separate the rice from the background to obtain a grayscale image of the area where each grain of rice is located, and determine the minimum circumscribed rectangle of each individual grain of rice and the length and width of the corresponding rice.
[0047] Since rice is divided into three categories, namely indica rice, japonica rice and glutinous rice, indica rice grains are generally oblong or slender, japonica rice grains are generally elliptical, and glutinous rice is divided into indica glutinous rice and japonica glutinous rice: indica glutinous rice grains are generally oblong or slender, and japonica glutinous rice grains are generally elliptical. Therefore, the minimum circumscribed rectangle of the grayscale image of qualified rice is a rectangle, and the corresponding length and width of the rice can also be approximated as the length and width of the minimum circumscribed rectangle of the corresponding grayscale image. Therefore, the length and width of each grain of rice can be determined.
[0048] Furthermore, considering that the appearance quality of rice is mainly affected by the integrity of rice grains and the size of rice grains, the present embodiment also includes a step of preliminary screening of rice samples, specifically:
[0049] Broken rice with a length-to-width ratio smaller than the standard length-to-width ratio is recorded as defective rice;
[0050] Rice with a length shorter than the standard length and a width shorter than the standard width is marked as defective rice, and an unmarked remaining rice sample is obtained; wherein the standard length, standard width and standard length-to-width ratio are determined by each template rice.
[0051] Since the length-to-width ratio of rice grains of the same variety and quality should be greater than a standard length-to-width ratio, and the length-to-width ratio of broken rice is obviously smaller than the standard length-to-width ratio, the broken rice can be screened out by the length-to-width ratio. At the same time, the rice with small grains can be screened out by the length and width.
[0052] In this embodiment, broken rice with obvious defects and rice with small grains are marked as defective, while the remaining unmarked rice may contain defective rice whose length-width ratio meets the standard. This may be because its size is larger than that of standard rice grains and the degree of breakage is smaller, so that the defective rice also meets the standard. Therefore, it is necessary to further analyze the unmarked rice.
[0053] Step S2, constructing ellipses of the minimum circumscribed rectangles. According to the length and width of the minimum circumscribed rectangles of the remaining unmarked rice obtained in step S1, construct an ellipse for the minimum circumscribed rectangles of each rice.
[0054] Among them, the method of constructing the ellipse of each rice is:
[0055] An ellipse is constructed with the center point of the minimum circumscribed rectangle of each rice as the coordinate origin, the length of the minimum circumscribed rectangle as the major axis of the ellipse, and the width as the minor axis of the ellipse.
[0056] The coordinate system is constructed with the major axis of the ellipse as the x-axis, the minor axis as the y-axis, and the center of the ellipse as the origin; the equation of the ellipse is , a>b>0, where a is half of the major axis and b is half of the minor axis.
[0057] The purpose of constructing the ellipses of each rice is to subsequently compare the shape of each rice itself with the shape difference of the constructed ellipses.
[0058] It should be noted that when constructing the coordinate system, the positive direction of the x-axis of rice areas with similar shapes is the same. For example, most rice areas have obvious depressions in their shapes. At this time, the long axis direction of each rice area with obvious depressions can be used as the positive or negative direction of the x-axis to avoid errors in the subsequent analysis of rice quality.
[0059] Step S3, calculating the ellipticity of the rice area of any rice and the corresponding ellipse.
[0060] The process of obtaining the ellipticity in this embodiment is as follows:
[0061] First, according to the coordinate system where the ellipse is located, the position coordinate points of the edge pixel points of the rice area in the grayscale image of rice are extracted to form a coordinate point set P, and the position coordinate points of the edge pixel points of the ellipse are extracted to form a coordinate point set E.
[0062] Secondly, the position coordinates of the edge point on the ellipse with the shortest distance to the edge pixel point of the rice area are obtained, and the vector from the edge pixel point of the rice area to the corresponding edge point on the ellipse is determined.
[0063] In one embodiment, for each j-th edge point in the rice region ,calculate The distance to any edge point on the edge of the ellipse, select the edge point of the ellipse corresponding to the minimum distance, and construct a vector between the two points.
[0064] In another embodiment, the present embodiment can also be based on the ellipse equation , calculate the edge points of the rice area Distance d to the ellipse:
[0065] ;
[0066] Among them, t is a parameter, ranging from 0 , the jth edge point in the rice area The position coordinates are , , are the horizontal and vertical coordinates of any edge point on the ellipse respectively.
[0067] right The function is derived, and the parameter t is calculated when the derived function is equal to 0. The edge point on the ellipse corresponding to the shortest distance can be obtained, and the vector of the two points can be constructed.
[0068] The direction of the vector constructed above is from the edge pixel point of the rice area to the edge point on the ellipse.
[0069] Then, the ellipticity of the rice area and the corresponding ellipse is calculated.
[0070] The specific calculation method of ellipticity is as follows:
[0071] ;
[0072] in, represents the ellipticity of the rice area of the mth rice grain and the corresponding ellipse; K represents the number of edge pixels of the rice area of the mth rice grain, The vector of the edge point corresponding to the shortest distance from the kth edge pixel point in the rice region of the mth grain of rice to the ellipse, Representation vector The model, Representation vector The angle with the positive x-axis where the major axis of the ellipse is located The cosine value of .
[0073] The above consideration of the direction of the vector is to distinguish the case where the magnitude of the vector of the edge pixel point of the rice area is the same as that of the vector of the edge point on the ellipse, but the direction of the vector is different. For example, a rice area may be inside the ellipse or outside the ellipse (such as a broken rice); it is also possible that part of the rice area is inside the ellipse and part of the rice area is outside the ellipse (such as a concave area in a rice grain); therefore, by introducing the vector The angle with the positive x-axis where the major axis of the ellipse is located The cosine value of can determine the relationship between the rice area and the ellipse in different situations, making it possible to distinguish situations where the vector modulus is the same but the direction is completely different, thereby quantifying the ellipticity more accurately.
[0074] It should be noted that the above ellipticity is only used to determine the detailed difference between the shape of the rice area and the corresponding ellipse, and it does not indicate whether the rice area is standard rice.
[0075] Step S4, calculating the deviation of the ovality of each rice and the template rice, and in response to the deviation being greater than or equal to a threshold, the rice is defective.
[0076] In this embodiment, according to the deviation between the ellipticity of each grayscale image obtained in step S3 and the ellipticity of the template grayscale image, it can be determined whether the rice corresponding to each grayscale image has defects.
[0077] In one embodiment, the deviation for: , is the ellipticity of the mth grain of rice, is the ellipticity of the nth template rice grain.
[0078] in, The smaller the value of , the more similar the ellipticity of the rice region of the m-th grain of rice is to the ellipticity of the rice region in the n-th grain of template rice, and the greater the probability that the rice has qualified appearance quality.
[0079] In this embodiment, according to the rice quality detection requirements, rice with a deviation exceeding a set threshold is marked as defective rice.
[0080] The threshold value is 0.1; specifically, it can be set according to the requirements of detection accuracy.
[0081] Of course, as another embodiment, the above deviation can also be the absolute value of the difference between the two ellipticities, wherein the threshold value needs to be set according to the actual situation.
[0082] It should be noted that the appearance of a rice grain with qualified quality is similar to an ellipse with a concave area in a local area. This concave area is the germ part of the rice grain, and its overall similarity to the ellipse shape is relatively high. Therefore, for rice grains with similar length, width and area to the qualified rice region, the edge of the rice region in the grayscale image is also similar to the ellipse constructed by it. However, rice with slight pits and cracks has obvious appearance difference from the qualified rice grains without cracks in the grayscale image. The broken parts will show straight cracks in the grayscale image, and the appearance is less similar to the ellipse shape constructed by it.
[0083] The template rice may include a plurality of standard rices of different quality specifications, i.e., a plurality of standard grayscale images. The calculation method of the ellipticity of the template rice is the same as the calculation method of the ellipticity of each rice in the rice sample, which will not be repeated here. Exemplarily, the template rice may be a plurality of standard rices of different quality specifications manually screened.
[0084] Among them, the length and width of the template rice can be obtained by the minimum circumscribed rectangle; the area can be obtained by the number of pixels of the corresponding template grayscale image.
[0085] Furthermore, considering that there are multiple standard rices of different quality specifications in the template rice, and although the sizes of the standard rices of different quality specifications are different, they may have the same ellipticity, therefore, it is necessary to screen the template rice to obtain the best template rice, which is specifically as follows:
[0086] Calculate the distance between each unlabeled rice grayscale image and all template grayscale images, , is the Euclidean distance between the mth grain of rice and the nth grain of template rice, , , Respectively represent the length, width, and area of the mth grain of rice, , , Respectively represent the length, width and area of the nth template rice; The smaller it is, the closer the length, width and area of the grayscale image of the m-th grain of rice is to that of the n-th grain of template rice, that is, the size and shape of the two grains of rice may be closer. At this time, the n-th grain of template rice is the best template rice.
[0087] In this embodiment, the difference between the ellipticity of the rice and the ellipticity of the best template rice is calculated, and a threshold is set according to the detection accuracy requirement of the rice quality. When the deviation is greater than the threshold, the rice is marked as defective rice.
[0088] The above-mentioned method of obtaining the best rice can eliminate template rice of different sizes but qualified quality, thereby improving the accuracy of detection of the quality grade of the current rice.
[0089] Step S5, taking the ratio of the number of defective rice to the total number of the rice sample as the appearance defect rate of the rice sample to complete the quality inspection of the corresponding batch of rice.
[0090] In this embodiment, the total number of marked defective rice is counted, and the ratio of the total number of defective rice to the total number of rice samples is used as the appearance defect rate of the current batch of rice to complete the qualified detection of the quality of the batch of rice.
[0091] The solution of the present invention can determine the shape change of the rice area by comparing the rice area with the constructed ellipse, and then calculate the difference with the shape change of the template grayscale image, so as to accurately determine whether the current rice is defective rice.
[0092] The present invention also provides a rice quality detection system based on image recognition. Figure 2 As shown, the system includes a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the rice quality detection method based on image recognition according to the present invention is implemented.
[0093] The detection system also includes other components familiar to those skilled in the art, such as a communication bus and a communication interface, whose configuration and functions are known in the art and thus will not be described in detail here.
[0094] In the present invention, the aforementioned memory may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus or device. For example, a computer-readable storage medium may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory RRAM (Resistive Random Access Memory), a dynamic random access memory DRAM (Dynamic Random Access Memory), a static random access memory SRAM (Static Random-Access Memory), an enhanced dynamic random access memory EDRAM (Enhanced Dynamic Random Access Memory), a high-bandwidth memory HBM (High-Bandwidth Memory), a hybrid memory cube HMC (Hybrid Memory Cube), etc., or any other medium that can be used to store the required information and can be accessed by an application, a module, or both. Any such computer storage medium may be part of a device or accessible or connectable to a device. Any application or module described in the present invention may be implemented by computer-readable / executable instructions stored or otherwise maintained by such a computer-readable medium.
[0095] In the description of this specification, “plurality” means at least two, such as two, three or more, etc., unless otherwise clearly and specifically defined.
[0096] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, various alternatives to the embodiments of the present invention described herein may be employed.
Claims
1. A rice quality detection method based on image recognition, characterized in that, include: Obtain the minimum bounding rectangle and rice area of the grayscale image of each rice in the rice samples in different batches of rice; Construct the ellipses of each minimum circumscribed rectangle; Calculate the ellipticity of the rice area and the corresponding ellipse of any rice , specifically: ; K represents the number of edge pixels in the rice region of the mth grain of rice, The vector of the edge point corresponding to the shortest distance from the kth edge pixel point in the rice region of the mth grain of rice to the ellipse, Representation vector The model, Representation vector The angle with the positive x-axis where the major axis of the ellipse is located The cosine of ; Calculating the deviation of the ovality of each rice and the template rice, and in response to the deviation being greater than or equal to a threshold, indicating that the rice is defective; The ratio of the number of defective rice to the total number of the rice sample is taken as the appearance defect rate of the rice sample to complete the quality inspection of the corresponding batch of rice.
2. A rice quality detection method based on image recognition according to claim 1, characterized in that, The process of constructing the ellipse of each minimum circumscribed rectangle is as follows: The corresponding ellipse is constructed with the center point of the minimum circumscribed rectangle of each grain of rice as the coordinate origin, the length of the minimum circumscribed rectangle as the major axis of the ellipse, and the width as the minor axis of the ellipse.
3. A rice quality detection method based on image recognition according to claim 2, characterized in that, The rice area is obtained through edge detection.
4. A rice quality detection method based on image recognition according to claim 3, characterized in that, The deviation for: , is the ellipticity of the mth grain of rice, is the ellipticity of the nth template rice grain.
5. A rice quality detection method based on image recognition according to claim 1, characterized in that, Before calculating the deviation of the ellipticity of each rice and the template rice, the template rice is screened to obtain the best template rice, which is specifically: Obtain the length, width and area of the minimum bounding rectangle of the current rice and the standard length, standard width and standard area of the standard minimum bounding rectangle of each template rice; calculate the Euclidean distance between the minimum bounding rectangle of the current rice and the minimum bounding rectangle of each template rice based on the length, width and area of the two; select the template rice corresponding to the standard minimum bounding rectangle with the smallest Euclidean distance as the best template rice.
6. A rice quality detection method based on image recognition according to claim 1, characterized in that, Before constructing the ellipses of the minimum circumscribed rectangles, a preliminary screening step of the rice samples is also included, specifically: Broken rice with a length-to-width ratio smaller than the standard length-to-width ratio is recorded as defective rice; Rice with a length shorter than the standard length and a width shorter than the standard width is marked as defective rice, and an unmarked remaining rice sample is obtained; wherein the standard length, standard width and standard length-to-width ratio are determined by each template rice.
7. A rice quality detection method based on image recognition according to claim 1, characterized in that, It also includes performing Gaussian noise reduction filtering on the grayscale images of each rice in the rice sample.
8. A rice quality detection system based on image recognition, characterized in that: include: processor; A memory storing a computer instruction for rice quality detection based on image recognition, wherein when the computer instruction is executed by the processor, the system executes a rice quality detection method based on image recognition according to any one of claims 1 to 7.
Citation Information
Patent Citations
Rice quality detection method, device, server and system
CN113240653A
Method, system and device for counting number of ear heads and storage medium
CN114066842A
Rubber ring defect batch detection method and detection system
CN114384080A