Cigarette cut stem weight calculation method, device and equipment and storage medium

By using image recognition technology and data modeling, the accuracy problem of stem weight detection has been solved, realizing automated calculation and detection of stem weight, and improving the objectivity and consistency of detection.

CN121861397APending Publication Date: 2026-04-14HONGYUN HONGHE TOBACCO (GRP) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-21
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing technologies cannot accurately measure the weight of stems in stem weight detection and analysis, resulting in a lack of key data support for stem structure characterization and blending uniformity assessment.

Method used

By combining image recognition technology with Gaussian filtering, maximum inter-class variance method, edge detection, support vector regression model and Kalman filtering algorithm, the weight of the stem wire can be automatically estimated.

Benefits of technology

Through systematic image processing and data modeling, accurate and automated calculation of stem weight was achieved, reducing manual intervention and improving the objectivity and consistency of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121861397A_ABST
    Figure CN121861397A_ABST
Patent Text Reader

Abstract

The invention discloses a weight calculation method, device and equipment for cigarette cut stems and a storage medium, and relates to the technical field of tobaccos, and the method realizes automatic estimation of the weight of the cigarette cut stems through device image processing and data modeling. Wherein in the step S1, an original image is preprocessed through Gaussian filtering noise reduction, and the image quality basis of subsequent analysis is improved; s2, extracting continuous contours of the cut stems by means of maximum between-class variance method segmentation and edge detection, and defining morphological boundaries; s3, calculating the area of a single piece through a pixel counting method, accumulating the area to obtain the total area, and quantifying the visual features; s4, inputting the total area into a pre-training support vector regression model, obtaining initial weight estimation through nonlinear mapping, and establishing association between the area and the weight; s5, performing normalization processing on the initial estimation, and unifying the data scale; and S6, optimizing the estimation stability by using Kalman filtering dynamic estimation and noise filtering, and finally outputting a weight calculation result. Manual intervention is reduced, and the accuracy and consistency of estimation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of tobacco technology, and in particular to a method, apparatus, device and storage medium for calculating the weight of cigarette stems. Background Technology

[0002] Stem fibers, used as fillers, are widely applied in tobacco processing. When stem fibers are used in blending, their appearance quality (structure, width, curl, etc.) and blending ratio (the percentage of stem fibers by weight in the finished tobacco) directly affect the quality of cigarette rolling, sensory quality, and consumption. The appearance quality and blending ratio of stem fibers are primarily tested using manual weighing and visual inspection to measure the weight percentage of stem fibers with different characteristics or their proportion in the tobacco, thereby evaluating the processing quality and blending uniformity.

[0003] Currently, the manual weighing method mainly uses multi-layer vibrating sieves to detect the structure of stems and filaments. It can only characterize the discrete distribution of stem and filament size and cannot accurately describe the continuous distribution of stem and filament size in different intervals. When judging the width and curvature of stems and filaments by visual inspection, there is a large degree of subjectivity and it cannot accurately describe their weight distribution. Moreover, the efficiency of manually picking and weighing to detect the blending ratio of stems and filaments is too low, the labor intensity is high, and the accuracy is insufficient.

[0004] Image recognition technology can efficiently and objectively acquire the morphological parameters of all stems in a test sample, such as length, width, and curl, significantly improving the continuity, accuracy, and objectivity of stem size distribution evaluation, and enabling rapid identification of stems in tobacco samples. However, while this technology can accurately depict the appearance and morphological characteristics of stems, it cannot directly convert them into corresponding quality data. Therefore, it still lacks crucial data support when characterizing stem structure and evaluating blending uniformity based on weight. Summary of the Invention

[0005] This application aims to provide a method, apparatus, device, and storage medium for calculating the weight of cigarette stems, thereby addressing the limitations of existing technologies in the detection and analysis of stem weight. While image recognition methods can be used for detecting the appearance features of stems and identifying stems in tobacco, they cannot directly and accurately measure stem weight, leading to difficulties in obtaining reliable weight data for stem structure characterization and blending uniformity assessment.

[0006] To achieve the above objectives, this application provides the following technical solution: A method for calculating the weight of cigarette stems, wherein the weight calculation method is applied to a sample of cigarette stems to be tested, the weight calculation method comprising: Step S1: Acquire the original image data of the cigarette stem sample to be tested using an external linear array scanning device, and perform noise reduction preprocessing on the original image data using a Gaussian filtering algorithm to obtain preprocessed image data; Step S2: The preprocessed image data is subjected to adaptive threshold segmentation using the maximum inter-class variance method to obtain a binarized image, and the continuous contour information of cigarette stems in the binarized image is extracted using an edge detection algorithm. Step S3: Based on the continuous contour information, calculate the area feature of each cigarette stem using the pixel counting method, and sum the area features of all cigarette stems to obtain the total area data of the cigarette stems. Step S4: Input the total area data of the cigarette stems into the pre-trained support vector regression model, and calculate the initial weight value of the cigarette stems through the nonlinear mapping function of the support vector regression model. Step S5: Normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value. Step S6: The standardized cigarette stem weight value is dynamically estimated and noise is filtered out using the Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

[0007] Beneficial effects of steps S1 to S6: The system achieves automated estimation of cigarette stem weight through systematic image processing and data modeling. Step S1 preprocesses the original image using Gaussian filtering for noise reduction, improving the image quality foundation for subsequent analysis. Step S2 uses Otsu's method for segmentation and edge detection to extract the continuous contours of the stems, clarifying their morphological boundaries. Step S3 calculates the area of ​​each stem using pixel counting and sums them to obtain the total area, quantifying visual features. Step S4 inputs the total area into a pre-trained support vector regression model, and obtains an initial weight estimate through nonlinear mapping, establishing the correlation between area and weight. Step S5 normalizes the initial estimate to unify the data scale. Step S6 uses Kalman filtering for dynamic estimation and noise removal to optimize estimation stability, finally outputting the calculated weight. These interconnected steps form a complete chain from image acquisition to weight output, reducing manual intervention and relying on objective algorithmic processing to improve the accuracy and consistency of the estimation.

[0008] As a further improvement to this application, in step S1, the original image data of the cigarette stem sample to be tested is acquired by an external linear array scanning device, and the original image data is preprocessed by a Gaussian filtering algorithm to reduce noise, resulting in preprocessed image data, including: Step S11: The cigarette stem sample to be tested is evenly laid on a backlight scanning platform with constant illumination conditions, no sample overlap, and uniform background. Step S12: Scan the cigarette stem sample to be tested on the backlight scanning platform with an external linear array scanning device at a preset sampling frequency to obtain the original image data stream; Step S13: The original image data stream is spliced ​​and reassembled to obtain a complete two-dimensional grayscale image, i.e., the original image data; Step S14: The weighted average of each pixel and its neighboring pixels in the original image data is obtained by using the preset Gaussian kernel function of the Gaussian filtering algorithm to obtain preliminary denoised image data. Step S15: Enhance the local contrast between the cigarette stem region and the background region in the preliminary denoised image data using a limited contrast adaptive histogram equalization algorithm to obtain enhanced image data; Step S16: The enhanced image data is traversed through a sliding window of a preset size using a median filtering algorithm to sort the gray values ​​of all pixels within the sliding window, and the gray value of the center pixel of the window is replaced with the median of the sorted gray values ​​to obtain the preprocessed image data.

[0009] Beneficial effects of steps S11 to S16: By standardizing sample placement, image acquisition, and multi-stage preprocessing, a reliable image foundation is laid for subsequent analysis. Specifically, step S11 involves evenly spreading the fibrous samples on a backlit platform to ensure constant illumination, no overlap, and a uniform background, thus clarifying the sample presentation state. Step S12 involves scanning the samples at a preset frequency to acquire the original image data stream and record visual information. Step S13 involves stitching and recombining the data stream into a complete two-dimensional grayscale image, constructing the raw image data ready for processing. Step S14 employs a Gaussian filtering algorithm, using a preset kernel function to weighted average the original image pixels and their neighborhoods to suppress random noise, resulting in a preliminary denoised image. Step S15 uses limited contrast adaptive histogram equalization to enhance the local contrast between the fibrous region and the background in the preliminary denoised image, highlighting target features. Step S16 uses median filtering, traversing the enhanced image with a preset-sized sliding window, sorting the grayscale values ​​within the window, and replacing the center pixel with the median value to further smooth residual noise and outliers, ultimately obtaining the preprocessed image data. The entire process forms a complete preprocessing chain, from standardized sample placement and image acquisition to multi-level noise reduction and enhancement, which improves image clarity and target discernibility, and provides quality assurance for subsequent contour extraction and area calculation.

[0010] As a further improvement of this application, step S2 involves performing adaptive threshold segmentation on the preprocessed image data using the maximum inter-class variance method to obtain a binarized image, and then extracting the continuous contour information of cigarette stems in the binarized image using an edge detection algorithm, including: Step S21: Perform global threshold calculation on the preprocessed image data using the maximum inter-class variance method to obtain the optimal grayscale threshold; Step S22: In the preprocessed image data, pixels with gray values ​​higher than the optimal gray value threshold are classified as target foreground, and pixels with gray values ​​lower than the optimal gray value threshold are classified as background, to obtain an initial binarized image; Step S23: Perform morphological closing operation on the initial binarized image, and obtain the improved binarized image by using circular elements of a preset radius to detect the small holes in the cigarette stem area of ​​the initial binarized image. Step S24: Calculate the gradient magnitude and direction of each pixel in the improved binarized image using the Canny edge detection algorithm, and extract the set of cigarette stem edge pixels through double threshold detection and edge connection. Step S25: Traverse the set of cigarette stem edge pixels using a contour tracking algorithm and serialize the interconnected edge pixels to identify and separate the complete closed contour of each cigarette stem in the set of cigarette stem edge pixels, thereby obtaining continuous contour information.

[0011] Beneficial effects of steps S21 to S25: Accurate acquisition of the morphological boundaries of cigarette stems is achieved through adaptive segmentation, binarization optimization, edge extraction, and contour tracking. Specifically, step S21 uses the Otsu's method to calculate the optimal grayscale threshold of the preprocessed image and performs adaptive segmentation based on the image's own grayscale distribution characteristics, providing a basis for distinguishing the target from the background. Step S22 categorizes pixels according to the threshold, with pixels above the threshold representing the target foreground and those below representing the background, generating an initial binarized image and clarifying the basic range of the stem region. Step S23 performs morphological closing operations on the initial binarized image, filling small holes in the stem region with circular elements of a preset radius to improve image connectivity, resulting in an improved binarized image. Step S24 uses the Canny edge detection algorithm to calculate the gradient magnitude and direction of each pixel in the image, and extracts the set of cigarette stem edge pixels through double threshold detection and edge connection, preserving key contour information. Step S25 uses a contour tracking algorithm to traverse the edge pixel set, serialize the connected pixels, identify and separate the complete closed contour of each stem, obtaining continuous contour information. The entire process forms a complete chain from threshold determination and binarization optimization to edge extraction and contour separation, providing an accurate morphological boundary basis for subsequent calculation of the area of ​​a single filament and accumulation of the total surface area, thereby improving the reliability of visual features for weight estimation.

[0012] As a further improvement to this application, step S3, based on the continuous contour information, calculates the area feature of each cigarette stem using a pixel counting method, and accumulates the area features of all cigarette stems to obtain the total area data of the cigarette stems, including: Step S31: Calculate the geometric moments of each complete closed contour in the continuous contour information, and obtain the minimum bounding rectangle of each complete closed contour. The minimum bounding rectangle is the length and width features of the corresponding cigarette stem. Step S32: Based on the continuous contour information, calculate the total number of pixels contained in each complete closed contour using a pixel filling algorithm, and convert the total number of pixels into physical area by combining the pixel resolution of the binarized image to obtain the area feature of each cigarette stem. Step S33: Accumulate the area features of all cigarette stems to obtain the total area data of cigarette stems.

[0013] Beneficial effects of steps S31 to S33: The quantitative extraction of cigarette stem area features is achieved through geometric moment calculation, pixel filling, and accumulation operations. Specifically, step S31 calculates the geometric moment of each closed contour in a continuous contour to obtain the corresponding minimum bounding rectangle, clarifying the length and width features of a single stem and providing geometric attribute references for area calculation. Step S32, based on the contour information, uses a pixel filling algorithm to count the total number of pixels inside each closed contour, and combines this with the pixel resolution of the binarized image to convert the pixel count into physical area, obtaining the area features of each stem and ensuring that area quantification is based on the actual contour range. Step S33 accumulates the area features of all single stems to form the total area data of cigarette stems. Overall, the algorithm objectively processes the contour information, transforming the visual form into an accumulative area value, establishing a correlation between area and weight for subsequent weight estimation, improving the accuracy and consistency of area data, and reducing human measurement errors.

[0014] As a further improvement to this application, step S4 involves inputting the total area data of the cigarette stems into a pre-trained support vector regression model, and calculating the initial weight value of the cigarette stems using the nonlinear mapping function of the support vector regression model, including: Step S41: Train the support vector regression model using the sequence minimum optimization algorithm with a preset historical dataset to obtain the pre-trained support vector regression model; Step S42: Input the total area data of the cigarette stems into the pre-trained support vector regression model, and perform nonlinear mapping on the total area data of the cigarette stems through the radial basis kernel function of the support vector regression model to obtain a high-dimensional feature vector; Step S43: Calculate the similarity between the high-dimensional feature vector and the support vector in the support vector regression model, and obtain the weighted contribution value by combining the Lagrange multiplier coefficients. Step S44: Sum all weighted contribution values ​​and add bias term parameters to obtain the initial cigarette stem weight value.

[0015] Beneficial effects of steps S41 to S44: By employing model training, nonlinear mapping, and weighted fusion, the correlation between the total area and weight of cigarette stems is established, and an initial estimate is output. Specifically, step S41 trains a support vector regression model using a sequential minimum optimization algorithm, obtaining a pre-trained model as a mapping tool; step S42 inputs the total stem area data into the model, extending it to a high-dimensional feature space through nonlinear mapping using the radial basis function kernel function, capturing the complex relationship between area and weight, and generating a high-dimensional feature vector; step S43 calculates the similarity between the high-dimensional feature vector and the model's support vectors, and combines Lagrange multipliers to evaluate the contribution of each support vector to the current input, obtaining a weighted contribution value; step S44 sums all weighted contribution values ​​and adds a bias term parameter, completing the initial transformation from area to weight, and outputting an initial estimate of the cigarette stem weight. Overall, relying on the nonlinear fitting capability of the support vector regression model, visually quantified area features are transformed into weight estimates, providing a foundational numerical basis for subsequent normalization and filtering processes, improving the objectivity and automation of the estimation.

[0016] As a further improvement to this application, step S5, normalizing the initial cigarette stem weight value to obtain a standardized cigarette stem weight value, includes: Step S51: Based on the global minimum and global maximum values ​​of stem weight in historical batches, the initial cigarette stem weight value is linearly normalized using Min-Max standardization to obtain the normalized weight value. Step S52: Define a sliding window buffer that maintains the normalized weight values ​​of the most recent several consecutive batches, and input the normalized weight values ​​into the sliding window buffer to form a time-series data stream; Step S53: The normalized weight value of the current batch is calculated by weighting the normalized weight value of the current batch with a preset smoothing factor using an exponentially weighted moving average to obtain the standardized cigarette stem weight value.

[0017] Beneficial effects of steps S51 to S53: Through linear normalization, temporal buffering, and dynamic smoothing, the predicted stem weight value is transformed into a standardized value with uniform scale and stable fluctuations. Specifically, step S51 uses the Min-Max normalization algorithm to linearly map the predicted weight value based on the global minimum and maximum values ​​of historical batch stem weight values, compressing it into a fixed interval and eliminating dimensional differences between different batches to obtain a normalized weight value. Step S52 defines a sliding window buffer to maintain the normalized weight values ​​of the most recent consecutive batches, inputting the current normalized weight value into the buffer to form a time-series data stream arranged in chronological order, providing a data foundation for capturing short-term trends. Step S53 uses an exponentially weighted moving average algorithm to weight the current batch's normalized weight value with a preset smoothing factor, giving higher weight to recent data and suppressing the influence of random fluctuations to obtain a standardized cigarette stem weight value. Overall, through a progressive processing approach of first unifying the scale, then accumulating time series data, and finally smoothing fluctuations, the initial predicted value is transformed into an input more suitable for dynamic state estimation, improving the stability of subsequent processing.

[0018] As a further improvement to this application, step S6 involves using a Kalman filter algorithm to perform dynamic state estimation and noise filtering on the standardized cigarette stem weight value to obtain the final cigarette stem weight calculation result, including: Step S61: Configure the state transition matrix and observation matrix of the Kalman filter, and calibrate the process noise and observation noise covariance matrix using standardized stem weight values ​​from several historical batches. Step S62: Input the standardized stem weight value of the current batch into the Kalman filter, and use the optimal state estimate of the previous batch of the Kalman filter as the prior state to calculate the state prior estimate and covariance prior of the current batch. Step S63: Calculate the Kalman gain based on the prior covariance of the current batch and the covariance of the observation noise; Step S64: The Kalman gain is linearly weighted and fused with the prior estimate of the current batch state and the observed value to obtain the posterior state estimate of the current batch, which is the final calculation result of the cigarette stem weight.

[0019] Beneficial effects of steps S61 to S64: By configuring filter parameters, dynamically calculating prior states, determining gains, and fusing estimates, dynamic state estimation and noise filtering of standardized stem weight values ​​are achieved, resulting in stable output. Specifically, step S61 configures the state transition matrix and observation matrix of the Kalman filter, using historical batch standardized weight values ​​to calibrate the process noise and observation noise covariance matrix, clarifying the system's dynamic characteristics and observation uncertainties. Step S62 inputs the current batch standardized weight value into the filter, using the optimal state estimate from the previous batch as a starting point, calculating the current state prior estimate and covariance prior to reflect the predicted state and uncertainty. Step S63 calculates the Kalman gain based on the current covariance prior and the observation noise covariance, balancing the trust weights of prediction and observation. Step S64 uses the Kalman gain to linearly weight and fuse the current prior estimate and observation values ​​to obtain the posterior state estimate, i.e., the final weight calculation result. Overall, through parameter configuration laying the foundation, prior calculation predicting the state, gain adjustment and trust allocation, and fusing and optimizing estimates, random noise is effectively filtered out, adapting to dynamic changes in weight values, improving the consistency and reliability of the results, and providing a stable output for weight calculation.

[0020] To achieve the above objectives, this application also provides the following technical solutions: A weight calculation device for cigarette stems, the weight calculation device being applied to the weight calculation method described above, the weight calculation device comprising: The cigarette stem image data acquisition module is used to acquire the original image data of the cigarette stem sample to be tested through an external linear array scanning device, and to perform noise reduction preprocessing on the original image data through a Gaussian filtering algorithm to obtain preprocessed image data. The cigarette stem image contour extraction module is used to perform adaptive threshold segmentation on the preprocessed image data using the maximum inter-class variance method to obtain a binarized image, and to extract the continuous contour information of the cigarette stems in the binarized image using an edge detection algorithm. The total area acquisition module for cigarette stems is used to calculate the area features of each cigarette stem based on the continuous contour information using a pixel counting method, and to accumulate the area features of all cigarette stems to obtain the total area data of the cigarette stems. The initial cigarette stem weight calculation module is used to input the total area data of the cigarette stems into a pre-trained support vector regression model, and calculate the initial cigarette stem weight value through the nonlinear mapping function of the support vector regression model. The cigarette stem weight normalization module is used to normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value. The cigarette stem weight calibration module is used to perform dynamic state estimation and noise filtering on the standardized cigarette stem weight value using a Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

[0021] To achieve the above objectives, this application also provides the following technical solutions: An electronic device includes a processor and a memory coupled to the processor, the memory storing program instructions executable by the processor; when the processor executes the program instructions stored in the memory, it implements the weight calculation method as described above.

[0022] To achieve the above objectives, this application also provides the following technical solutions: A computer-readable storage medium storing program instructions that, when executed by a processor, can implement the weight calculation method described above. Attached Figure Description

[0023] Figure 1 This is a schematic flowchart illustrating the steps of one embodiment of the method for calculating the weight of cigarette stems according to this application; Figure 2 This is a schematic diagram of the functional modules of an embodiment of a cigarette stem weight calculation device according to this application; Figure 3 This is a schematic diagram of the structure of an embodiment of the electronic device of this application; Figure 4 This is a schematic diagram of the structure of one embodiment of the storage medium of this application. Detailed Implementation

[0024] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0025] The terms "first," "second," and "third" in this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. All directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of this application are only used to explain the relative positional relationships and movements between components in a specific orientation (as shown in the figures). If the specific orientation changes, the directional indications also change accordingly. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.

[0026] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0027] like Figure 1 As shown, a method for calculating the weight of cigarette stems is applied to a sample of cigarette stems to be tested.

[0028] Specifically, the weight calculation method includes the following steps: Step S1: Acquire the original image data of the cigarette stem sample to be tested using an external linear array scanning device, and perform noise reduction preprocessing on the original image data using a Gaussian filtering algorithm to obtain the preprocessed image data.

[0029] Further, in step S1, the original image data of the cigarette stem sample to be tested is acquired through an external linear array scanning device, and the original image data is preprocessed by a Gaussian filtering algorithm to reduce noise, thereby obtaining preprocessed image data. Specifically, this includes the following steps: Step S11: The cigarette stem sample to be tested is evenly laid on a backlight scanning platform with constant illumination conditions, no sample overlap, and uniform background.

[0030] Preferably, the stalk sample to be tested can be evenly spread on a backlit scanning platform, with the single-layer thickness controlled between 0.3 mm and 0.8 mm (monitored in real time by a laser rangefinder above the platform, with an accuracy of ±0.02 mm). An LED surface light source with a wavelength of 550 nm green light can be used, which is offset from the absorption peak of chlorophyll in the stalk, with an illuminance uniformity of ≥95% and a fixed light intensity of 2500 lx ± 100 lx.

[0031] Preferably, the surface of the backlight scanning platform can be covered with a diffuse white acrylic sheet with a reflectivity of 85% and a color temperature of 6500K, and a black light-blocking strip with a width of 5mm is pasted on the edge to ensure that the grayscale difference between the sample and the background is ≥120.

[0032] Step S12: Scan the cigarette stem sample to be tested on the backlight scanning platform with an external linear array scanning device at a preset sampling frequency to obtain the original image data stream.

[0033] Preferably, a line scan camera with a resolution of 4096 pixels and a pixel size of 7μm can be used, along with a 16mm fixed-focus lens with an aperture of f / 2.8 and distortion of <0.1%.

[0034] The scanning mode involves the platform moving at a constant speed of 0.5 mm / s, and the camera sampling at a frequency of 10 kHz (i.e., acquiring 10,000 lines of images per second) to ensure that there are no gaps between adjacent lines. The line spacing = moving speed / sampling frequency = 0.5 mm / s / 10,000 Hz = 0.05 μm / line, which is much smaller than the pixel size of 7 μm, thus avoiding undersampling.

[0035] Step S13: The original image data stream is spliced ​​and reassembled to obtain a complete two-dimensional grayscale image, i.e., the original image data.

[0036] Preferably, a coordinate system is established with the platform movement direction as the X-axis (row direction) and the camera scanning direction as the Y-axis (column direction). The physical coordinates of the pixel in the i-th row and j-th column are X... i =i × line spacing, Y j =j × pixel size. The output of the line scan camera is 12-bit raw data (0-4095), which is converted to 8-bit grayscale (0-255) through linear mapping (divided by 16).

[0037] Step S14: The weighted average of each pixel and its neighboring pixels in the original image data is obtained by using the preset Gaussian kernel function of the Gaussian filtering algorithm to obtain the preliminary denoised image data.

[0038] Preferably, a 3×3 kernel can be used to balance noise reduction and detail preservation, with a standard deviation σ = 0.8. The kernel function is characterized as follows: Substituting σ=0.8, the 3×3 kernel weight matrix After normalization, it becomes: .

[0039] Preferably, for each pixel (i,j) in the image, its 3×3 neighborhood is taken, the boundary pixels are padded with zeros, and the average is weighted according to the kernel weight: ,in, In the initial denoising image data, the pixel gray value at coordinate (i,j), m,n∈{−1,0,1}, and m+2 and n+2 are 1-based indices for converting the offset (m,n∈{−1,0,1}) into kernel values. If a 0-based index (starting from 0) is used, it is equivalent to K(m+1,n+1), and they are essentially the same. This represents the grayscale value of the neighboring pixels in the original image data.

[0040] For example: Suppose the current pixel coordinates are (i,j)=(2,3) (i.e., the 2nd row and 3rd column), and we take a 3×3 neighborhood (m=−1,0,1; n=−1,0,1), then: When m=−1 and n=−1, the neighborhood pixel coordinates are (2−1,3−1)=(1,2), and the corresponding Gaussian kernel weight is K(−1+2,−1+2)=K(1,1) (that is, the first row and first column of the kernel matrix, with a value of 1 / 16).

[0041] When m=0 and n=0, the neighboring pixel coordinates are (2,3) (current pixel), and the corresponding weight is K(0+2,0+2)=K(2,2) (that is, the second row and second column of the kernel matrix, with a value of 4 / 16).

[0042] The sum of the weights × gray values ​​of all neighboring pixels is... The result of (2,3).

[0043] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0044] Step S15: Enhance the local contrast between the cigarette stem region and the background region in the preliminary denoised image data using a limited contrast adaptive histogram equalization algorithm to obtain the enhanced image data.

[0045] Preferably, Contrast Limited Adaptive Histogram Equalization (CLAHE) is a local contrast enhancement algorithm.

[0046] Specifically, the grid division of the limited contrast adaptive histogram equalization divides the image into 8×8 sub-blocks (each block has approximately 250,000 rows × 512 columns, which can be adaptively adjusted according to the image size); the contrast limiting can be set with a cropping threshold T=2 (that is, the number of pixels in the histogram that exceed twice the average value is cropped, and the excess pixels are evenly distributed to each gray level); the interpolation method is to fuse the sub-blocks through bilinear interpolation.

[0047] Step S16: The enhanced image data is traversed through a sliding window of a preset size using a median filtering algorithm to sort the gray values ​​of all pixels within the sliding window, and the gray value of the center pixel of the window is replaced with the median of the sorted gray values ​​to obtain the preprocessed image data.

[0048] Preferably, the preset parameters of the median filtering algorithm can be set as follows: the sliding window size is 5×5, and the sliding window size can be 3×3 / 5×5 / 7×7 through pre-testing. Among them, 5×5 is optimal in terms of noise reduction (high noise suppression rate) and detail preservation (low edge blur). The window step size is 1 pixel, that is, traversing pixel by pixel.

[0049] Preferably, the median filtering algorithm traverses from the top left corner (0,0), taking a 5×5 neighborhood, and using copying to fill the boundary, that is, pixels that exceed the image edge are replaced by the nearest neighbor pixel value; sorting and median replacement are achieved by sorting the gray values ​​of 25 pixels in the neighborhood in ascending order, and taking the 13th value (median) as the new value of the center pixel.

[0050] Beneficial effects of steps S11 to S16: By standardizing sample placement, image acquisition, and multi-stage preprocessing, a reliable image foundation is laid for subsequent analysis. Specifically, step S11 involves evenly spreading the fibrous samples on a backlit platform to ensure constant illumination, no overlap, and a uniform background, thus clarifying the sample presentation state. Step S12 involves scanning the samples at a preset frequency to acquire the original image data stream and record visual information. Step S13 involves stitching and recombining the data stream into a complete two-dimensional grayscale image, constructing the raw image data ready for processing. Step S14 employs a Gaussian filtering algorithm, using a preset kernel function to weighted average the original image pixels and their neighborhoods to suppress random noise, resulting in a preliminary denoised image. Step S15 uses limited contrast adaptive histogram equalization to enhance the local contrast between the fibrous region and the background in the preliminary denoised image, highlighting target features. Step S16 uses median filtering, traversing the enhanced image with a preset-sized sliding window, sorting the grayscale values ​​within the window, and replacing the center pixel with the median value to further smooth residual noise and outliers, ultimately obtaining the preprocessed image data. The entire process forms a complete preprocessing chain, from standardized sample placement and image acquisition to multi-level noise reduction and enhancement, which improves image clarity and target discernibility, and provides quality assurance for subsequent contour extraction and area calculation.

[0051] Step S2: The preprocessed image data is subjected to adaptive threshold segmentation using the maximum inter-class variance method to obtain a binarized image, and the continuous contour information of cigarette stems in the binarized image is extracted using an edge detection algorithm.

[0052] Further, in step S2, the preprocessed image data is subjected to adaptive threshold segmentation using the maximum inter-class variance method to obtain a binarized image, and the continuous contour information of cigarette stems in the binarized image is extracted using an edge detection algorithm. Specifically, this includes the following steps: Step S21: Perform global threshold calculation on the preprocessed image data using the maximum inter-class variance method to obtain the optimal grayscale threshold.

[0053] Preferably, adaptive segmentation threshold calculation can be implemented based on Otsu's maximum inter-class variance method. A grayscale histogram is constructed from the preprocessed image. Calculate the inter-class variance : .

[0054] in, , , The grayscale mean is the global grayscale value, and L is the number of grayscale levels, L=256. This is achieved by iterating through the grayscale values. Solve for the between-class variance The largest optimal threshold .

[0055] It is worth noting that the threshold range is affected by a variety of factors. In image processing, the choice of threshold depends on the grayscale distribution. Cigarette stems are usually dark (low grayscale value) and the background is light (high grayscale value). Therefore, the threshold needs to be set between the two to achieve effective segmentation.

[0056] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0057] Step S22: In the preprocessed image data, pixels with gray values ​​higher than the optimal gray value threshold are classified as target foreground, and pixels with gray values ​​lower than the optimal gray value threshold are classified as background, thus obtaining the initial binarized image.

[0058] Preferably, each pixel of the preprocessed image is iterated over, and if the gray value is greater than the optimal threshold t, it is marked as foreground (gray value = 255); if the gray value is less than or equal to t, it is marked as background (gray value = 0). Step S23: Perform morphological closing operation on the initial binarized image, and obtain the improved binarized image by using the small holes in the cigarette stem area of ​​the initial binarized image through a circular element of a preset radius.

[0059] Preferably, the closing operation fills small holes inside an object while maintaining the overall shape of the object. The expression is A∙B=(A⊕B)⊖B, where A is the initial binary image, B is the structuring element, ⊕ is the dilation operation, and ⊖ is the erosion operation.

[0060] Preferably, the selection of structural elements is generally as follows: Shape: Circular, closer to the target shape, reducing edge distortion.

[0061] Radius: 3 pixels, capable of filling holes with a diameter of ≤5 pixels without blurring the edges of the strands.

[0062] Generation method: The circular structural element is generated using OpenCV's getStructuringElement function.

[0063] Step S24: The gradient magnitude and direction of each pixel in the improved binarized image are calculated using the Canny edge detection algorithm, and the set of cigarette stem edge pixels is extracted by double threshold detection and edge connection.

[0064] Preferably, the Canny edge detection algorithm uses the Sobel operator to calculate the gradient magnitude and direction of the image. The gradient magnitude reflects the edge strength, and the direction reflects the edge direction. Non-maximum suppression is performed along the gradient direction to retain the pixels with the largest local gradient, refine the edges, and remove redundancy. Dual threshold detection can be set to a high threshold (150) and a low threshold (50) to classify pixels into strong edges (>150), weak edges (50 to 150), and non-edges (<50). Strong edge pixels are retained, and weak edge pixels are retained if they are adjacent to strong edges to form continuous edges.

[0065] Step S25: Traverse the set of cigarette stem edge pixels using a contour tracking algorithm and serialize the interconnected edge pixels to identify and separate the complete closed contour of each cigarette stem in the set of cigarette stem edge pixels, thereby obtaining continuous contour information.

[0066] Preferably, the contour tracking algorithm can adopt the Moore-Neighbor Tracing algorithm, which starts from the edge pixels and tracks the closed contour in a counterclockwise direction, and can effectively handle contours with complex shapes.

[0067] Specifically, the Moore neighborhood tracking algorithm works as follows: ① Traverse the edge pixels of the improved binary image and find the unvisited strong edge pixels as the starting point.

[0068] ② Search for the next edge pixel in a counter-clockwise direction (Moore neighborhood order: right → bottom right → bottom → bottom left → left → top left → top right).

[0069] ③ Add the found pixels to the contour list and mark them as visited.

[0070] ④ Repeat steps ② to ③ until you return to the starting point and form a closed contour.

[0071] ⑤ Filter all closed contours (area ≥ 500 pixels) 2 To eliminate noise; perimeter / area ratio ≤ 0.3 to eliminate slender pseudo-profiles.

[0072] Preferably, each closed contour should include a set of contour points (coordinates stored in sequence); area (number of pixels within the contour × pixel resolution); perimeter (sum of distances between contour points); and minimum bounding rectangle (used for subsequent feature extraction).

[0073] Beneficial effects of steps S21 to S25: Accurate acquisition of the morphological boundaries of cigarette stems is achieved through adaptive segmentation, binarization optimization, edge extraction, and contour tracking. Specifically, step S21 uses the Otsu's method to calculate the optimal grayscale threshold of the preprocessed image and performs adaptive segmentation based on the image's own grayscale distribution characteristics, providing a basis for distinguishing the target from the background. Step S22 categorizes pixels according to the threshold, with pixels above the threshold representing the target foreground and those below representing the background, generating an initial binarized image and clarifying the basic range of the stem region. Step S23 performs morphological closing operations on the initial binarized image, filling small holes in the stem region with circular elements of a preset radius to improve image connectivity, resulting in an improved binarized image. Step S24 uses the Canny edge detection algorithm to calculate the gradient magnitude and direction of each pixel in the image, and extracts the set of cigarette stem edge pixels through double threshold detection and edge connection, preserving key contour information. Step S25 uses a contour tracking algorithm to traverse the edge pixel set, serialize the connected pixels, identify and separate the complete closed contour of each stem, obtaining continuous contour information. The entire process forms a complete chain from threshold determination and binarization optimization to edge extraction and contour separation, providing an accurate morphological boundary basis for subsequent calculation of the area of ​​a single filament and accumulation of the total surface area, thereby improving the reliability of visual features for weight estimation.

[0074] Step S3: Based on the continuous contour information, calculate the area feature of each cigarette stem using the pixel counting method, and sum the area features of all cigarette stems to obtain the total area data of the cigarette stems.

[0075] Further, step S3 involves calculating the area features of each cigarette stem filament based on continuous contour information using a pixel counting method, and then summing the area features of all cigarette stem filaments to obtain the total area data of the cigarette stem filaments. This specifically includes the following steps: Step S31: Calculate the geometric moments of each complete closed contour in the continuous contour information, and obtain the minimum bounding rectangle of each complete closed contour. The minimum bounding rectangle is the length and width features of the corresponding cigarette stem.

[0076] Preferably, the minimum enclosing rectangle (MER) is the rectangle that completely contains the contour and has the smallest area, and its orientation can be determined by principal component analysis (PCA) of the contour.

[0077] The algorithm uses OpenCV's minAreaRect() function, which returns the center coordinates, width, height, and rotation angle of the rotated rectangle; for the i-th contour C i minAreaRect(C i Returns a RotatedRect object, including the following metrics: ①center: The coordinates of the center of the rectangle, which are consistent with the centroid used in the calculation of geometric moments.

[0078] ②size: The width w and height h of the rectangle, where w ≥ h.

[0079] ③angle: The rotation angle of the rectangle relative to the x-axis, ranging from −90° to 0°.

[0080] Feature assignment: The width w of the rectangle is used as the length feature of the stem, and the height h is used as the width feature. Since the stems are mostly long and thin, w is usually greater than h.

[0081] Step S32: Based on the continuous contour information, the total number of pixels contained in each complete closed contour is calculated using a pixel filling algorithm, and the total number of pixels is converted into physical area by combining the pixel resolution of the binarized image to obtain the area features of each cigarette stem.

[0082] Preferably, the pixel filling algorithm can be a scanline filling algorithm, which traverses the pixels in the contour row by row and quickly fills continuous pixel segments by maintaining an active edge table. The specific implementation steps are as follows: select an unfilled pixel in the contour as a seed point (such as the centroid); expand to the left and right along the row where the seed point is located to find continuous unfilled pixel segments; repeat the previous step for the rows above and below the pixel segment until all rows have been processed.

[0083] For example, the standard template area is 100mm. 2 If the pixel area is 2000, then the pixel resolution is 0.05mm.2 / pixel, the pixel area of ​​a certain wire is 1500, and the pixel resolution is 0.05mm. 2 If the pixel is 0.05, then its physical area is 1500 × 0.05 = 75 mm². 2 .

[0084] Step S33: Accumulate the area features of all cigarette stems to obtain the total area data of cigarette stems.

[0085] For example, a sample contains 3 filaments with physical areas of 60 mm². 2 80mm 2 50mm 2 The total area is 60 + 80 + 50 = 190 mm² 2 .

[0086] Beneficial effects of steps S31 to S33: The quantitative extraction of cigarette stem area features is achieved through geometric moment calculation, pixel filling, and accumulation operations. Specifically, step S31 calculates the geometric moment of each closed contour in a continuous contour to obtain the corresponding minimum bounding rectangle, clarifying the length and width features of a single stem and providing geometric attribute references for area calculation. Step S32, based on the contour information, uses a pixel filling algorithm to count the total number of pixels inside each closed contour, and combines this with the pixel resolution of the binarized image to convert the pixel count into physical area, obtaining the area features of each stem and ensuring that area quantification is based on the actual contour range. Step S33 accumulates the area features of all single stems to form the total area data of cigarette stems. Overall, the algorithm objectively processes the contour information, transforming the visual form into an accumulative area value, establishing a correlation between area and weight for subsequent weight estimation, improving the accuracy and consistency of area data, and reducing human measurement errors.

[0087] Step S4: Input the total area data of cigarette stems into the pre-trained support vector regression model, and calculate the initial weight value of cigarette stems through the nonlinear mapping function of the support vector regression model.

[0088] Further, in step S4, the total area data of cigarette stems is input into a pre-trained support vector regression model, and the initial weight value of cigarette stems is calculated through the nonlinear mapping function of the support vector regression model. This specifically includes the following steps: Step S41: Train the support vector regression model using the sequence minimum optimization algorithm with a preset historical dataset to obtain the pre-trained support vector regression model.

[0089] Preferably, step S41 is designed to train a support vector regression (SVR) model using the Sequence Minimum Optimization (SMO) algorithm to establish a mapping relationship between area features and weight.

[0090] The SVR quadratic programming problem is decomposed into multiple subproblems, with two Lagrange multipliers selected for optimization at each step until convergence. The penalty factor C, ranging from C∈[0.1,1000], can be set to C=100 to balance model complexity and error tolerance. The RBF kernel function parameter γ=0.1 is determined through cross-validation to control the width of the feature map. The ϵ threshold can be set to ϵ=0.1 to define the tolerance range of the insensitive loss function. An example of the training process is shown in the following code block: from sklearn.svm import SVR from sklearn.model_selection import GridSearchCV # Data preparation, let X_train be the area feature and y_train be the weight label param_grid = {'C': [0.1, 10, 100],'gamma': [0.01, 0.1, 1],'epsilon':[0.05, 0.1]} grid = GridSearchCV(SVR(kernel='rbf'), param_grid, cv=5, scoring='neg_mean_squared_error') grid.fit(X_train_scaled, y_train) best_model = grid.best_estimator_ # Optimal model Step S42: Input the total area data of cigarette stems into the pre-trained support vector regression model, and perform nonlinear mapping on the total area data of cigarette stems through the radial basis kernel function of the support vector regression model to obtain a high-dimensional feature vector.

[0091] Preferably, the radial basis function (RBF kernel function) is: ,in, This refers to the total area of ​​cigarette stems, i.e., area characteristics. This represents the i-th support vector in the pre-trained Support Vector Regression (SVR) model, i.e., the total area data of the i-th key sample selected in the training set. γ is the kernel width parameter, γ=0.1 to control the rate of similarity decay between samples. During the mapping process, the input area feature x (scalar) is mapped by the RBF kernel, generating a high-dimensional feature vector. .

[0092] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0093] Step S43: Calculate the similarity between the high-dimensional feature vector and the support vector in the support vector regression model, and combine the Lagrange multiplier coefficients to obtain the weighted contribution value.

[0094] Preferably, area features With support vectors The similarity is ,in, Data on the total area of ​​cigarette stems The high-dimensional feature vector, The high-dimensional feature vector generated after mapping the i-th support vector with the RBF kernel.

[0095] It is worth noting that, and All vectors are implicitly high-dimensional, requiring no explicit expansion (to avoid the curse of dimensionality), and participate in computation indirectly only through kernel functions. This kernel technique is key to SVR's handling of nonlinear problems, enabling it to capture complex nonlinear relationships in the data while maintaining computational efficiency.

[0096] Preferably, the weighted contribution is determined by the Lagrange multipliers. With error Jointly determine the weight , The weighted contribution value is .in, To suppress the influence of distant samples, the sign of the weights is determined by the error direction; positive error samples enhance the contribution, while negative errors suppress it.

[0097] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0098] Step S44: Sum all weighted contribution values ​​and add bias term parameters to obtain the initial cigarette stem weight value.

[0099] Preferably, the bias can be adjusted using the mean error of the training set. : Where N is the total number of samples in the training set, i is the i-th training sample, and y iLet M be the true weight label of the i-th training sample, M be the number of support vectors (the number of "key samples" selected by the SVR model from the training set, usually much smaller than N), j be the j-th support vector, and α be the true weight label of the i-th training sample. j Let y be the Lagrange multiplier coefficient corresponding to the j-th support vector. j Let x be the true weight label corresponding to the j-th support vector. j Let x be the input feature of the j-th support vector. i Let K(x) be the input feature of the i-th training sample. j ,x i Let be the radial basis function (RBF), and let x be the support vector x. j With the i-th training sample x i The similarity.

[0100] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0101] Beneficial effects of steps S41 to S44: By employing model training, nonlinear mapping, and weighted fusion, the correlation between the total area and weight of cigarette stems is established, and an initial estimate is output. Specifically, step S41 trains a support vector regression model using a sequential minimum optimization algorithm, obtaining a pre-trained model as a mapping tool; step S42 inputs the total stem area data into the model, extending it to a high-dimensional feature space through nonlinear mapping using the radial basis function kernel function, capturing the complex relationship between area and weight, and generating a high-dimensional feature vector; step S43 calculates the similarity between the high-dimensional feature vector and the model's support vectors, and combines Lagrange multipliers to evaluate the contribution of each support vector to the current input, obtaining a weighted contribution value; step S44 sums all weighted contribution values ​​and adds a bias term parameter, completing the initial transformation from area to weight, and outputting an initial estimate of the cigarette stem weight. Overall, relying on the nonlinear fitting capability of the support vector regression model, visually quantified area features are transformed into weight estimates, providing a foundational numerical basis for subsequent normalization and filtering processes, improving the objectivity and automation of the estimation.

[0102] Step S5: Normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value.

[0103] Further, step S5 involves normalizing the initial cigarette stem weight value to obtain a standardized cigarette stem weight value, specifically including the following steps: Step S51: Based on the global minimum and global maximum values ​​of stem weight in historical batches, the initial cigarette stem weight value is linearly normalized using Min-Max standardization to obtain the normalized weight value.

[0104] Preferably, the global minimum / maximum value can be obtained by taking the extreme value of the weight values ​​of historical batches (such as production data of the past 12 months).

[0105] Step S52: Define a sliding window buffer that maintains the normalized weight values ​​of the most recent several consecutive batches, and input the normalized weight values ​​into the sliding window buffer to form a time-series data stream.

[0106] Preferably, the window capacity of the sliding window is a preset value (e.g., 10, i.e., retaining the 10 most recent batches); the first-in-first-out (FIFO) principle is adopted, and when a new batch of data enters, the oldest batch of data is removed to keep the data in the window always up-to-date; the data in the window are arranged in batch order to form a time series.

[0107] Preferably, the window size can be further determined based on the production rhythm and data stability. For example, cigarette production is usually done in shifts, with each shift lasting 8 hours. If short-term fluctuations need to be reflected, 10 can be used, which is the data from the most recent 10 shifts; if long-term trends need to be reflected, 30 can be used, which is the data from the most recent 30 shifts.

[0108] Preferably, the buffer can be a circular queue or a deque, ensuring that the time complexity of insertion and deletion operations is O(1).

[0109] Step S53: The normalized weight value of the current batch is calculated by weighting the normalized weight value of the current batch with a preset smoothing factor using an exponentially weighted moving average to obtain the standardized cigarette stem weight value.

[0110] Preferably, the exponentially weighted moving average is used to assign higher weights to recent data and lower weights to long-term data, with the weights decreasing exponentially over time. The smoothing factor of the exponentially weighted moving average can be adjusted according to the data volatility characteristics. If the data fluctuates greatly, such as the weight of the stems being greatly affected by the raw materials, a factor of 0.3 can be used; if the data is relatively stable, such as a mature production process, a factor of 0.1 can be used.

[0111] Beneficial effects of steps S51 to S53: Through linear normalization, temporal buffering, and dynamic smoothing, the predicted stem weight value is transformed into a standardized value with uniform scale and stable fluctuations. Specifically, step S51 uses the Min-Max normalization algorithm to linearly map the predicted weight value based on the global minimum and maximum values ​​of historical batch stem weight values, compressing it into a fixed interval and eliminating dimensional differences between different batches to obtain a normalized weight value. Step S52 defines a sliding window buffer to maintain the normalized weight values ​​of the most recent consecutive batches, inputting the current normalized weight value into the buffer to form a time-series data stream arranged in chronological order, providing a data foundation for capturing short-term trends. Step S53 uses an exponentially weighted moving average algorithm to weight the current batch's normalized weight value with a preset smoothing factor, giving higher weight to recent data and suppressing the influence of random fluctuations to obtain a standardized cigarette stem weight value. Overall, through a progressive processing approach of first unifying the scale, then accumulating time series data, and finally smoothing fluctuations, the initial predicted value is transformed into an input more suitable for dynamic state estimation, improving the stability of subsequent processing.

[0112] Step S6: The standardized cigarette stem weight value is dynamically estimated and noise is filtered out using the Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

[0113] Further, in step S6, the standardized cigarette stem weight value is dynamically estimated and noise filtered using the Kalman filter algorithm to obtain the final cigarette stem weight calculation result, which specifically includes the following steps: Step S61: Configure the state transition matrix and observation matrix of the Kalman filter, and calibrate the process noise and observation noise covariance matrix by giving several historical batches of standardized stem weight values.

[0114] Preferably, the state vector includes the standardized weight value of the current batch and its first-order rate of change: ,in, Let [the weight] be the standardized weight of the kth batch, ranging from [0,1]. The rate of change of weight. .

[0115] Preferably, the state transition matrix F is used to describe the evolution of the state over time: ,in, It is the batch number, and the time interval is fixed.

[0116] Preferably, the observation matrix H is set to only observe weight values ​​and cannot directly measure the rate of change: .

[0117] Preferably, the noise covariance can be calculated from the historical batch weight fluctuation variance: ,in, This represents the variance in weight fluctuation.

[0118] Preferably, the observation noise covariance can be determined through sensor accuracy calibration experiments to reflect the sensor measurement error. For example, if the sensor measurement error is 0.005, then the observation noise covariance is 0.005. 2 .

[0119] It should be noted that the meaning of the formula symbols in this embodiment only applies to the steps they explain. The meanings of the formula symbols for other steps are not interchangeable. Although formula symbols may appear similar, they are not interchangeable because the steps they explain are different.

[0120] Step S62: Input the standardized filament weight value of the current batch into the Kalman filter, and use the optimal state estimate of the previous batch of the Kalman filter as the prior state to calculate the state prior estimate and covariance prior of the current batch.

[0121] Preferably, step S62 can directly call the Python numpy package, for example: import numpy as np def kalman_predict(x_prev, P_prev, F, Q): """ Kalman filter prediction steps (step S62) parameter: x_prev: Previous batch of optimal state estimates (2×1 vector, [weight, rate of change]) P_prev: Covariance matrix of the previous batch (2×2 matrix) F: State transition matrix (2×2 matrix) Q: Process noise covariance matrix (2×2 matrix) return: x_prior: Prior estimate of the current batch state (2×1 vector) P_prior: Covariance prior for the current batch (2×2 matrix) """ # State prior estimation: x_prior = F · x_prev x_prior = F @ x_prev # @ indicates matrix multiplication # Covariance Prior: P_prior = F · P_prev · F^T + Q P_prior = F @ P_prev @ FT + Q # .T represents matrix transpose return x_prior, P_prior Step S63: Calculate the Kalman gain based on the prior covariance of the current batch and the covariance of the observation noise.

[0122] Preferably, step S63 can also directly call the Python numpy package, for example: import numpy as np def calculate_kalman_gain(P_prior, H, R): """ Kalman gain calculation (step S63) parameter: P_prior: The covariance prior (2×2 matrix) output from step S62. H: Observation matrix (1×2 matrix) R: Observation noise covariance matrix (1×1 matrix) return: K: Kalman gain matrix (2×1 matrix) """ # Step 1: Calculate S = H·P_prior·H^T + R H_P_prior = H @ P_prior # 1×2 matrix H_P_prior_H_T = H_P_prior @ HT # 1×1 matrix (scalar) S = H_P_prior_H_T + R # 1×1 matrix # Step 2: Calculate the Kalman gain K = P_prior·H^T·S^{-1} H_T = HT # 2×1 matrix (transpose of H) P_prior_H_T = P_prior @ H_T # 2×1 matrix K = P_prior_H_T @ np.linalg.inv(S) # 2×1 matrix (matrix multiplication: (2×1)×(1×1)=2×1) return K Step S64: The Kalman gain is linearly weighted and fused with the prior estimate of the current batch state and the observed values ​​to obtain the posterior state estimate of the current batch, which is the final calculation result of the cigarette stem weight.

[0123] Preferably, step S64 can also directly call the Python numpy package, for example: import numpy as np def kalman_update(x_prior, P_prior, K, z_k, H): """ Kalman filter update steps (step S64) parameter: x_prior: The state prior estimate output from step S62 (2×1 vector, [weight, rate of change]) P_prior: The covariance prior (2×2 matrix) output from step S62. K: Kalman gain (2×1 matrix) output from step S63. z_k: Current batch observations (normalized weight values, from step S53) H: Observation matrix (1×2 matrix, [[1,0]]) return: x_post: Posterior state estimate (2×1 vector, including final weight) P_post: Posterior covariance matrix (2×2 matrix) final_weight: Final weight of cigarette stems (normalized value, x_post[0]) """ # Step 1: Calculate the observation residual (actual observation - predicted observation) z_pred = H @ x_prior # Predict the observation (scalar, H·x_prior) residual = z_k - z_pred # Residual (scalar) # Step 2: Linear weighted fusion to calculate the posterior state estimate (core formula) x_post = x_prior + K * residual # Broadcast operation: 2×1 matrix + (2×1 matrix × scalar) # Step 3: Update the posterior covariance (for the next round of prediction) I = np.eye(2) # 2×2 identity matrix P_post = (I - K @ H) @ P_prior # Matrix multiplication: (2×2)×(2×2) # Extract the final weight (normalized value) final_weight = x_post[0] return x_post, P_post, final_weight Beneficial effects of steps S61 to S64: By configuring filter parameters, dynamically calculating prior states, determining gains, and fusing estimates, dynamic state estimation and noise filtering of standardized stem weight values ​​are achieved, resulting in stable output. Specifically, step S61 configures the state transition matrix and observation matrix of the Kalman filter, using historical batch standardized weight values ​​to calibrate the process noise and observation noise covariance matrix, clarifying the system's dynamic characteristics and observation uncertainties. Step S62 inputs the current batch standardized weight value into the filter, using the optimal state estimate from the previous batch as a starting point, calculating the current state prior estimate and covariance prior to reflect the predicted state and uncertainty. Step S63 calculates the Kalman gain based on the current covariance prior and the observation noise covariance, balancing the trust weights of prediction and observation. Step S64 uses the Kalman gain to linearly weight and fuse the current prior estimate and observation values ​​to obtain the posterior state estimate, i.e., the final weight calculation result. Overall, through parameter configuration laying the foundation, prior calculation predicting the state, gain adjustment and trust allocation, and fusing and optimizing estimates, random noise is effectively filtered out, adapting to dynamic changes in weight values, improving the consistency and reliability of the results, and providing a stable output for weight calculation.

[0124] Beneficial effects of steps S1 to S6: The system achieves automated estimation of cigarette stem weight through systematic image processing and data modeling. Step S1 preprocesses the original image using Gaussian filtering for noise reduction, improving the image quality foundation for subsequent analysis. Step S2 uses Otsu's method for segmentation and edge detection to extract the continuous contours of the stems, clarifying their morphological boundaries. Step S3 calculates the area of ​​each stem using pixel counting and sums them to obtain the total area, quantifying visual features. Step S4 inputs the total area into a pre-trained support vector regression model, and obtains an initial weight estimate through nonlinear mapping, establishing the correlation between area and weight. Step S5 normalizes the initial estimate to unify the data scale. Step S6 uses Kalman filtering for dynamic estimation and noise removal to optimize estimation stability, finally outputting the calculated weight. These interconnected steps form a complete chain from image acquisition to weight output, reducing manual intervention and relying on objective algorithmic processing to improve the accuracy and consistency of the estimation.

[0125] like Figure 2 As shown, this embodiment provides an example of a weight calculation device for cigarette stems. In this embodiment, the weight calculation device is applied to the weight calculation method as described in the above embodiment.

[0126] Specifically, the weight calculation device includes a cigarette stem image data acquisition module 1, a cigarette stem image contour extraction module 2, a cigarette stem total area acquisition module 3, an initial cigarette stem weight value calculation module 4, a cigarette stem weight value normalization module 5, and a cigarette stem weight value calibration module 6, which are electrically or signalally connected in sequence.

[0127] The module 1, which acquires cigarette stem image data, uses an external linear array scanning device to collect the original image data of the cigarette stem sample to be tested. It then performs noise reduction preprocessing on the original image data using a Gaussian filtering algorithm to obtain preprocessed image data. The module 2, which extracts the contour of the cigarette stem image, performs adaptive threshold segmentation on the preprocessed image data using the maximum inter-class variance method to obtain a binarized image. It then extracts the continuous contour information of the cigarette stems in the binarized image using an edge detection algorithm. The module 3, which acquires the total area of ​​the cigarette stems, calculates the area features of each cigarette stem based on the continuous contour information using a pixel counting method, and accumulates the total area. The total area of ​​cigarette stems is obtained by adding the area features of all cigarette stems. The initial cigarette stem weight calculation module 4 is used to input the total area data of cigarette stems into a pre-trained support vector regression model, and calculate the initial cigarette stem weight value through the nonlinear mapping function of the support vector regression model. The cigarette stem weight normalization module 5 is used to normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value. The cigarette stem weight calibration module 6 is used to perform dynamic state estimation and noise filtering on the standardized cigarette stem weight value through the Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

[0128] It should be noted that this embodiment is a functional module embodiment based on the above method embodiment. For additional content such as extensions, optimizations, limitations, examples, principle explanations, and beneficial effects of this embodiment, please refer to the above embodiments. This embodiment will not repeat them here.

[0129] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Figure 3 As shown, the electronic device 7 includes a processor 71 and a memory 72 coupled to the processor 71.

[0130] The memory 72 stores program instructions for implementing the federated learning-based collaborative energy-saving method for government data clusters in any of the above embodiments.

[0131] The processor 71 is used to execute program instructions stored in the memory 72 for collaborative energy saving of government data clusters based on federated learning.

[0132] The processor 71 can also be referred to as a CPU (Central Processing Unit). The processor 71 may be an integrated circuit chip with signal processing capabilities. The processor 71 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor.

[0133] Furthermore, Figure 4 This is a schematic diagram of the structure of a storage medium according to an embodiment of this application. See also: Figure 4 In this embodiment of the application, the storage medium 8 stores program instructions 81 capable of implementing all the above methods. These program instructions 81 can be stored in the storage medium in the form of a software product, including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, or terminal devices such as computers, servers, mobile phones, and tablets.

[0134] In the several embodiments provided in this application, it should be understood that the disclosed systems (apparatus), systems, and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of systems or units may be electrical, mechanical, signal, or other forms.

[0135] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units. The above are merely embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made based on the description and drawings of this application, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for calculating the weight of cigarette stems, wherein the weight calculation method is applied to a sample of cigarette stems to be tested, characterized in that, The weight calculation method includes: Step S1: Acquire the original image data of the cigarette stem sample to be tested using an external linear array scanning device, and perform noise reduction preprocessing on the original image data using a Gaussian filtering algorithm to obtain preprocessed image data; Step S2: The preprocessed image data is subjected to adaptive threshold segmentation using the maximum inter-class variance method to obtain a binarized image, and the continuous contour information of cigarette stems in the binarized image is extracted using an edge detection algorithm. Step S3: Based on the continuous contour information, calculate the area feature of each cigarette stem using the pixel counting method, and sum the area features of all cigarette stems to obtain the total area data of the cigarette stems. Step S4: Input the total area data of the cigarette stems into the pre-trained support vector regression model, and calculate the initial weight value of the cigarette stems through the nonlinear mapping function of the support vector regression model. Step S5: Normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value. Step S6: The standardized cigarette stem weight value is dynamically estimated and noise is filtered out using the Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

2. The weight calculation method according to claim 1, characterized in that, Step S1: Acquire the original image data of the cigarette stem sample to be tested using an external linear array scanning device, and perform noise reduction preprocessing on the original image data using a Gaussian filtering algorithm to obtain preprocessed image data, including: Step S11: The cigarette stem sample to be tested is evenly laid on a backlight scanning platform with constant illumination conditions, no sample overlap, and uniform background. Step S12: Scan the cigarette stem sample to be tested on the backlight scanning platform with an external linear array scanning device at a preset sampling frequency to obtain the original image data stream; Step S13: The original image data stream is spliced ​​and reassembled to obtain a complete two-dimensional grayscale image, i.e., the original image data; Step S14: The weighted average of each pixel and its neighboring pixels in the original image data is obtained by using the preset Gaussian kernel function of the Gaussian filtering algorithm to obtain preliminary denoised image data. Step S15: Enhance the local contrast between the cigarette stem region and the background region in the preliminary denoised image data using a limited contrast adaptive histogram equalization algorithm to obtain enhanced image data; Step S16: The enhanced image data is traversed through a sliding window of a preset size using a median filtering algorithm to sort the gray values ​​of all pixels within the sliding window, and the gray value of the center pixel of the window is replaced with the median of the sorted gray values ​​to obtain the preprocessed image data.

3. The weight calculation method according to claim 1, characterized in that, Step S2 involves performing adaptive threshold segmentation on the preprocessed image data using the maximum inter-class variance method to obtain a binarized image, and then extracting the continuous contour information of cigarette stems in the binarized image using an edge detection algorithm, including: Step S21: Perform global threshold calculation on the preprocessed image data using the maximum inter-class variance method to obtain the optimal grayscale threshold; Step S22: In the preprocessed image data, pixels with gray values ​​higher than the optimal gray value threshold are classified as target foreground, and pixels with gray values ​​lower than the optimal gray value threshold are classified as background, to obtain an initial binarized image; Step S23: Perform morphological closing operation on the initial binarized image, and obtain the improved binarized image by using circular elements of a preset radius to detect the small holes in the cigarette stem area of ​​the initial binarized image. Step S24: Calculate the gradient magnitude and direction of each pixel in the improved binarized image using the Canny edge detection algorithm, and extract the set of cigarette stem edge pixels through double threshold detection and edge connection. Step S25: Traverse the set of cigarette stem edge pixels using a contour tracking algorithm and serialize the interconnected edge pixels to identify and separate the complete closed contour of each cigarette stem in the set of cigarette stem edge pixels, thereby obtaining continuous contour information.

4. The weight calculation method according to claim 1, characterized in that, Step S3: Based on the continuous contour information, calculate the area feature of each cigarette stem using a pixel counting method, and sum the area features of all cigarette stems to obtain the total area data of the cigarette stems, including: Step S31: Calculate the geometric moments of each complete closed contour in the continuous contour information, and obtain the minimum bounding rectangle of each complete closed contour. The minimum bounding rectangle is the length and width features of the corresponding cigarette stem. Step S32: Based on the continuous contour information, calculate the total number of pixels contained in each complete closed contour using a pixel filling algorithm, and convert the total number of pixels into physical area by combining the pixel resolution of the binarized image to obtain the area feature of each cigarette stem. Step S33: Accumulate the area features of all cigarette stems to obtain the total area data of cigarette stems.

5. The weight calculation method according to claim 1, characterized in that, Step S4: Input the total area data of the cigarette stems into a pre-trained support vector regression model, and calculate the initial weight value of the cigarette stems using the nonlinear mapping function of the support vector regression model, including: Step S41: Train the support vector regression model using the sequence minimum optimization algorithm with a preset historical dataset to obtain the pre-trained support vector regression model; Step S42: Input the total area data of the cigarette stems into the pre-trained support vector regression model, and perform nonlinear mapping on the total area data of the cigarette stems through the radial basis kernel function of the support vector regression model to obtain a high-dimensional feature vector; Step S43: Calculate the similarity between the high-dimensional feature vector and the support vector in the support vector regression model, and obtain the weighted contribution value by combining the Lagrange multiplier coefficients. Step S44: Sum all weighted contribution values ​​and add bias term parameters to obtain the initial cigarette stem weight value.

6. The weight calculation method according to claim 1, characterized in that, Step S5, normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value, including: Step S51: Based on the global minimum and global maximum values ​​of stem weight in historical batches, the initial cigarette stem weight value is linearly normalized using Min-Max standardization to obtain the normalized weight value. Step S52: Define a sliding window buffer that maintains the normalized weight values ​​of the most recent several consecutive batches, and input the normalized weight values ​​into the sliding window buffer to form a time-series data stream; Step S53: The normalized weight value of the current batch is calculated by weighting the normalized weight value of the current batch with a preset smoothing factor using an exponentially weighted moving average to obtain the standardized cigarette stem weight value.

7. The weight calculation method according to claim 1, characterized in that, Step S6: The standardized cigarette stem weight value is dynamically estimated and noise filtered using a Kalman filter algorithm to obtain the final cigarette stem weight calculation result, including: Step S61: Configure the state transition matrix and observation matrix of the Kalman filter, and calibrate the process noise and observation noise covariance matrix using standardized stem weight values ​​from several historical batches. Step S62: Input the standardized stem weight value of the current batch into the Kalman filter, and use the optimal state estimate of the previous batch of the Kalman filter as the prior state to calculate the state prior estimate and covariance prior of the current batch. Step S63: Calculate the Kalman gain based on the prior covariance of the current batch and the covariance of the observation noise; Step S64: The Kalman gain is linearly weighted and fused with the prior estimate of the current batch state and the observed value to obtain the posterior state estimate of the current batch, which is the final calculation result of the cigarette stem weight.

8. A weight calculation device for cigarette stems, wherein the weight calculation device is applied to the weight calculation method as described in any one of claims 1 to 7, characterized in that, The weight calculation device includes: The cigarette stem image data acquisition module is used to acquire the original image data of the cigarette stem sample to be tested through an external linear array scanning device, and to perform noise reduction preprocessing on the original image data through a Gaussian filtering algorithm to obtain preprocessed image data. The cigarette stem image contour extraction module is used to perform adaptive threshold segmentation on the preprocessed image data using the maximum inter-class variance method to obtain a binarized image, and to extract the continuous contour information of the cigarette stems in the binarized image using an edge detection algorithm. The total area acquisition module for cigarette stems is used to calculate the area features of each cigarette stem based on the continuous contour information using a pixel counting method, and to accumulate the area features of all cigarette stems to obtain the total area data of the cigarette stems. The initial cigarette stem weight calculation module is used to input the total area data of the cigarette stems into a pre-trained support vector regression model, and calculate the initial cigarette stem weight value through the nonlinear mapping function of the support vector regression model. The cigarette stem weight normalization module is used to normalize the initial cigarette stem weight value to obtain a standardized cigarette stem weight value. The cigarette stem weight calibration module is used to perform dynamic state estimation and noise filtering on the standardized cigarette stem weight value using a Kalman filter algorithm to obtain the final cigarette stem weight calculation result.

9. An electronic device, characterized in that, The method includes a processor and a memory coupled to the processor, the memory storing program instructions executable by the processor; when the processor executes the program instructions stored in the memory, it implements the weight calculation method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program instructions that, when executed by a processor, enable the weight calculation method as described in any one of claims 1 to 7.