Adulteration detection system and method for brewing sorghum based on machine vision
Through the machine vision-based wine-making sorghum adulteration detection system, the Xception network model and anti-aliasing processing technology are used to solve the accuracy of sorghum adulteration detection during rotation change, and the rapid, lossless and accurate sorghum identification is achieved, reducing the Test cost and time.
Patent Information
- Application Number
- CN202210407676.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-19
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2042-04-19
AI Technical Summary
The existing sorghum adulteration detection technology has different output results when the rotation changes, which affects the detection accuracy. The traditional method has high time and cost, so it is impossible to detect the characteristics of each sorghum in real time and non-destructively.
Using a machine vision-based adulteration detection system for brewing sorghum, combined with an industrial color camera, LED white dome light source and screen disk, the rotation invariance is improved through Xception network model and anti-aliasing treatment, and the rapid and lossless identification of single sorghum is achieved.
It improves the accuracy and robustness of the detection, reduces the repetitive differences, and achieves rapid detection without pretreatment and damage to sorghum. The analysis process does not require the consumption of organic reagents.
Smart Images

Figure CN114743011B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a system and method for detecting adulteration of brewing sorghum, and belongs to the technical field of non-destructive detection of agricultural products. Background Art
[0002] In my country, sorghum has been used as a raw material for brewing liquor for more than 700 years. Different varieties of sorghum have different effects on the production process and quality of liquor due to different contents of starch, protein, polyphenols, etc. When purchasing sorghum raw materials, the winery mainly requires Luzhou Red, Langnuo Red and Yinuo Red. However, in order to seek higher profits, many unscrupulous vendors often mix non-demand sorghum varieties that are not suitable for brewing with the demand varieties. Among them, Jinnuoliang and Liaoning Hongyingzi are the most common. In order to ensure the liquor production process, the winery needs to conduct strict quality inspections before the sorghum is stored for processing.
[0003] At present, the traditional means of identifying sorghum adulteration mainly relies on the appearance of sorghum. When the naked eye cannot distinguish it, the cooking method is used. Adulteration detection technology based on DNA or spectrum has gradually become a hot topic. The former distinguishes different varieties of sorghum by comparing DNA fragments, but it requires complex molecular labeling and fragment separation processes, which is time- and material-intensive. The latter has the advantages of non-destructive and rapid detection, but it cannot guarantee that the characteristics of each grain of sorghum can still be detected when the sampling volume is relatively large. Therefore, it is not effective for distinguishing sorghum samples with a low adulteration rate. Machine vision technology can make up for the shortcomings of the above two methods and can realize the variety identification of single-grain sorghum, and it is non-destructive, rapid, and relatively low-cost.
[0004] With the rise of big data and artificial intelligence, convolutional neural networks (CNNs) have been applied in agricultural product and food testing and have achieved satisfactory results due to their advantages in automatically extracting representative features. However, CNNs violate the Nyquist sampling theorem, so small changes in the same input image (such as translation, scaling, and rotation) may also lead to network output results with very different results. For the sorghum adulteration detection system, the biggest impact is the output error that may be caused by the rotation of the input image. Therefore, it is necessary to find a robust and reliable method to improve the rotation invariance of the trained CNN, thereby improving the accuracy of adulteration detection. Summary of the invention
[0005] The present invention provides a machine vision-based detection system and method for adulteration of brewing sorghum, which can use the image of each grain of sorghum combined with a machine learning algorithm to achieve non-destructive and rapid detection. It is conducive to the development of small equipment and is suitable for real-time detection of sorghum in wineries when purchasing.
[0006] In order to achieve the above object, the present invention provides the following technical solutions:
[0007] A machine vision-based adulteration detection system for brewing sorghum, the system comprising: an industrial color camera 1, an LED white light dome light source 2, a black sample plate 3, a sieve plate 4 and a computer 5;
[0008] An LED white light dome light source 2 is arranged above the black sample plate 3, and a mesh plate 4 is placed on the black sample plate 3. The light emitting area of the LED white light dome light source 2 is larger than the area of the mesh plate 4.
[0009] The top of the LED white light dome light source 2 is provided with an opening; the industrial color camera 1 is arranged vertically, and the lens of the industrial color camera 1 is directed toward the screen plate 4 from the top opening of the LED white light dome light source 2; the industrial color camera 1 and the computer 5 are connected via a data cable;
[0010] The screen plate 4 is provided with a plurality of screen holes.
[0011] Wherein, the diameter of the sieve holes is 4.5 mm, and the hole spacing is 5.5 mm.
[0012] Among them, the screen plate 4 carries 115 sorghum grains.
[0013] The height of the screen plate 4 is 1 mm.
[0014] Wherein, the diameter of the LED white light dome light source 2 is 170 mm.
[0015] A method for detecting adulteration of brewing sorghum based on machine vision using a brewing sorghum adulteration detection system based on machine vision, the method comprising the following steps:
[0016] Three sorghum varieties required for brewing sorghum, namely Luzhouhong, Langnuohong and Yinuohong, and seven non-demand sorghum varieties with the smallest appearance difference from the demand sorghum varieties, namely Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi, were selected as sorghum samples to be tested; a total of four classification models were established, namely, the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the adulteration discrimination model of the mixed demand sample of Luzhouhong, Langnuohong and Yinuohong; when making adulteration predictions, any one of the four models was selected for testing according to the demand sorghum variety to be tested;
[0017] Step 1: Get the original image of each sorghum variety
[0018] For the Luzhouhong adulteration discrimination model, the original images of Luzhouhong and seven non-demand sorghum varieties were obtained respectively;
[0019] For the Langnuohong adulteration discrimination model, the original images of Langnuohong and seven non-demand sorghum varieties were obtained respectively;
[0020] For the adulteration discrimination model of Yinuohong, the original images of Yinuohong and seven non-demand sorghum varieties were obtained respectively;
[0021] For the adulteration discrimination model of mixed demand samples of Luzhouhong, Langnuohong and Yinuohong, the original images of Luzhouhong, Langnuohong, Yinuohong and 7 non-demand sorghum varieties were obtained respectively;
[0022] The seven non-demand sorghum varieties are: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi;
[0023] When acquiring each image, a certain amount of sorghum grain samples are randomly selected for each sorghum variety, and the sorghum grain samples are dispersed by using a sieve plate 4. The sorghum images are collected by using an industrial color camera 1, and each image contains m sorghum grains; n images are acquired for each sorghum variety, and the size of each image is 1944×2592, which is called the original image;
[0024] Step 2, extracting single grains of sorghum from each original image of each sorghum variety and generating images of the same size, and removing defective grains;
[0025] Step 2.1: Preprocess each original image of each sorghum variety:
[0026] The background of each original image of each sorghum variety collected was removed: the image of the R channel was selected for binarization, and the salt and pepper noise was eliminated using the median filter;
[0027] Morphological processing: hole filling, two morphological dilation processes, hole filling, three morphological erosion processes, and three morphological dilation processes are performed in sequence; at this time, the background values of the R channel are all 0, so the background of the R channel is assigned to the G and B channels, and the three channels are superimposed to generate an image with background removed;
[0028] Step 2.2: Crop the image obtained in step 2.1 and generate a small image containing a single sorghum grain:
[0029] The background pixel values of the image obtained in step 2.1 are all 0, that is, all black. At this time, in order to generate m small images containing a single sorghum grain from the image containing m sorghum grains, the image obtained in step 2.1 is first binarized, and then the attributes of all 8 connected regions in the image are obtained to generate a small image containing a single sorghum grain with a size of 224×224 for later network model training;
[0030] Step 2.3: Remove defective grains from the small image containing a single sorghum grain obtained in step 2.2:
[0031] The grains with a ratio of white area pixels within the sorghum grain range to the area pixels within the box greater than 1 / 4 are regarded as damaged grains and removed; the ratio of white area pixels within the sorghum grain range to the area pixels within the box is the ratio of the number of pixels with a pixel value of 255 within the box to the total number of pixels within the box;
[0032] Step 3: Dataset division
[0033] Repeat step 2.3 for each 224×224-sized small image containing a single sorghum grain obtained for each sorghum variety, and finally obtain s small images containing a single sorghum grain for each sorghum variety; extract 60%×s small images from each sorghum variety as the training set of the model, 10%×s images as the cross-validation set of the model, and 30%×s images as the test set of the model;
[0034] For the Luzhou Red adulteration discrimination model, a training set of the Luzhou Red adulteration discrimination model, a cross-validation set of the Luzhou Red adulteration discrimination model, and a test set of the Luzhou Red adulteration discrimination model are obtained respectively;
[0035] For the Langnuohong adulteration discrimination model, the training set of the Langnuohong adulteration discrimination model, the cross-validation set of the Langnuohong adulteration discrimination model and the test set of the Langnuohong adulteration discrimination model are obtained respectively;
[0036] For the Yinuohong adulteration discrimination model, the training set of the Yinuohong adulteration discrimination model, the cross-validation set of the Yinuohong adulteration discrimination model and the test set of the Yinuohong adulteration discrimination model are obtained respectively;
[0037] For the mixed demand sample adulteration discrimination model, a training set of the mixed demand sample adulteration discrimination model, a cross-validation set of the mixed demand sample adulteration discrimination model and a test set of the mixed demand sample adulteration discrimination model are obtained respectively;
[0038] Step 4: Structural adjustment of the Xception network model:
[0039] Step 4.1, adjust the size of the image input layer to 224×224×3; use the z-score preprocessing method to preprocess the input image at the input layer;
[0040] Step 4.2: Adjust the last fully connected layer of the image;
[0041] For the Luzhouhong adulteration discrimination model, the output of the fully connected layer is set to 8, which means 8 categories of sorghum, including Luzhouhong and 7 non-demand sorghums;
[0042] For the Langnuohong adulteration discrimination model, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Langnuohong and 7 non-demand sorghums;
[0043] For the adulteration discrimination model of Yinuohong, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Yinuohong and 7 non-demand sorghums;
[0044] For the mixed demand sample adulteration discrimination model, the output of the fully connected layer was set to 10, i.e., 10 categories of sorghum, including Luzhou red, Langnuo red, Yinuo red, and 7 non-demand sorghums;
[0045] Step 4.3: Use the Adam optimization algorithm to train the network, set the batch size to 64, the learning rate decay rate to 0.1, and the learning rate decays once every 10 generations of training;
[0046] Step 4.4, perform anti-aliasing on the maximum pooling layer in the Xception network;
[0047] The maximum pooling layer with a stride of 2 is replaced by a maximum pooling layer with a stride of 1 and a downsampling layer with a stride of 2; the size of the convolution kernel remains unchanged;
[0048] Step 5, respectively substitute the training sets of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model;
[0049] Step 5.1, substitute the training set of the Luzhou Red adulteration discrimination model and the cross-validation set images of the Luzhou Red adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training, and obtain the trained Luzhou Red adulteration discrimination model;
[0050] Substituting the test set image of the Luzhou Red adulteration discrimination model obtained in step 3 into the Luzhou Red adulteration discrimination model for testing, and testing the confusion matrix obtained;
[0051] Step 5.2, substitute the training set of the Langnuohong adulteration discrimination model and the cross-validation set images of the Langnuohong adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training, and obtain the trained Langnuohong adulteration discrimination model;
[0052] Substituting the test set images of the Langnuohong adulteration discrimination model obtained in step 3 into the Langnuohong adulteration discrimination model for testing, and testing the obtained confusion matrix;
[0053] Step 5.3, substitute the training set of the Yinuohong adulteration discrimination model and the cross-validation set images of the Yinuohong adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training, and obtain the trained Yinuohong adulteration discrimination model;
[0054] Substituting the test set images of the Yinuohong adulteration discrimination model obtained in step 3 into the Yinuohong adulteration discrimination model for testing, and testing the obtained confusion matrix;
[0055] Step 5.4, substitute the training set of the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained mixed demand sample adulteration discrimination model;
[0056] The test set images of the mixed demand sample adulteration discrimination model obtained in step 3 are substituted into the mixed demand sample adulteration discrimination model for testing, and the confusion matrix obtained by the test is tested.
[0057] Wherein, m=115, n=10.
[0058] Compared with the prior art, the present invention has the following beneficial effects:
[0059] The machine vision-based brewing sorghum adulteration detection system and method provided by the present invention do not require pre-treatment of the sample to be tested, have good repeatability, do not require consumption of organic reagents during the analysis process, and are non-destructive to the sorghum. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 This is a flow chart of the method for detecting adulteration of brewing sorghum based on machine vision of the present invention;
[0061] Figure 2 It is a structural schematic diagram of the machine vision-based adulteration detection system for brewing sorghum of the present invention;
[0062] Figure 3a Feature map of the input image;
[0063] Figure 3b For the Xception network without anti-aliasing Figure 3a Feature map of the input image;
[0064] Figure 3c Xception pair with anti-aliasing Figure 3a Feature map of the input image;
[0065] Figure 4a to Figure 4d This is the confusion matrix of the Luzhou red model, Langnuo red model, Yinuo red model and mixed sample model.
[0066] The accompanying drawings are denoted as follows:
[0067] 1. Industrial color camera 2. LED white light dome light source
[0068] 3. Black sample plate 4. Sieve plate
[0069] 5. Computer DETAILED DESCRIPTION
[0070] The specific implementation of the present invention will be further described below in conjunction with the accompanying drawings.
[0071] like Figure 2 As shown, a machine vision-based brewing sorghum adulteration detection system includes: an industrial color camera 1, an LED white light dome light source 2, a black sample plate 3, a sieve plate 4 and a computer 5.
[0072] An LED white light dome light source 2 is arranged above the black sample plate 3 , and a mesh plate 4 is placed on the black sample plate 3 . The light emitting area of the LED white light dome light source 2 is larger than that of the mesh plate 4 .
[0073] An opening is provided at the top of the LED white light dome light source 2. The industrial color camera 1 is arranged vertically, and the lens of the industrial color camera 1 faces the screen plate 4 from the top opening of the LED white light dome light source 2. The industrial color camera 1 and the computer 5 are connected via a data cable.
[0074] The screen plate 4 is provided with a plurality of screen holes. Since the particle size of the demand sorghum is generally smaller than that of the non-demand sorghum varieties, the diameter of the screen holes is determined according to the demand sorghum variety. The hole spacing is set according to the variety with the largest particle diameter among all sorghums to ensure that the largest particles do not contact each other. The height of the screen plate 4 can ensure that the particles entering the same screen hole can be easily manually separated.
[0075] Preferably, the diameter of the mesh holes is 4.5 mm, and the hole spacing is 5.5 mm.
[0076] Preferably, the screen plate 4 can carry 115 sorghum grains, so as to ensure the detection quantity of each sampling detection and ensure that each sorghum grain is within a suitable field of view.
[0077] Preferably, the height of the screen plate 4 is 1 mm.
[0078] Preferably, the diameter of the LED white light dome light source 2 is 170 mm.
[0079] like Figure 1As shown, a method for detecting adulteration of brewing sorghum based on machine vision comprises the following steps:
[0080] Three sorghum varieties required for brewing sorghum: Luzhouhong, Langnuohong and Yinuohong, and seven non-demand sorghum varieties with the smallest appearance difference from the demand sorghum varieties: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi were selected as sorghum samples to be tested. A total of four classification models were established, namely the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the adulteration discrimination model of mixed demand samples of Luzhouhong, Langnuohong and Yinuohong. When making adulteration predictions, any of the four models was selected for testing according to the demand sorghum variety to be tested.
[0081] Step 1: Get the original image of each sorghum variety
[0082] For the Luzhouhong adulteration discrimination model, the original images of Luzhouhong and seven non-demand sorghum varieties were obtained respectively;
[0083] For the Langnuohong adulteration discrimination model, the original images of Langnuohong and seven non-demand sorghum varieties were obtained respectively;
[0084] For the adulteration discrimination model of Yinuohong, the original images of Yinuohong and seven non-demand sorghum varieties were obtained respectively;
[0085] For the adulteration discrimination model of mixed demand samples of Luzhouhong, Langnuohong and Yinuohong, the original images of Luzhouhong, Langnuohong, Yinuohong and 7 non-demand sorghum varieties were obtained respectively;
[0086] The seven non-demand sorghum varieties are: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi.
[0087] When acquiring each image, a certain amount of sorghum grain samples are randomly selected from each sorghum variety, the sorghum grain samples are dispersed using a sieve plate 4, and sorghum images are captured using an industrial color camera 1, each image containing m sorghum grains. Each sorghum variety is respectively acquired with n images, each image having a size of 1944×2592, which are referred to as original images.
[0088] Preferably, m=115, n=10.
[0089] Step 2, extracting single grains of sorghum from each original image of each sorghum variety and generating images of the same size, and removing defective grains;
[0090] Step 2.1: Preprocess each original image of each sorghum variety:
[0091] The background of each original image of each sorghum variety collected was removed: the image of the R channel was selected for binarization, and the salt and pepper noise was eliminated using the median filter;
[0092] Morphological processing: hole filling, two morphological dilation processes, hole filling, three morphological erosion processes, and three morphological dilation processes are performed in sequence. At this time, the background values of the R channel are all 0, so the background values of the R channel are assigned to the G and B channels, and the three channels are superimposed to generate an image with background removed;
[0093] Step 2.2: Crop the image obtained in step 2.1 and generate a small image containing a single sorghum grain:
[0094] The background pixel values of the image obtained in step 2.1 are all 0, that is, completely black. At this time, in order to generate m small images containing a single sorghum grain from the image containing m sorghum grains, the image obtained in step 2.1 is first binarized, and then the attributes of all 8 connected regions in the image are obtained to generate a small image containing a single sorghum grain with a size of 224×224 for subsequent network model training.
[0095] Step 2.3: Remove defective grains from the small image containing a single sorghum grain obtained in step 2.2:
[0096] The grains whose ratio of white area pixels within the sorghum grain range to the pixels within the box area is greater than 1 / 4 are regarded as damaged grains and are removed; the ratio of white area pixels within the sorghum grain range to the pixels within the box area is the ratio of the number of pixels with a pixel value of 255 in the box to the total number of pixels in the box.
[0097] Step 3: Dataset division
[0098] Repeat step 2.3 for each 224×224 image containing a single sorghum grain obtained for each sorghum variety, and finally obtain s images containing a single sorghum grain for each sorghum variety. From each sorghum variety, extract 60%×s images as the training set of the model, 10%×s images as the cross-validation set of the model, and 30%×s images as the test set of the model;
[0099] For the Luzhou Red adulteration discrimination model, a training set of the Luzhou Red adulteration discrimination model, a cross-validation set of the Luzhou Red adulteration discrimination model, and a test set of the Luzhou Red adulteration discrimination model are obtained respectively;
[0100] For the Langnuohong adulteration discrimination model, the training set of the Langnuohong adulteration discrimination model, the cross-validation set of the Langnuohong adulteration discrimination model and the test set of the Langnuohong adulteration discrimination model are obtained respectively;
[0101] For the Yinuohong adulteration discrimination model, the training set of the Yinuohong adulteration discrimination model, the cross-validation set of the Yinuohong adulteration discrimination model and the test set of the Yinuohong adulteration discrimination model are obtained respectively;
[0102] For the mixed demand sample adulteration discrimination model, a training set of the mixed demand sample adulteration discrimination model, a cross-validation set of the mixed demand sample adulteration discrimination model and a test set of the mixed demand sample adulteration discrimination model are obtained respectively.
[0103] Step 4: Structural adjustment of the Xception network model:
[0104] Step 4.1, adjust the size of the image input layer to 224×224×3; use the z-score preprocessing method to preprocess the input image at the input layer;
[0105] Step 4.2: Adjust the last fully connected layer of the image;
[0106] For the Luzhouhong adulteration discrimination model, the output of the fully connected layer is set to 8, which means 8 categories of sorghum, including Luzhouhong and 7 non-demand sorghums;
[0107] For the Langnuohong adulteration discrimination model, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Langnuohong and 7 non-demand sorghums;
[0108] For the adulteration discrimination model of Yinuohong, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Yinuohong and 7 non-demand sorghums;
[0109] For the mixed demand sample adulteration discrimination model, the output of the fully connected layer was set to 10, i.e., 10 categories of sorghum, including Luzhou red, Langnuo red, Yinuo red, and 7 non-demand sorghums;
[0110] Step 4.3: Use the Adam optimization algorithm to train the network, set the batch size to 64, the learning rate decay rate to 0.1, and the learning rate decays once every 10 generations of training;
[0111] Step 4.4, perform anti-aliasing on the maximum pooling layer in the Xception network;
[0112] The maximum pooling layer with a stride of 2 is replaced by a maximum pooling layer with a stride of 1 and a downsampling layer with a stride of 2. The size of the convolution kernel remains unchanged.
[0113] Figure 3a is a set of small images containing a single sorghum grain that have been rotated at different angles, where the upper left corner is the original input image, and the upper right corner, lower left corner, and lower right corner are the images of the sorghum grain in the small image containing a single sorghum grain rotated 90°, 180°, and 270° counterclockwise around its center point, respectively. Figure 3b and Figure 3c These are the feature maps of the Xception network without anti-aliasing and the Xception network with anti-aliasing for the same input image. Figure 3a Same as in Figure 3b and Figure 3c The upper left corner, upper right corner, lower left corner, and lower right corner are the original image and the image of the sorghum grain rotated 90°, 180°, and 270° counterclockwise around its center point as the feature map obtained after the network input. In order to clearly present the feature map results, the target sorghum grain is masked and only the network's recognition of the background information is observed. It can be seen that when the target object rotates in the image, the network without anti-aliasing processing will also recognize the background information as a feature, while the network with anti-aliasing processing can still correctly regard the background features as 0.
[0114] Step 5, respectively substitute the training sets of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model;
[0115] Step 5.1, substitute the training set of the Luzhou Red adulteration discrimination model and the cross-validation set images of the Luzhou Red adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training to obtain the trained Luzhou Red adulteration discrimination model.
[0116] The test set image of the Luzhou Red adulteration discrimination model obtained in step 3 is substituted into the Luzhou Red adulteration discrimination model for testing. The confusion matrix obtained by the test is as follows: Figure 4a shown.
[0117] Step 5.2: Substitute the training set of the Langnuohong adulteration discrimination model and the cross-validation set images of the Langnuohong adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training to obtain the trained Langnuohong adulteration discrimination model.
[0118] The test set images of the Langnuohong adulteration discrimination model obtained in step 3 are substituted into the Langnuohong adulteration discrimination model for testing. The confusion matrix obtained by the test is as follows: Figure 4b shown.
[0119] Step 5.3, substitute the training set of the Yinuohong adulteration discrimination model obtained in step 3 and the cross-validation set images of the Yinuohong adulteration discrimination model into the Xception network obtained in step 4 for training to obtain the trained Yinuohong adulteration discrimination model.
[0120] The test set images of the Yinuohong adulteration discrimination model obtained in step 3 are substituted into the Yinuohong adulteration discrimination model for testing. The confusion matrix obtained by the test is as follows: Figure 4c shown.
[0121] Step 5.4, substitute the training set of the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training to obtain the trained mixed demand sample adulteration discrimination model.
[0122] The test set image of the mixed demand sample adulteration discrimination model obtained in step 3 is substituted into the mixed demand sample adulteration discrimination model for testing. The confusion matrix obtained by the test is as follows: Figure 4d shown.
[0123] Figure 4a to Figure 4d Among them, JNL1, JNL2, JNL4, JNL7, JNL8, JNL9, and LN represent seven non-demand sorghums: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9, and Liaoning Hongyingzi; LangN1, LZH, and YNH represent demand sorghums: Langnuohong (Langnuohong No. 1), Luzhouhong, and Yinuohong.
[0124] The following takes the Luzhou Red adulteration discrimination model as an example to further illustrate the method of the present invention.
[0125] Step 1, respectively obtain the original images of Luzhou Red, Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi;
[0126] When acquiring each image, a certain amount of sorghum grain samples are randomly selected from each sorghum variety, the sorghum grain samples are dispersed using a sieve plate 4, and sorghum images are captured using an industrial color camera 1, each image containing 115 sorghum grains. Ten images are acquired for each sorghum variety, each image having a size of 1944×2592, which are referred to as original images.
[0127] Step 2, extracting single grains of sorghum from each original image of each sorghum variety and generating images of the same size, and removing defective grains;
[0128] Step 2.1: Preprocess each original image of each sorghum variety:
[0129] The background of each original image of each sorghum variety collected was removed: the image of the R channel was selected for binarization, and the salt and pepper noise was eliminated using the median filter;
[0130] Among them, the cv2.threshold function is used for binarization, the starting value and the maximum value are set to 0 and 255 respectively, and the cv2.THRESH_BINARY algorithm is used for threshold division;
[0131] Use cv2.medianBlur function to perform median filtering, where the filter kernel size is set to 5;
[0132] Morphological processing: hole filling, two morphological dilation processes, hole filling, three morphological erosion processes, and three morphological dilation processes are performed in sequence. At this time, the background values of the R channel are all 0, so the background values of the R channel are assigned to the G and B channels, and the three channels are superimposed to generate an image with background removed;
[0133] Step 2.2: Crop the image obtained in step 2.1 and generate a small image containing a single sorghum grain:
[0134] The background pixel values of the image obtained in step 2.1 are all 0, that is, completely black. At this time, in order to generate 115 small images containing a single sorghum grain from the image containing 115 sorghum grains, the image obtained in step 2.1 is first binarized, and then the attributes of all 8 connected regions in the image are obtained to generate a small image containing a single sorghum grain with a size of 224×224 for subsequent network model training.
[0135] Step 2.3: Remove defective grains from the small image containing a single sorghum grain obtained in step 2.2:
[0136] The grains whose ratio of white area pixels within the sorghum grain range to the pixels within the box area is greater than 1 / 4 are regarded as damaged grains and are removed; the ratio of white area pixels within the sorghum grain range to the pixels within the box area is the ratio of the number of pixels with a pixel value of 255 in the box to the total number of pixels in the box.
[0137] Step 3: Dataset division
[0138] Repeat step 2.3 for each 224×224 image containing a single sorghum grain obtained for each sorghum variety, and finally obtain 1000 small images containing a single sorghum grain for each sorghum variety. From each sorghum variety, extract 600 small images as the training set of the model, 100 images as the cross-validation set of the model, and 300 images as the test set of the model;
[0139] Step 4: Structural adjustment of the Xception network model:
[0140] Step 4.1, adjust the size of the image input layer to 224×224×3; use the z-score preprocessing method to preprocess the input image at the input layer;
[0141] Step 4.2, adjust the last fully connected layer of the image; set the output of the fully connected layer to 8, that is, 8 categories of sorghum, including Luzhou red and 7 non-demand sorghum;
[0142] Step 4.3: Use the Adam optimization algorithm to train the network, set the batch size to 64, the learning rate decay rate to 0.1, and the learning rate decays once every 10 generations of training;
[0143] Step 4.4, perform anti-aliasing on the maximum pooling layer in the Xception network;
[0144] The maximum pooling layer with a stride of 2 is replaced by a maximum pooling layer with a stride of 1 and a downsampling layer with a stride of 2. The size of the convolution kernel remains unchanged.
[0145] Step 5: Substitute the training set of the Luzhou Red model and the cross-validation set images of the Luzhou Red model obtained in step 3 into the Xception network obtained in step 4 for training to obtain a trained Luzhou Red adulteration discrimination model.
[0146] The test set image of the Luzhou Red model obtained in step 3 is substituted into the Luzhou Red adulteration discrimination model for testing. The confusion matrix obtained by the test is as follows: Figure 4a shown.
[0147] Among them, JNL1, JNL2, JNL4, JNL7, JNL8, JNL9, and LN represent 7 non-demand sorghums: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9, and Liaoning Hongyingzi; LangN1 represents the demand sorghum: Langnuohong (Langnuohong No. 1).
Claims
1. A method for detecting adulteration of brewing sorghum based on machine vision using a brewing sorghum adulteration detection system based on machine vision, the system comprising: Industrial color camera (1), LED white light dome light source (2), black sample plate (3), sieve plate (4) and computer (5); An LED white light dome light source (2) is arranged above the black sample plate (3), and a mesh plate (4) is placed on the black sample plate (3), wherein the light emitting area of the LED white light dome light source (2) is larger than the area of the mesh plate (4); an opening is arranged at the top of the LED white light dome light source (2); an industrial color camera (1) is arranged vertically, and a lens of the industrial color camera (1) faces the mesh plate (4) from the top opening of the LED white light dome light source (2); the industrial color camera (1) and a computer (5) are connected via a data cable; a plurality of mesh holes are arranged on the mesh plate (4); and the method is characterized in that: Three demand sorghum varieties, Luzhouhong, Langnuohong and Yinuohong, and seven non-demand sorghum varieties with the smallest appearance difference from the demand sorghum varieties were selected as sorghum samples to be tested; a total of four classification models were established, namely, the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong, and the adulteration discrimination model of mixed demand samples of Luzhouhong, Langnuohong and Yinuohong; when making adulteration predictions, any one of the four models was selected for testing according to the demand sorghum variety to be tested; Step 1, respectively obtain the original image of each sorghum variety; For the Luzhouhong adulteration discrimination model, the original images of Luzhouhong and seven non-demand sorghum varieties were obtained respectively; For the Langnuohong adulteration discrimination model, the original images of Langnuohong and seven non-demand sorghum varieties were obtained respectively; For the adulteration discrimination model of Yinuohong, the original images of Yinuohong and seven non-demand sorghum varieties were obtained respectively; For the adulteration discrimination model of mixed demand samples of Luzhouhong, Langnuohong and Yinuohong, the original images of Luzhouhong, Langnuohong, Yinuohong and 7 non-demand sorghum varieties were obtained respectively; The seven non-demand sorghum varieties are: Jinnuoliang No. 1, Jinnuoliang No. 2, Jinnuoliang No. 4, Jinnuoliang No. 7, Jinnuoliang No. 8, Jinnuoliang No. 9 and Liaoning Hongyingzi; When acquiring each image, a certain amount of sorghum grain samples are randomly selected from each sorghum variety, and the sorghum grain samples are dispersed using a sieve plate (4). The sorghum images are captured using an industrial color camera (1), and each image contains m sorghum grains. n images are acquired from each sorghum variety, and the size of each image is 1944×2592, which are called original images. Step 2, extracting single grains of sorghum from each original image of each sorghum variety and generating images of the same size, and removing defective grains; Step 2.1: Preprocess each original image of each sorghum variety: The background of each original image of each sorghum variety collected was removed: the image of the R channel was selected for binarization, and the salt and pepper noise was eliminated using the median filter; Morphological processing: hole filling, two morphological dilation processes, hole filling, three morphological erosion processes, and three morphological dilation processes are performed in sequence; at this time, the background values of the R channel are all 0, so the background of the R channel is assigned to the G and B channels, and the three channels are superimposed to generate an image with background removed; Step 2.2: Crop the image obtained in step 2.1 and generate a small image containing a single sorghum grain: The background pixel values of the image obtained in step 2.1 are all 0, that is, all black. At this time, in order to generate m small images containing a single sorghum grain from the image containing m sorghum grains, the image obtained in step 2.1 is first binarized, and then the attributes of all 8 connected regions in the image are obtained to generate a small image containing a single sorghum grain with a size of 224×224 for later network model training; Step 2.3: Remove defective grains from the small image containing a single sorghum grain obtained in step 2.2: The grains with a ratio of white area pixels within the sorghum grain range to the area pixels within the box greater than 1 / 4 are regarded as damaged grains and removed; the ratio of white area pixels within the sorghum grain range to the area pixels within the box is the ratio of the number of pixels with a pixel value of 255 within the box to the total number of pixels within the box; Step 3: Dataset division; Repeat step 2.3 for each 224×224-sized small image containing a single sorghum grain obtained for each sorghum variety, and finally obtain s small images containing a single sorghum grain for each sorghum variety; extract 60%×s small images from each sorghum variety as the training set of the model, 10%×s images as the cross-validation set of the model, and 30%×s images as the test set of the model; For the Luzhou Red adulteration discrimination model, a training set of the Luzhou Red adulteration discrimination model, a cross-validation set of the Luzhou Red adulteration discrimination model, and a test set of the Luzhou Red adulteration discrimination model are obtained respectively; For the Langnuohong adulteration discrimination model, the training set of the Langnuohong adulteration discrimination model, the cross-validation set of the Langnuohong adulteration discrimination model and the test set of the Langnuohong adulteration discrimination model are obtained respectively; For the Yinuohong adulteration discrimination model, the training set of the Yinuohong adulteration discrimination model, the cross-validation set of the Yinuohong adulteration discrimination model and the test set of the Yinuohong adulteration discrimination model are obtained respectively; For the mixed demand sample adulteration discrimination model, a training set of the mixed demand sample adulteration discrimination model, a cross-validation set of the mixed demand sample adulteration discrimination model and a test set of the mixed demand sample adulteration discrimination model are obtained respectively; Step 4: Structural adjustment of the Xception network model; Step 4.1, adjust the size of the image input layer to 224×224×3; use the z-score preprocessing method to preprocess the input image at the input layer; Step 4.2: Adjust the last fully connected layer of the image; For the Luzhouhong adulteration discrimination model, the output of the fully connected layer is set to 8, which means 8 categories of sorghum, including Luzhouhong and 7 non-demand sorghums; For the Langnuohong adulteration discrimination model, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Langnuohong and 7 non-demand sorghums; For the adulteration discrimination model of Yinuohong, the output of the fully connected layer is set to 8, i.e., 8 categories of sorghum, including Yinuohong and 7 non-demand sorghums; For the mixed demand sample adulteration discrimination model, the output of the fully connected layer was set to 10, i.e., 10 categories of sorghum, including Luzhou red, Langnuo red, Yinuo red, and 7 non-demand sorghums; Step 4.3: Use the Adam optimization algorithm to train the network, set the batch size to 64, the learning rate decay rate to 0.1, and the learning rate decays once every 10 generations of training; Step 4.4, perform anti-aliasing on the maximum pooling layer in the Xception network; The maximum pooling layer with a stride of 2 is replaced by a maximum pooling layer with a stride of 1 and a downsampling layer with a stride of 2; the size of the convolution kernel remains unchanged; Step 5, respectively substitute the training sets of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained adulteration discrimination model of Luzhouhong, the adulteration discrimination model of Langnuohong, the adulteration discrimination model of Yinuohong and the mixed demand sample adulteration discrimination model; Step 5.1, substitute the training set of the Luzhou Red adulteration discrimination model obtained in step 3 and the cross-validation set images of the Luzhou Red adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained Luzhou Red adulteration discrimination model; Substituting the test set image of the Luzhou Red adulteration discrimination model obtained in step 3 into the Luzhou Red adulteration discrimination model for testing, and testing the confusion matrix obtained; Step 5.2, substitute the training set of the Langnuohong adulteration discrimination model and the cross-validation set images of the Langnuohong adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training, and obtain the trained Langnuohong adulteration discrimination model; Substituting the test set images of the Langnuohong adulteration discrimination model obtained in step 3 into the Langnuohong adulteration discrimination model for testing, and testing the obtained confusion matrix; Step 5.3, substitute the training set of the Yinuohong adulteration discrimination model and the cross-validation set images of the Yinuohong adulteration discrimination model obtained in step 3 into the Xception network obtained in step 4 for training, and obtain the trained Yinuohong adulteration discrimination model; Substituting the test set images of the Yinuohong adulteration discrimination model obtained in step 3 into the Yinuohong adulteration discrimination model for testing, and testing the obtained confusion matrix; Step 5.4, substitute the training set of the mixed demand sample adulteration discrimination model obtained in step 3 and the cross-validation set images of the mixed demand sample adulteration discrimination model into the Xception network obtained in step 4 for training, and obtain the trained mixed demand sample adulteration discrimination model; The test set images of the mixed demand sample adulteration discrimination model obtained in step 3 are substituted into the mixed demand sample adulteration discrimination model for testing, and the confusion matrix obtained by the test is tested.
2. The method for detecting adulteration of brewing sorghum based on machine vision according to claim 1, characterized in that: In step 1, m=115, n=10.
3. The method for detecting adulteration of brewing sorghum based on machine vision according to claim 1, characterized in that: The diameter of the sieve holes is 4.5 mm, and the hole spacing is 5.5 mm.
4. The method for detecting adulteration of brewing sorghum based on machine vision according to claim 1, characterized in that: The screen plate (4) carries 115 sorghum grains.
5. The method for detecting adulteration of brewing sorghum based on machine vision according to claim 1, characterized in that: The height of the screen plate (4) is 1 mm.
6. The method for detecting adulteration of brewing sorghum based on machine vision according to claim 1, characterized in that: The diameter of the LED white light dome light source (2) is 170 mm.
Citation Information
Patent Citations
Intelligent pearl sorting system based on machine vision
CN107309181A
Multi-channel image acquisition device and a multi-channel image acquisition method
CN109819150A
Sorghum disease intelligent recognition system and recognition method based on machine vision
CN111967357A
Sorghum opening rate detection method and system based on machine vision
CN114037898A
Dome ring light combined light source measuring device
CN210071675U
