Rapeseed counting method based on density map estimation
The Python software and Bayesian Loss model combined with the deep learning network to generate density maps, solve the problem of time-consuming and laborious rapeseed grain counting, and achieve efficient and accurate grain counting, which can quickly estimate the number and quality of grains.
Patent Information
- Application Number
- CN202510683390.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-26
- Publication Date
- 2025-08-15
AI Technical Summary
In the prior art, rapeseed grain counting method is time-consuming and labor-intensive, easily causing visual and brain fatigue, and the counting is inaccurate, making it difficult to achieve efficient and intelligent counting.
Data processing technology based on Python software for grain calibration and Bayesian Loss model is used to generate density maps, and rapeseed grain counting is combined with deep learning networks. Multi-scale features are generated using VGG19 network and grain count is estimated through density maps.
It realizes high-precision grain counting under different densities, with high counting accuracy, can quickly and accurately estimate grain quantity and quality, and improves counting efficiency and accuracy.
Smart Images

Figure CN120495273A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of rapeseed grain counting, and in particular to a rapeseed grain counting method based on density map estimation. Background Art
[0002] Intelligent grain counting. Currently, there are two methods for grain counting: manual counting and instrumental analysis. Most researchers currently working on grain counting have opted for instrumental analysis, which offers high accuracy, low operational complexity, and the ability to test a large number of samples. In recent years, data processing technology based on the Bayesian Loss model has rapidly developed and achieved high accuracy. The pursuit of intelligent instrumentation, simplified operation, and convenient operation is the mainstream of current research.
[0003] Accurate seed counting. From image analysis methods such as erosion and dilation, watershed algorithms, active contour models, and feature point matching, to counting using sound impact and infrared light, scientists have been exploring how to replace traditional manual operations with precision machines, improve detection accuracy, and expand the pixel count range. To this end, we propose a rapeseed seed counting method based on density map estimation. Summary of the Invention
[0004] The object of the present invention is to provide a rapeseed grain counting method based on density map estimation to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention provides the following technical solution: a rapeseed grain counting method based on density map estimation, which implements rapeseed grain counting by the following steps:
[0006] S1. Use Python software to calibrate rapeseed grains and accurately locate the position of each grain;
[0007] S2. The data processing technology of the Bayesian Loss model is used to process the data to accurately obtain the image of each data set and the area where the rapeseed is densely adhered.
[0008] Preferably, in the laboratory stage, the OCR digital reading uses the template matching method of opencv to obtain the LED digital.
[0009] Preferably, in the actual application stage, OCR digital reading uses a deep learning solution to improve the adaptability to complex scenarios.
[0010] Preferably, the deep learning solution for OCR digital reading in the practical application stage is: using the MNIST data set and the text recognition data set in the Baidu OCR text recognition case to implement model training and testing. In this way, not only the recognition of LED numbers can be achieved, but also the recognition of more complex handwritten numbers can be achieved.
[0011] Preferably, software is used in S1 to mark the grains in the image, and in actual use, the grains are marked under different density conditions. After the marking is completed, the Python software converts the image annotation information into a mat file, which is used as the input of the deep learning network model. The mat file contains the coordinates of the annotation points and the number of annotation points.
[0012] Preferably, the Bayesian Loss model in S2 includes a density map generation network, which is a network based on VGG19, and uses the calibrated image of rapeseed grains as a data source, and then processes it as a data source.
[0013] Preferably, the steps of the density map generation model are:
[0014] First, the original image is scaled to 512×512 pixels. The VGG19 network is used to obtain multi-scale features. Specifically, it includes 5 convolutional layers, 4 pooling layers, and 5 ReLU functions. The size of the convolution kernel in the convolution layer is 3×3. The pooling layer uses a 2×2 convolution kernel for maximum pooling to complete the downsampling of the feature map and obtain high-dimensional hidden layer features.
[0015] The feature map is then upsampled and fine-tuned through two 3×3 convolutions.
[0016] Finally, a 1×1 convolution can generate a predicted density map of 512×512 pixels. The pixels of the density map are integrated to obtain the number of rapeseed grains.
[0017] Preferably, a Bayesian Loss model verification method is also included, which is: establishing a univariate linear regression equation for rapeseed to estimate the thousand-grain weight of rapeseed grains, comparing it with the actual thousand-grain weight, and obtaining the accuracy of our Bayesian Loss model in grain counting.
[0018] Compared with the prior art, the present invention has the following beneficial effects:
[0019] 1. The present invention uses Python language to make the recognition tool, and in actual use, it can achieve high-precision marking of different densities of rapeseed in images collected by different image acquisition devices, and after the calibration is completed, the image annotation information can be converted into a mat file to be used as the input of the subsequent deep learning network model.
[0020] 2. The present invention establishes a Bayesian Loss model to generate a density map, which is processed to more efficiently and accurately count rapeseed grains. It also uses Bayesian learning loss to supervise each grain with a point to complete the accurate counting of the grain points.
[0021] 3. This invention establishes a relationship model between rapeseed grain number and quality by using a high-precision electronic scale to measure rapeseed grain samples using the number of rapeseed grain images obtained through image processing. Therefore, the number of rapeseed grain images can be used to estimate rapeseed grain quality, and thus the thousand-kernel weight of the rapeseed. The measured thousand-kernel weight is compared with the actual thousand-kernel weight of the rapeseed grains to determine the accuracy of the Bayesian Loss model, verifying its reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a flow chart of the counter system of the present invention;
[0023] Figure 2 This is the calibration diagram under medium density of the present invention;
[0024] Figure 3 This is a flow chart marked in the present invention;
[0025] Figure 4 This is a flow chart of the algorithm in the present invention;
[0026] Figure 5 This is the Bayesian Loss model structure diagram of the present invention;
[0027] Figure 6 This is the density map 1 of the present invention;
[0028] Figure 7 This is the second density map of the present invention. DETAILED DESCRIPTION
[0029] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0030] This invention provides a technical solution to address the time-consuming and labor-intensive nature of traditional manual rapeseed seed counting, which can lead to visual and brain fatigue and errors caused by prolonged observation and counting. This project aims to improve the efficiency and accuracy of intelligent seed counting. This project aims to design a rapeseed seed counter based on density map estimation. The counter uses Python software to calibrate rapeseed seeds, precisely locating each kernel. Data processing techniques based on the Bayesian Loss model are then used to accurately generate images of each dataset and identify areas of dense rapeseed seed adhesion. This allows for faster seed counting and improved accuracy.
[0031] OCR digit reading: Two approaches are planned. In the laboratory phase, OpenCV template matching will be used to capture LED digits, offering significant advantages in efficiency and accuracy. In the practical application phase, a deep learning approach will be employed to improve adaptability to complex scenarios. The former approach is generally capable of highly efficient recognition and acquisition of single images under relatively good laboratory conditions. The latter will utilize the MNIST dataset and text recognition datasets from Baidu's OCR text recognition case studies to train and test the model. This approach will enable recognition not only of LED digits but also of more complex handwritten digits.
[0032] Use software to mark the kernels in the image. In actual use, different image acquisition devices may have different densities of rapeseed in the images. In this case, the kernels under different density conditions can also be marked. The specific graphics marking can be seen below. Figure 1 As shown, after the calibration is completed, Python software converts the image annotation information into a mat file. The specific process is as follows Figure 4 , used as input for the deep learning network model. The mat file contains the coordinates and number of annotation points. It achieves near-100% count accuracy at low and medium density calibrations, while there is a certain degree of error at high density. During high-density counting, due to overlapping rapeseed seeds and the presence of photographs, the count may deviate from the actual number, but this remains within a manageable range.
[0033] Due to the widespread use of CNNs in various machine vision applications, most current mainstream image processing technologies use image datasets constructed using CNNs. By processing image data, a dataset within the image is obtained, and further processing is performed on the image to produce a more accurate image, thereby achieving better image processing results. Based on this, in-depth research has been conducted on computational methods for estimating quantities, using dense graphs represented by CNNs and deep neural networks. Many meaningful results have been obtained, and the network structure of these computational methods is also continuously evolving and progressing in a positive direction. Based on the method used to generate the density map, these models can be divided into two categories: direct density regression estimation methods and probability density map regression estimation methods.
[0034] With the continuous improvement of deep learning technology, the CNN density regression algorithm has been widely used in demographic problems. The excellent performance of CNN can also be extended to other statistical problems, thus expanding its applicability. The Bayesian Loss model uses Bayesian loss to supervise the expected number of each rapeseed marker and obtain the best statistical results. Therefore, in this project, we will focus on the Bayesian Loss model.
[0035] The Bayesian Loss model can be divided into two parts according to its function. One is the density map generation network, which is a network based on VGG19. It can use the calibrated image of rapeseed grains as a data source and then process it as a data source to obtain a data source. Figure 3 shown.
[0036] In the density map generation model, the original image is first scaled to 512×512 pixels. Multi-scale features are then obtained using the VGG19 network, which consists of five convolutional layers, four pooling layers, and five ReLU functions. The convolution kernels in the convolutional layers are all 3×3 in size, and the pooling layers use a 2×2 kernel for maximum pooling, which downsamples the feature map and generates high-dimensional hidden layer features. The feature map is then upsampled and fine-tuned using two 3×3 convolutions. Finally, a 1×1 convolution generates a 512×512 pixel predicted density map. Integrating the density map pixels yields the number of rapeseed kernels.
[0037] The labeled images are used as labels for the dataset in the experiment, namely GT (Ground Truth). The requirements for rapeseed grain counting GT are that, on the one hand, the actual number of rapeseed grains in the original image can be obtained, and on the other hand, the characteristic distribution i of the original image can be maintained. In order to solve the problem of difficulty in improving counting accuracy under severe occlusion, relevant researchers introduced a regression-based method. Since the BayesianLoss model is difficult to use existing labeling information to establish labeling information based on labeling information, and uses labeling information as prior information, a 2D Gaussian distribution is used to fit the labeling information, thereby establishing a labeling information x based on labeling information. m Likelihood function, that is, the label information y n The marking information, that is, rapeseed seeds only exist in the marking information x m The conditional probability of , the specific formula can be seen in formula (2):
[0038] p(y n / x m )=N(x m ;z n ,σ 2 12×20) (2)
[0039] x m It represents a two-dimensional pixel position in the existing density map, y n =n represents the label of a given two-dimensional pixel, {(z n ,y n ):n=1,2,...,N} represents the point annotation map of the sample image, N is the total number of rapeseed grains, z n Indicates the location of rapeseed mark point, N(x m ;z n ,σ 2 1 2×2 ) is x m 2D Gaussian distribution at, according to Bayes theorem, x m With y n The posterior probability of the label is formula (3).
[0040]
[0041] The posterior probability field defines the probability that each position in the space belongs to a certain target. Therefore, the expected count of each target is calculated, and the expected number of the nth rapeseed grain E[c n ]See formula (4):
[0042]
[0043] D est x mIndicates the influence of the marked information on the marked information, Represents the spatial position x m Label it y n =n, that is, the probability of there being rapeseed grains in a certain spatial location, c n =n is with y n = the total number of n levels. Formula (2-3) is obtained by the posterior probability p(y n / x m ) and D est x m The expected number of each target is calculated by multiplying and adding , and the corresponding Bayesian loss function is given, as shown in formula (5).
[0044]
[0045] In order to better construct a model for background pixels, the Bayesian Loss model introduces an additional background label. When y0 = 0, the posterior probability is changed to formula (6): Then there is,
[0046]
[0047] The expected counts of the foreground and the entire background are respectively expressed as (7) and (8):
[0048]
[0049] In practice, the best result is that the background count is zero and the foreground count of each annotation point is 1. Therefore, the following enhancement loss function is proposed, see formula (9).
[0050]
[0051] In order to define the background possibility, Bayesian Loss constructs a virtual background point z0m for each pixel, see Equation (10).
[0052]
[0053] Through simulation experiments on the Bayesian Loss model, the superiority of the Bayesian Loss model in prediction accuracy, robustness and promotion performance is verified. To this end, we will use Bayesian learning loss to supervise each seed with a number to complete the accurate counting of the number of seed points. In the Bayesian model, when the variance of the Gaussian distribution is 16, the resulting density map has a strong ambiguity. In the predicted density map, the brighter it is, the more ambiguous it is, and the darker it is, the clearer it is whether it is rapeseed grains or background. In areas where rapeseed grains are sparse, they are all dark, while in areas where rapeseed grains are dense, they appear brighter. At this point, the smaller σ is, the clearer the information in the figure will be. This is because a small σ is not easy to cause overlap of rapeseed grain areas, such as Figure 5-7 shown.
[0054] Under the Bayesian model, classification is excellent. It is effective for small data sets and can handle multiple classifications simultaneously. In particular, when the data exceeds the memory capacity, incremental learning can be performed repeatedly. This method is minimally affected by sample loss and is simple, making it frequently used in text recognition. The Bayesian Loss model exhibits excellent counting performance. In density plots, its mean absolute error (MAE) reaches 15.34, its mean square error (MSE) reaches 20.19, and its average relative error (REL) reaches 1.32%. The Bayesian Loss model clearly displays the density range of rapeseed seeds and the precise number of labeled seeds, enabling better identification of rapeseed seeds and analyzing the impact of different densities on seed identification. This system can also be directly applied to counting crop seeds during agricultural sowing and production. It can help directly determine the thousand-kernel weight of crops. Thousand-kernel weight is a measure of seed quality, and in agricultural production, it can be used to predict crop yields in advance. The Bayesian Loss model allows us to quickly and accurately determine the number of seeds with high accuracy. The development of automatic counting enables staff to quickly and accurately obtain the set number of grains, making our staff's work more relaxed.
[0055] Thousand-kernel weight is a significant factor affecting rapeseed quality, and accurate kernel counting is crucial for achieving this goal. We estimate rapeseed thousand-kernel weight by establishing a linear regression equation. Comparing this with the actual thousand-kernel weight reveals the accuracy of our Bayesian Loss model for kernel counting. Our Bayesian Loss model consistently maintains a high level of kernel count prediction, significantly improving the accuracy and efficiency of rapeseed kernel counting technology.
[0056] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.
[0057] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A method for counting rapeseed grains based on density map estimation, characterized in that: The following steps are used to count rapeseed grains: S1. Use Python software to calibrate rapeseed grains and accurately locate the position of each grain; S2. The data processing technology of the Bayesian Loss model is used to process the data to accurately obtain the image of each data set and the area where the rapeseed is densely adhered.
2. The method for counting rapeseed grains based on density map estimation according to claim 1, characterized in that: In the laboratory stage, the OCR digital reading method of OpenCV template matching is used to obtain LED numbers.
3. The rapeseed grain counting method based on density map estimation according to claim 1, characterized in that: In the practical application stage of OCR digital reading, deep learning solutions are used to improve the adaptability to complex scenarios.
4. The rapeseed grain counting method based on density map estimation according to claim 1, characterized in that: The deep learning solution for OCR digital reading in the actual application stage is to use the MNIST dataset and the text recognition dataset in the Baidu OCR text recognition case to implement model training and testing. This method not only realizes the recognition of LED numbers, but also includes the recognition of more complex handwritten numbers.
5. The method for counting rapeseed grains based on density map estimation according to claim 1, wherein: In the S1, software is used to mark the grains in the image, and in actual use, the grains are marked under different density conditions. After the marking is completed, the Python software converts the image annotation information into a mat file, which is used as the input of the deep learning network model. The mat file contains the coordinates of the annotation points and the number of annotation points.
6. The rapeseed grain counting method based on density map estimation according to claim 1, characterized in that: The Bayesian Loss model in S2 includes a density map generation network, which is a network based on VGG19. The calibrated image of rapeseed grains is used as a data source and then processed as a data source.
7. The rapeseed grain counting method based on density map estimation according to claim 1, characterized in that: The steps of the density map generation model are: First, the original image is scaled to 512×512 pixels. The VGG19 network is used to obtain multi-scale features. Specifically, it includes 5 convolutional layers, 4 pooling layers, and 5 ReLU functions. The size of the convolution kernel in the convolution layer is 3×3. The pooling layer uses a 2×2 convolution kernel for maximum pooling to complete the downsampling of the feature map and obtain high-dimensional hidden layer features. The feature map is then upsampled and fine-tuned through two 3×3 convolutions. Finally, a 1×1 convolution can generate a predicted density map of 512×512 pixels. The pixels of the density map are integrated to obtain the number of rapeseed grains.
8. The method for counting rapeseed grains based on density map estimation according to claim 1, characterized in that: It also includes a Bayesian Loss model verification method, which is to establish a univariate linear regression equation for rapeseed to estimate the thousand-grain weight of rapeseed grains, compare it with the actual thousand-grain weight, and obtain the accuracy of our Bayesian Loss model for grain counting.