Non-contact detection method and system for straw moisture content based on near-infrared hyperspectrum
By combining near-infrared hyperspectral technology with multi-source data processing, the accuracy and stability issues of straw moisture content detection in complex environments have been resolved, enabling real-time and accurate detection in loose straw scenarios.
Patent Information
- Application Number
- CN202610013181.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-07
- Publication Date
- 2026-03-17
- Estimated Expiration
- 2046-01-07
AI Technical Summary
Existing straw moisture content detection technologies have unstable detection accuracy in loose pile scenarios, making it difficult to maintain reliability in complex environments, and traditional methods cannot achieve real-time and accurate batch detection.
A non-contact detection method based on near-infrared hyperspectral imaging is adopted, which combines a hyperspectral camera, temperature and humidity sensor, light sensor and laser rangefinder to acquire multi-source data. Moisture content is predicted through feature extraction subnetwork, attention fusion subnetwork and multi-scale regression output module, and weighted correction is performed using environmental parameters and basic straw information.
It improves the stability and cross-scenario consistency of straw moisture content detection, enables reliable detection under non-uniform stacking and environmental change conditions, and enhances the volume representativeness of the detection results.
Smart Images

Figure CN121453710B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of moisture content detection technology, and in particular to a non-contact method and system for detecting straw moisture content based on near-infrared hyperspectral imaging. Background Technology
[0002] Straw moisture content is a key indicator affecting straw return efficiency, feed quality, and biomass energy conversion performance. Its detection methods have long relied on drying and portable moisture meters. While drying yields relatively accurate results, its long testing cycle cannot meet the needs of on-site batch processing, and it cannot provide real-time feedback on material conditions. Portable measurement methods suffer from insufficient sample representativeness in bulk material scenarios, and the test results fluctuate significantly between different batches, making them unsuitable for quality control under continuous operating conditions.
[0003] Near-infrared reflective detection devices, which have emerged in recent years, enable non-contact measurement. However, their detection accuracy in loosely stacked straw scenarios is unstable, and the consistency of predicted values under different stacking patterns is poor. Some near-infrared devices are based on fixed-band measurements, making it difficult to accurately determine areas of non-uniform stacking, resulting in significant spatial deviations in the detection results. Furthermore, existing spectral detection devices are prone to cross-batch model failures in complex environments, causing detection results to drift with changes in the scene, making it difficult for the detection equipment to maintain long-term reliability in actual production.
[0004] To address the above issues, this application presents a non-contact detection method and system for straw moisture content based on near-infrared hyperspectral imaging. Summary of the Invention
[0005] The technical problem this application aims to solve is to address the shortcomings of existing technologies by providing a non-contact method and system for detecting straw moisture content based on near-infrared hyperspectral imaging. This method acquires straw hyperspectral data within a preset spectral range using a hyperspectral camera, and simultaneously collects environmental parameters and stacking density information using temperature and humidity sensors, light sensors, and laser rangefinders. After band clipping, wavelet denoising, and standard normal variable correction, the hyperspectral data, along with normalized environmental parameters and basic straw information, is input into a detection network. The detection network predicts moisture content through a feature extraction subnetwork, an attention fusion subnetwork, and a multi-scale regression output module. When the representativeness score is high, the hyperspectral data and environmental parameters are weighted and corrected based on perturbation spectral differences to improve the matching degree and volumetric representativeness of the multi-source data.
[0006] To achieve the above objectives, this application provides the following technical solution:
[0007] A non-contact method for detecting straw moisture content based on near-infrared hyperspectral imaging is applied to a detection device. The detection device includes a near-infrared hyperspectral imaging device and a processor. The near-infrared hyperspectral imaging device includes a hyperspectral camera, a temperature and humidity sensor, a light sensor, and a laser rangefinder. The method includes:
[0008] Acquire hyperspectral data of straw covering a preset wavelength range, and simultaneously collect environmental parameter data and basic straw information, wherein the basic straw information is the straw stacking density information collected by the laser ranging sensor;
[0009] The hyperspectral data of straw is subjected to band clipping, wavelet denoising and standard normal variable correction to obtain spectral preprocessed data. The environmental parameter data and basic information of straw are normalized and encoded to obtain conditional vectors.
[0010] The spectral preprocessing data and the conditional vector are input as input parameters to a preset detection network. The detection network processes the input parameters to obtain the straw moisture content detection value.
[0011] The hyperspectral data of the straw is subjected to band clipping, wavelet denoising, and standard normal variable correction to obtain spectral preprocessed data, including:
[0012] Select a target band that matches the water absorption from the hyperspectral data within a preset spectral range to obtain target clipped band data;
[0013] The target cropped band data is decomposed into multi-scale wavelet data based on the DB4 wavelet basis. The coefficients are compressed at a preset number of decomposition levels, and then the compressed coefficients are reconstructed by wavelet to obtain denoised spectral data.
[0014] For each spectral vector of the denoised spectral data, standard normal variable correction is performed, including mean centering of the spectral vector and normalization according to the standard deviation, to obtain the spectral preprocessed data.
[0015] The detection network includes a feature extraction subnetwork, an attention fusion subnetwork, and an output module, wherein:
[0016] The feature extraction subnetwork consists of three feature extraction modules, which are used to extract spectral-spatial joint features at three scales from the spectral preprocessing data. Each feature extraction module includes a spectral convolutional layer and a spatial convolutional layer. Each feature extraction module is followed by a residual block, which includes a batch normalization layer and a nonlinear activation layer, used to perform skip connections on the output of the feature extraction module during feature transmission.
[0017] The spectral convolutional layer is configured as a one-dimensional convolution, used to perform convolution operations on the spectral dimension. The kernel size of the one-dimensional convolution is 1×10, and the number of convolutional channels increases progressively in each feature extraction module. The spatial convolutional layer is configured as a two-dimensional convolution, used to perform convolution operations on the spatial dimension corresponding to the spectral preprocessing data. The kernel size of the two-dimensional convolution is 3×3.
[0018] The attention fusion subnetwork is used to perform weighted fusion of the spectral-spatial joint features at the three scales based on environmental parameter data and straw basic information, and output fused features.
[0019] The attention fusion subnetwork includes:
[0020] The query vector generation unit is configured to linearly map the spectral-spatial joint features at three scales output by the three feature extraction modules to generate corresponding query vectors.
[0021] The conditional coding layer is configured to perform fusion mapping on the environmental parameter data and straw basic information to generate key vectors and value vectors for attention calculation;
[0022] The conditional attention calculation layer is configured to perform attention weight calculation based on the query vector, key vector and value vector to obtain weight coefficients for each scale feature, wherein the weight coefficients are used to characterize the confidence level of different spectral regions under the current temperature, humidity and stacking density conditions.
[0023] The feature weighting layer is configured to perform channel-by-channel weighted adjustment of the corresponding spectral-spatial joint features according to the weighting coefficients to obtain fused features.
[0024] The output module includes:
[0025] The first particle size regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the first scale in the fused features, and output the first particle size moisture content detection value for initial screening of straw moisture.
[0026] The second particle size regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the second scale in the fused features, and generate the second particle size moisture content detection value in combination with the straw variety.
[0027] The third granularity regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the third scale in the fused features, so as to output the third granularity moisture content detection value.
[0028] The multi-scale loss weighted branch is configured to calculate the mean square error loss for the first particle size moisture content detection value, the second particle size moisture content detection value, and the third particle size moisture content detection value, and calculate the straw moisture content detection value based on the mean square error loss.
[0029] The near-infrared hyperspectral imaging device further includes an airflow nozzle, and the acquisition of straw hyperspectral data covering a preset wavelength range includes:
[0030] Obtain the static spectrum of straw within the detection area;
[0031] The airflow nozzle is used to agitate the straw to rearrange the surface layer of the straw, and spectral sequences are collected.
[0032] Based on the spectral difference characteristics between the static spectrum and the spectral sequence, a representative score is calculated to characterize the volume of straw piles within the detection area.
[0033] If the representative score is less than or equal to the preset difference threshold, the static spectrum will be used as the straw hyperspectral data;
[0034] If the representative score is greater than the difference threshold, the static spectrum is weighted according to the spectral difference characteristics, and the weighted static spectrum is used as the straw hyperspectral data.
[0035] If the representative score is greater than the difference threshold, the method further includes:
[0036] Collect environmental parameter data and basic information about straw;
[0037] Multiple candidate environmental parameter sets are extracted from the environmental parameter data and basic straw information;
[0038] A spectral feature vector is constructed based on the spectral difference characteristics, and the corresponding matching score is calculated based on the matching correlation between the spectral feature vector and each candidate environmental parameter in the candidate environmental parameter set.
[0039] The matching scores are normalized to obtain the matching weights of each candidate environmental parameter, and the candidate environmental parameter sets are weighted according to the matching weights to obtain environmental parameter data and basic straw information that match the straw hyperspectral data.
[0040] The attention fusion subnetwork also includes:
[0041] The key vector and value vector are scaled according to the matching weights to adjust the attention distribution of the attention fusion subnetwork, wherein the scaling includes:
[0042] Based on the matching weights, a scaling factor matrix corresponding to the key vector and value vector is generated;
[0043] The key vector and value vector are normalized twice based on the scaling factor matrix to generate adjusted key vectors and value vectors that are consistent with the representative scores of the straw hyperspectral data.
[0044] A non-contact straw moisture content detection system based on near-infrared hyperspectral imaging, the system comprising:
[0045] The near-infrared hyperspectral imaging module is configured to acquire hyperspectral data of straw covering a preset wavelength range through a hyperspectral camera, and simultaneously acquire environmental parameter data and basic straw information through a temperature and humidity sensor, a light sensor and a laser rangefinder; the near-infrared hyperspectral imaging module includes an airflow nozzle for perturbing the straw with airflow to acquire spectral sequences and calculate a representative score;
[0046] The multi-source data processing module is configured to perform band clipping, wavelet denoising, and standard normal variable correction on the straw hyperspectral data to form spectral preprocessed data, and generate condition vectors based on environmental parameter data and straw basic information; when the representative score is greater than a preset difference threshold, it calculates matching weights based on multiple candidate environmental parameter sets and generates target environmental parameter data and straw basic information that match the straw hyperspectral data based on the matching weights.
[0047] The moisture content detection module is configured to input the spectral preprocessing data, the target environmental parameter data, and the basic information of straw into a preset detection network, and process them through a feature extraction subnetwork, an attention fusion subnetwork, and an output module to generate a straw moisture content detection value.
[0048] The multi-source data processing module includes:
[0049] The spectral preprocessing unit is configured to perform band clipping, wavelet denoising, and standard normal variable correction on the straw hyperspectral data to generate spectral preprocessed data;
[0050] The condition vector generation unit is configured to normalize and encode the environmental parameter data and the basic information of straw to form an initial condition vector for attention fusion.
[0051] The matching weight calculation unit is configured to calculate the matching weights corresponding to the spectral difference features from multiple candidate environmental parameter sets when the representative score is greater than a preset difference threshold, and generate target environmental parameter data and basic straw information that match the straw hyperspectral data based on the matching weights.
[0052] Compared with the prior art, the beneficial effects of this application are:
[0053] This application employs a collaborative design combining hyperspectral imaging, environmental parameter acquisition, and conditional attention fusion to enable moisture content prediction that simultaneously reflects spectral characteristics and the actual state of the pile, maintaining stable output even under non-uniform stacking and environmental variation conditions. Data self-correction is achieved through representativeness scoring and multi-source matching weights, improving the volume representativeness and cross-scenario consistency of the detection, thereby obtaining more reliable moisture content results in the online detection of loose straw. Attached Figure Description
[0054] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0055] Figure 1 An exemplary application scenario diagram provided for an embodiment of this application;
[0056] Figure 2 This is a schematic diagram of the detection device provided in the embodiments of this application;
[0057] Figure 3 A schematic diagram of a processor module provided in an embodiment of this application;
[0058] Figure 4 A flowchart illustrating the non-contact detection method for straw moisture content based on near-infrared hyperspectral imaging provided in this application embodiment;
[0059] Figure 5 This is a schematic diagram of the detection network provided in an embodiment of this application;
[0060] Figure 6 This is a schematic diagram of the structure of the feature extraction subnetwork provided in the embodiments of this application;
[0061] Figure 7 This is a schematic diagram of another near-infrared hyperspectral imaging device provided in the embodiments of this application. Detailed Implementation
[0062] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0063] The term "embodiment" as used herein 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 separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0064] The non-contact detection method for straw moisture content proposed in this application is mainly aimed at the online quality monitoring needs of crop straw in scenarios such as returning to the field, feed processing, and biomass energy conversion.
[0065] In practical engineering, straw is often stored in bundles, transported in bulk, or temporarily piled up. Moisture content directly affects the rate of decomposition, briquetting strength, fermentation stability, and combustion efficiency. However, traditional testing methods rely heavily on manual sampling and offline drying, which damages samples and fails to cover the entire batch, allowing only post-processing traceability rather than real-time control of the process. Operators at large-scale livestock farm feed production lines, straw baling stations, and biomass power plant raw material pretreatment workshops commonly report the inability to detect moisture content in a timely manner, making it a common bottleneck restricting the high-value utilization of straw resources.
[0066] To improve detection efficiency, existing technologies attempt to introduce portable near-infrared moisture meters or fixed single-point near-infrared sensors to directly measure the reflectance spectrum of straw surfaces. However, as a natural fiber material, straw's components, such as cellulose, hemicellulose, and lignin, exhibit significant near-infrared absorption characteristics. The spectra of straw vary considerably depending on the variety, origin, and harvesting time. Furthermore, the bulk density, impurity content, and lighting conditions of straw in bulk stacking introduce additional spectral distortions. This means that while simple moisture content retrieval methods relying on a few characteristic bands or empirical models may work under laboratory conditions, they often exhibit poor model transferability and require frequent recalibration in complex field or production line environments. Especially under conditions of high-speed conveyor belt transport and dynamically changing stack thickness, single-point near-infrared measurements can only reflect the instantaneous state of a small, shallow area, making it difficult to provide a representative determination of the volume average moisture content of the entire batch of material.
[0067] Near-infrared hyperspectral imaging technology expands the spatial dimension to some extent. By simultaneously acquiring two-dimensional spatial distribution and one-dimensional spectral information, it can more finely characterize the moisture non-uniformity of the stacked surface. However, existing solutions in this field typically treat hyperspectral data as a single-source signal, focusing mainly on spectral preprocessing and regression model selection. External conditions such as ambient temperature and humidity, light intensity, and straw stack density are simply removed as noise factors, failing to be used as prior conditions to describe the detection scenario and explicitly introduce the moisture content inversion process. As the detection scenario shifts in time and space, the model's sensitivity to these implicit conditions is amplified as prediction bias. This results in significant differences in the application effects of the same model on summer wheat straw, autumn corn straw, and different regions, increasing maintenance costs and the barrier to entry for use.
[0068] On the other hand, under non-contact detection conditions, hyperspectral cameras can usually only image the surface of the straw pile from a certain distance and angle, and the moisture distribution inside the pile can only be indirectly inferred through limited surface responses.
[0069] Those skilled in the art will understand that variations in stacking morphology, localized peaks, or pits can lead to significant differences in the representativeness of point clouds and spectral information in different regions within the same image. However, existing methods mostly avoid severely occluded areas through simple region cropping or masking, lacking a systematic solution that can quantitatively assess the volumetric representativeness of different fields of view without prior delineation of structural regions, and feed the assessment results back into the subsequent multi-source data fusion and model inference processes.
[0070] Based on the aforementioned issues, this application does not limit itself to isolated modeling of the hyperspectral reflectance curve itself during the specific implementation process. Instead, it takes the stability of the detection results in representing the true moisture content of the current batch of straw as its starting point, and treats near-infrared hyperspectral data, environmental parameters, and straw stacking density as multi-source observations that jointly constrain the same physical scenario. By deploying hyperspectral cameras, temperature and humidity sensors, light sensors, and laser rangefinders on the production line or in the stockyard, a non-contact imaging link covering the 900nm-1700nm band is constructed to simultaneously acquire multi-source data characterizing the appearance, internal structure compactness, and environmental boundary conditions of the straw. On this basis, this application proposes to input the preprocessed hyperspectral data into the monitoring network, and encode the environmental parameters and stacking density into conditional vectors. Through a conditional attention fusion mechanism, the feature weights of different bands and different spatial regions are explicitly adjusted, enabling the model to adaptively select more reliable spectral features for moisture content estimation under different working conditions such as high temperature and humidity, sparse stacking, or compact stacking.
[0071] Furthermore, addressing the issue that the surface spectrum may not match the volume state of the stack in a stacking scenario, this application, in its embodiments, slightly rearranges the surface layer of straw within the detection area through airflow disturbance, collects spectral sequences before and after the disturbance, and constructs a difference index reflecting the representativeness of the stack volume. When this representativeness index indicates that the current field of view can only reflect local abnormal areas, this application does not simply discard that area. Instead, it combines environmental parameters and basic straw information, selects multiple candidate condition combinations from the temporal and spatial neighborhoods, calculates the matching weight using the degree of matching between spectral difference features and candidate conditions, and reconstructs the target environmental parameters and stacking density that are most consistent with the current hyperspectral data through weighted reconstruction. This is then used as a condition input to the attention fusion subnetwork, thereby reducing the impact of multi-source data mismatch and local sampling distortion on the moisture content inversion results, and fundamentally improving the detection representativeness and cross-scene stability in non-contact 3D stacking scenarios.
[0072] refer to Figure 1 , Figure 1 This is an exemplary application scenario diagram provided for an embodiment of this application.
[0073] like Figure 1 As shown, straw typically exists in loose piles or stacks during field transport, temporary storage, or raw material pretreatment. Its stacking morphology is influenced by factors such as harvesting method, wind direction, impurity content, and degree of compaction, exhibiting significant randomness and heterogeneity. Although multiple stacking areas may appear to be in the same open-air environment, the internal temperature and humidity conditions are often inconsistent due to limited airflow exchange, differences in light exposure between the surface and interior, and varying degrees of compaction. This can easily lead to spectral shifts caused by localized moisture differences during spectral acquisition.
[0074] Furthermore, even with similar overall ambient temperature and humidity, different stacking areas may still exhibit differences in wind direction obstruction, surface radiation, stack height, and surface roughness. These subtle environmental disturbances directly affect the near-infrared hyperspectral reflection intensity and baseline morphology through changes in optical path, scattering path, and surface reflection conditions, resulting in significant scene-dependent data collection for the same type of straw at different locations. This application addresses this common characteristic of such stacking scenarios by introducing environmental parameters and stacking density as input conditions on top of spectral preprocessing, enabling the model to obtain more stable and representative moisture content prediction results in complex stacking environments.
[0075] It should be noted that, Figure 1 The relative positions of the straw stacking arrangement and detection device shown are only used to illustrate the application scenario of this application. Their shape, scale, sensor arrangement and stacking quantity do not limit the protection scope of this application. Those skilled in the art can make appropriate adjustments to the actual deployment method according to different application needs.
[0076] refer to Figure 2 , Figure 2 This is a schematic diagram of the detection device provided in an embodiment of this application.
[0077] Figure 2 The detection device shown includes a near-infrared hyperspectral imaging device and a processor electrically connected thereto. The near-infrared hyperspectral imaging device is used for non-contact optical acquisition of the target straw stacking area, and can simultaneously acquire spectral information, environmental boundary conditions and stacking structure characteristics to form a multi-source input for moisture content estimation.
[0078] In its implementation, the near-infrared hyperspectral imaging device includes a hyperspectral camera, a temperature and humidity sensor, a light sensor, and a laser rangefinder. The hyperspectral camera is used to collect hyperspectral reflectance data of straw covering a preset wavelength range; the temperature and humidity sensor is used to collect the temperature and relative humidity of the environment in the detection area to characterize the possible influence of external air conditions on the spectral morphology; the light sensor is used to monitor changes in ambient light intensity and to correct for light source disturbances in complex scenarios; and the laser rangefinder is used to obtain the thickness, undulation, and compactness of the straw pile within the detection area to reflect the influence of spatial geometry on the spectral scattering path.
[0079] Understandably, hyperspectral cameras can employ either line-scan or area-array hyperspectral imaging devices, with their spectral resolution, spatial resolution, and imaging frame rate selected based on the moving speed of the stacked materials and the required detection accuracy. In practical applications, hyperspectral cameras can use either a pushbroom structure to achieve line-by-line acquisition along a specific direction, or a snapshot structure to simultaneously acquire full-spectrum cubic data within a single frame. The camera's optics can be configured with a fixed-focal-length lens or a dedicated near-infrared achromatic lens to enhance imaging consistency across different spectral bands.
[0080] In addition, the hyperspectral camera can be equipped with an external near-infrared auxiliary light source or a diffuse illumination module to eliminate ambient light inhomogeneity in outdoor or semi-open environments; the camera can be installed from above, from the side, or from multiple angles to adapt to different stacking configurations and detection distances.
[0081] The processor performs preprocessing operations such as cropping, denoising, and standardization on the acquired spectral data, and encodes environmental parameters and stacking density to construct conditional vectors. Then, the spectral preprocessing data and conditional vectors are input into a preset detection network, and the moisture content detection results of straw are generated through feature extraction unit, attention fusion unit, and output module.
[0082] In some optional embodiments, the processor is equipped with a non-contact straw moisture content detection system based on near-infrared hyperspectral imaging, as provided in the embodiments of this application.
[0083] refer to Figure 3 , Figure 3 A schematic diagram of a processor module provided in an embodiment of this application.
[0084] like Figure 3 As shown, the processor includes a near-infrared hyperspectral imaging module, a multi-source data processing module, and a water content detection module, wherein:
[0085] The near-infrared hyperspectral imaging module is configured to acquire hyperspectral data of straw covering a preset wavelength range through a hyperspectral camera, and simultaneously acquire environmental parameter data and basic straw information through a temperature and humidity sensor, a light sensor and a laser rangefinder; the near-infrared hyperspectral imaging module includes an airflow nozzle for perturbing the straw with airflow to acquire spectral sequences and calculate a representative score;
[0086] The multi-source data processing module is configured to perform band clipping, wavelet denoising, and standard normal variable correction on the straw hyperspectral data to form spectral preprocessed data, and generate condition vectors based on environmental parameter data and straw basic information; when the representative score is greater than a preset difference threshold, it further calculates matching weights based on multiple candidate environmental parameter sets and generates target environmental parameter data and straw basic information that match the straw hyperspectral data based on the matching weights.
[0087] The moisture content detection module is configured to input the spectral preprocessing data, the target environmental parameter data, and the basic information of straw into a preset detection network, and process them through a feature extraction subnetwork, an attention fusion subnetwork, and an output module to generate a straw moisture content detection value.
[0088] In one example, the multi-source data processing module includes:
[0089] The spectral preprocessing unit is configured to perform band clipping, wavelet denoising, and standard normal variable correction on the straw hyperspectral data to generate spectral preprocessed data;
[0090] The condition vector generation unit is configured to normalize and encode the environmental parameter data and the basic information of straw to form an initial condition vector for attention fusion.
[0091] The matching weight calculation unit is configured to calculate the matching weights corresponding to the spectral difference features from multiple candidate environmental parameter sets when the representative score is greater than a preset difference threshold, and generate target environmental parameter data and basic straw information that match the straw hyperspectral data based on the matching weights.
[0092] Next, with reference to the accompanying drawings, the non-contact method for detecting straw moisture content based on near-infrared hyperspectral imaging provided in this application will be further described. Figure 4 The method shown is applied to a detection device, which includes a near-infrared hyperspectral imaging device and a processor. The near-infrared hyperspectral imaging device includes a hyperspectral camera, a temperature and humidity sensor, a light sensor, and a laser rangefinder. The method includes:
[0093] S1: Acquire hyperspectral data of straw covering a preset wavelength range, and simultaneously collect environmental parameter data and basic straw information;
[0094] The basic information about the straw mentioned above refers to the straw stacking density information collected by the laser ranging sensor;
[0095] In this embodiment, since straw often exhibits structural undulations such as pile peaks, depressions, and localized compaction in its actual stacking state, relying solely on spectral data is insufficient to accurately assess its true moisture content. Therefore, a laser rangefinder is used to simultaneously obtain the stack thickness and density distribution to characterize the compactness of local layers. Simultaneously, temperature and humidity sensors and light sensors record the instantaneous ambient temperature, humidity, and light intensity, quantities closely related to phenomena such as spectral baseline drift and characteristic peak shift.
[0096] It is understood that the environmental parameter data described in this application may specifically include physical quantities such as temperature, relative humidity, and ambient light intensity, used to characterize external air conditions and light disturbances; while the straw stack density information can be calculated based on the stack height distribution, surface undulation changes, or statistical results of multiple distance measurements output by laser ranging sensors, used to reflect the compaction degree and spatial geometric differences of the loose stack area. The methods for collecting and converting the above data can all be implemented by those skilled in the art based on existing sensors and conventional signal processing methods, and will not be elaborated here.
[0097] S2: Perform band clipping, wavelet denoising, and standard normal variable correction on the hyperspectral data of straw to obtain spectral preprocessed data; normalize and encode the environmental parameter data and basic information of straw to obtain conditional vectors.
[0098] In this embodiment, the preprocessing stage follows the basic physical laws of near-infrared imaging in scattering media. By cropping the original spectrum to retain characteristic bands strongly correlated with moisture absorption, noise introduced by invalid spectral dimensions is avoided. Multi-scale wavelet denoising technology effectively suppresses high-frequency interference caused by surface roughness, light source perturbations, and sensor dark noise, resulting in a more stable spectral profile. Furthermore, a standard normal variable correction method is employed to center the mean and normalize the variance of the spectra at different locations and in different frames, thereby reducing spectral amplitude differences caused by the randomness of stacking.
[0099] In this step, the application also encodes parameters such as temperature, humidity, light, and stacking density into conditional vectors, so that the subsequent model can adaptively adjust the feature weights based on the scene state during inference, avoiding the decrease in model generalization caused by ignoring scene conditions.
[0100] It is understandable that the specific normalization encoding can be achieved by eliminating dimensions, scaling intervals, or statistically standardizing various environmental parameters and stacking density data. For example, min-max scaling, Z-score standardization, piecewise normalization, or converting multidimensional parameters into fixed-length vector representations via a simple linear mapping network can be used. The selection of the above encoding method can be adjusted according to the range of the field sensor output and the data stability. Those skilled in the art can complete the corresponding implementation based on conventional data preprocessing methods, and this application does not limit the encoding method itself.
[0101] S3: Input the spectral preprocessing data and the conditional vector as input parameters into a preset detection network, and process the input parameters through the detection network to obtain the straw moisture content detection value;
[0102] In this embodiment, the detection network consists of a feature extraction subnetwork, an attention fusion subnetwork, and an output module. The feature extraction subnetwork captures multi-scale joint features of the spectral and spatial dimensions, enabling the model to not only identify changes in traditional moisture absorption peaks but also perceive the differences in the pile structure reflected by spectral and spatial textures. The attention fusion subnetwork extracts scene state information from the conditional vector and assigns differentiated weights to different spectral regions during feature fusion, enhancing reliable bands and suppressing unstable bands. This is suitable for detecting loosely packed materials in non-laboratory environments and can significantly alleviate the spectral drift problem caused by scene changes. Finally, the output module generates a moisture content prediction value based on a multi-scale regression strategy, effectively utilizing the comprehensive information of sensitive bands, intermediate bands, and overall bands in the hyperspectral spectrum, thereby improving detection accuracy.
[0103] Next, we will further elaborate on the technical content of the method in this application regarding spectral preprocessing data.
[0104] In one example, the hyperspectral data of the straw is subjected to band clipping, wavelet denoising, and standard normal variable correction to obtain spectral preprocessed data, including:
[0105] Select a target band that matches the water absorption from the hyperspectral data within a preset spectral range to obtain target clipped band data;
[0106] In the field of related spectral analysis technology, the optimal selection of sensitive wavelengths for water content is usually determined based on the characteristic absorption mechanism of water in the near-infrared region. It is well known that water exhibits significant stretching vibration absorption peaks in the wavelengths of 1150nm–1250nm, 1400nm–1500nm, and 1800nm–1950nm; and in addition to water, plant fiber materials (such as straw) also show some degree of overlapping absorption in adjacent wavelengths due to the presence of cellulose, hemicellulose, and lignin in their components. Therefore, when cropping hyperspectral data, this application determines the target wavelength set based on the energy variation trend of spectral transmittance or reflectance to eliminate spectral bands that are weakly correlated with water content and are easily affected by ambient light and optical path disturbances.
[0107] The target cropped band data is decomposed into multi-scale wavelet data based on the DB4 wavelet basis. The coefficients are compressed at a preset number of decomposition levels, and then the compressed coefficients are reconstructed by wavelet to obtain denoised spectral data.
[0108] For suppressing spectral noise, existing technologies generally employ multi-scale analysis methods based on wavelet transform. Taking the DB4 wavelet basis as an example, its tight support and good smoothness enable it to have a more stable reconstruction capability when dealing with high-frequency noise caused by scattering noise, ambient light disturbances, or equipment dark noise.
[0109] In some optional implementations, the spectral data is first decomposed at multiple scales by setting a decomposition level to obtain approximation and detail components. Then, the high-frequency components of the detail components are compressed using empirical or statistical thresholds to eliminate impulse noise and interfering textures. Finally, the processed coefficients are subjected to inverse wavelet transform to obtain the reconstructed spectrum. This method can locally suppress high-frequency noise in the spectrum without disrupting the overall shape of the absorption peaks, making the final spectral curve closer to the true physical response. Those skilled in the art can adjust the decomposition level or threshold strategy according to the device sampling frequency, target signal-to-noise ratio, and data smoothing requirements.
[0110] For each spectral vector of the denoised spectral data, standard normal variable correction is performed, including mean centering of the spectral vector and normalization according to the standard deviation, to obtain the spectral preprocessed data.
[0111] Understandably, Standard Normal Variance (SNV) correction is one of the most common correction methods in spectral preprocessing, used to reduce DC offset and scale inconsistency caused by sample surface roughness, uneven illumination, and scattering variations. The basic principle of SNV is to perform mean centering and standard deviation normalization on each spectral vector, so that the corrected spectrum has a uniform amplitude scale, thereby enhancing the comparability between spectra at different sampling locations and from different viewing angles.
[0112] Those skilled in the art can complete the correction simply by processing the spectral data point by point according to the formula. The introduction of SNV can effectively reduce the differences in overall reflection intensity caused by uneven stacking, slight changes in sampling angle, or local brightness of the light source, making the subsequent feature extraction process more stable and reliable.
[0113] Next, we will further elaborate on the technical content of the method for detecting networks in this application.
[0114] refer to Figure 5 , Figure 5 This is a schematic diagram of the detection network provided in an embodiment of this application.
[0115] Figure 5 The detection network is shown to include a feature extraction subnetwork, an attention fusion subnetwork, and an output module, wherein:
[0116] The input to the feature extraction subnetwork is spectral preprocessing data, which is used to extract joint spectral-spatial features at three scales;
[0117] The input to the attention fusion subnetwork is a conditional vector, which is used to perform weighted fusion of the spectral-spatial joint features of the three scales based on environmental parameter data and straw basic information, and output fused features.
[0118] The input to the output module is the fusion feature, which is used to output the straw moisture content detection value.
[0119] It is understood that the three scales in this application specifically refer to the multi-level representations formed by the feature extraction sub-network at different convolution depths and receptive fields. These include a shallow local scale mainly based on the original spectral texture, a mid-level correlation scale mainly based on band correlation structures, and a deep global scale that integrates long-distance dependencies between bands and spatial distribution information. These scales are used to characterize the structural changes in hyperspectral data at different resolutions. There are no hard boundaries between the different scales; rather, they are hierarchical feature representations naturally formed through successive convolutions. Those skilled in the art can adjust the number of scales according to the device resolution and data complexity.
[0120] Furthermore, the spectral-spatial joint feature specifically refers to the simultaneous inclusion of band reflection information in the spectral dimension and local neighborhood structure in the spatial dimension within the same feature tensor. For example, while one-dimensional spectral convolution is used to model the continuous absorption relationship between bands, two-dimensional convolution is used to capture the texture, roughness, or stacking undulation features of the sample in the spatial neighborhood, enabling the network to simultaneously characterize the intensity change of the moisture absorption peak and the influence of the stack surface structure on the optical path and scattering in a single feature map.
[0121] It is understandable that the combined spectral and spatial features can more realistically reflect the spectral behavior of bulk materials under non-uniform structures and complex environmental conditions. Based on this, this application performs conditional weighted fusion to improve the stability and scenario adaptability of the final moisture content prediction.
[0122] It should be noted that the detection network of this application can be adapted to the scale of data collected on-site, the target detection accuracy, and the computing power constraints of the deployment end. For example, in lightweight deployment scenarios, the real-time performance can be improved by reducing the number of convolutional layers, lowering the feature channel dimension, or adopting a shallow attention structure. In scenarios with high accuracy requirements or high sample complexity, deeper feature extraction modules, multi-scale cross-layer connections, or higher-dimensional conditional coding methods can be introduced to enhance the network's sensitivity to spectral details and environmental coupling. The specific structure can be selected by those skilled in the art based on actual engineering constraints and data performance, and this application does not limit it in this regard.
[0123] refer to Figure 6 , Figure 6 This is a schematic diagram of the structure of the feature extraction subnetwork provided in an embodiment of this application.
[0124] like Figure 6 As shown, to adapt to the heterogeneity of near-infrared hyperspectral data of straw in both spectral and spatial dimensions, this feature extraction sub-network adopts a hierarchical structure formed by sequentially stacking multi-level feature extraction modules. Specifically, it includes a first feature extraction module, a second feature extraction module, and a third feature extraction module. Each level includes a spectral convolutional layer, a spatial convolutional layer, and a residual block for maintaining gradient stability. Through this hierarchical design, the network can capture local differences in moisture absorption peaks in the shallow stage, model the correlation patterns between spectral bands in the middle stage, and integrate the influence of heap surface texture, roughness, and local morphological changes on spectral behavior in the deep stage. This results in spectral-spatial joint features with different receptive fields and levels of abstraction, specifically spectral-spatial joint feature one, spectral-spatial joint feature two, and spectral-spatial joint feature three.
[0125] In the specific structure, the spectral convolutional layer operates on the spectral dimension using one-dimensional convolution, with the convolution kernel covering adjacent bands to learn the absorption intensity variation trend. This convolutional layer can extract local patterns directly related to the moisture absorption mechanism, such as feature peak broadening, peak position shift, or intensity attenuation. The spatial convolutional layer operates on the spatial dimension using two-dimensional convolution, capturing the texture structure of the stacked surface by aggregating features from different pixel neighborhoods, such as reflection differences caused by straw fiber alignment, surface roughness, or local shading. After the two types of convolutional features are processed in parallel in the same module, they are skipped through residual blocks to output the spectral-spatial joint features at the corresponding scale of the module. This ensures that the integrity of the original spectral structure is maintained as the network deepens, avoiding gradient vanishing or representation shift problems. The residual block includes a batch normalization layer and a nonlinear activation layer, used to skip through the output of the feature extraction module during feature transmission.
[0126] In one example, the spectral convolutional layer is configured as a one-dimensional convolution to perform convolution operations on the spectral dimension. The kernel size of the one-dimensional convolution is 1×10, and the number of convolutional channels increases progressively in each feature extraction module. The spatial convolutional layer is configured as a two-dimensional convolution to perform convolution operations on the spatial dimension corresponding to the spectral preprocessing data. The kernel size of the two-dimensional convolution is 3×3.
[0127] It is understood that the specific differences between the different feature extraction modules in this application lie in the number of convolution channels. The number of convolution channels can be understood as the number of feature maps generated by one-dimensional convolution in the spectral dimension, used to characterize the variation patterns and local correlations of the spectrum in different absorption segments. As the number of convolution channels increases, the network can learn subtle changes in moisture absorption peaks, the correlation between adjacent bands, and spectral perturbations caused by stacking patterns at a higher dimension. This allows the spectral representation from shallow to deep layers to gradually transition from simple local curve morphology to composite features capable of characterizing relationships across a longer range of bands. Those skilled in the art can adjust the number of channels in one-dimensional convolution according to the spectral sampling interval, the number of effective bands, and the target detection accuracy to obtain spectral feature decomposition capabilities more suited to the scene.
[0128] In some optional implementations, the number of convolutional channels can also be understood as the number of feature planes output by the two-dimensional convolution in the spatial dimension. This is used to capture the texture differences, local reflection intensity variations, and spatial distribution features affected by ambient lighting or stacking roughness of the straw surface within the detection area. The setting of the number of two-dimensional convolutional channels determines whether the network can distinguish spatial perturbations at different scales, such as high-frequency textures in loose fiber areas, low-frequency brightness variations in compacted areas, or local shadow structures caused by lighting angles. In scenes with significant variations in imaging conditions or complex stacking morphologies, appropriately increasing the number of spatial convolutional channels can enhance the network's ability to distinguish spatial textures, making the generated spectral-spatial joint features more stable in response to scene conditions during subsequent fusion stages.
[0129] In one example, the attention fusion subnetwork includes:
[0130] The query vector generation unit is configured to linearly map the spectral-spatial joint features at three scales output by the three feature extraction modules to generate corresponding query vectors.
[0131] The conditional coding layer is configured to perform fusion mapping on the environmental parameter data and straw basic information to generate key vectors and value vectors for attention calculation;
[0132] The conditional attention calculation layer is configured to perform attention weight calculation based on the query vector, key vector and value vector to obtain weight coefficients for each scale feature, wherein the weight coefficients are used to characterize the confidence level of different spectral regions under the current temperature, humidity and stacking density conditions.
[0133] The feature weighting layer is configured to perform channel-by-channel weighted adjustment of the corresponding spectral-spatial joint features according to the weighting coefficients to obtain fused features.
[0134] In this embodiment, the attention fusion subnetwork uses the matching relationship between spectral-spatial joint features and conditional vectors as the core of its modeling. Features at different scales output by the three feature extraction modules are first projected onto a unified dimension via their respective independent linear mappings or small fully connected networks, forming corresponding query vector sequences. Each query vector corresponds one-to-one with a spectral-spatial location in the feature map. Environmental parameter data and straw stacking density information are first fused and mapped in the conditional encoding layer: for example, numerical values such as temperature, humidity, light intensity, and stacking height are concatenated and input into a multilayer perceptron, outputting a fixed-length vector, which is then transformed by two linear transformations to generate key and value vectors respectively. In this way, conditional information is encoded as a latent representation describing which feature patterns the model should focus on in the current scenario, rather than simply being auxiliary features appended to the input.
[0135] Furthermore, the conditional attention computation layer can be implemented using scaled dot product attention or other equivalent computational forms:
[0136] The query vector at each scale is used to perform an inner product or relevance measure with the condition key vector to obtain an evaluation value representing the degree of fit between the feature at that location and the current environment-stacking state. This evaluation value is then scaled and Softmax normalized to generate a sequence of weight coefficients. These weight coefficients reflect both the credibility of different spectral regions under given temperature, humidity, and stacking density conditions, and the relative importance of features at each scale within the current scene. In terms of parameter implementation, the key vector and value vector can be broadcast across the entire feature map along the channel dimension, ensuring consistent modulation effects across all locations under the same scene conditions. Alternatively, different conditional mapping branches can be configured for different scales to highlight the different roles of shallow and deep features in complex scenes. Those skilled in the art can choose the appropriate branch based on computational resources and accuracy requirements.
[0137] Furthermore, after receiving the attention weights, the feature weighting layer performs channel-by-channel weighted adjustments on the spectral-spatial joint features at each scale. Specifically, the attention weights can be viewed as a set of scaling factors for channels or bands, which are multiplied element-wise or channel-wise with the original features to suppress unstable bands or spatial regions heavily affected by environmental interference, while improving the feature response to better match the current scene conditions. The weighted multi-scale features are then integrated into a unified fusion feature through cascading, summation, or cross-scale fusion for subsequent water content regression detection.
[0138] In one example, the output module includes:
[0139] The first particle size regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the first scale in the fused features, and output the first particle size moisture content detection value for initial screening of straw moisture.
[0140] The second particle size regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the second scale in the fused features, and generate the second particle size moisture content detection value in combination with the straw variety.
[0141] The third granularity regression branch is configured to perform regression fitting on the spectral-spatial joint features corresponding to the third scale in the fused features, so as to output the third granularity moisture content detection value.
[0142] The multi-scale loss weighted branch is configured to calculate the mean square error loss for the first particle size moisture content detection value, the second particle size moisture content detection value, and the third particle size moisture content detection value, and calculate the straw moisture content detection value based on the mean square error loss.
[0143] Specifically, in relevant spectral modeling and deep learning regression tasks, multi-scale regression structures are commonly used to process input data with hierarchical feature distributions. These structures typically input feature maps from different depths into separate regression heads to capture different levels of information, from coarse-grained to fine-grained. For example, shallow features more readily reflect local intensity fluctuations and short-range absorption structures in the original spectral curve; mid-level features can characterize the correlation between bands, spectral segmentation trends, and spatial textures within a certain range; while deep features contain global absorption patterns across regions and bands. Traditional single-scale regression methods, if relying solely on deep features, easily overlook significant near-surface absorption differences; if relying solely on shallow features, they lack robustness to changes in packing density or illumination disturbances.
[0144] In some optional implementations, each regression branch in this embodiment can employ a lightweight regression sub-network with one or more fully connected layers. Its input is a fusion feature tensor of the corresponding scale, which is flattened or converted into a fixed-length feature vector after global average pooling, and then outputs the corresponding water content prediction value via the regression layer. For mesoscale branches that require incorporating variety information, the feature vector and the variety encoding vector can be concatenated or linearly fused, enabling the network to adaptively correct for differences in absorption characteristics among different varieties. This type of fusion method has been widely used in existing agricultural product spectral classification and regression tasks. Its implementation relies on conventional fully connected layers and activation functions, which can be directly constructed by those skilled in the art using conventional deep learning frameworks.
[0145] Furthermore, for the weighted approach of multi-scale loss, existing deep supervision strategies typically calculate the regression loss for each level of prediction result separately and then perform a weighted sum based on preset or learned weights. This allows the network to simultaneously optimize the feature extraction capabilities of different levels during backpropagation. The theoretical basis is that shallow features are more sensitive to local absorption structures, while deep features are more robust to the overall absorption trend. Through joint optimization, shallow and deep features can mutually constrain each other in the convergence direction, thus avoiding overfitting noise in shallow layers or neglecting local band information in deep layers. This embodiment uses mean squared error as the single-term loss. Those skilled in the art can adjust the loss weights according to the task characteristics or adopt an adaptive weighting method based on gradient magnitude to further improve training stability. By using multi-scale supervision and weighted merging, the final output result possesses both local sensitivity and overall stability, suitable for estimating the moisture content of loosely structured materials like straw, whose spectra are significantly affected by environmental disturbances under different stacking conditions.
[0146] Next, we will further elaborate on the technical content of the method for acquiring hyperspectral data of straw in this application.
[0147] refer to Figure 7 , Figure 7 This is a schematic diagram of another near-infrared hyperspectral imaging device provided in the embodiments of this application.
[0148] Figure 7 The near-infrared hyperspectral imaging device shown includes not only a hyperspectral camera and other sensors (not shown in the figure), but also an additional airflow nozzle for applying controlled disturbance to the straw stack area before or during spectral acquisition. This structure is particularly suitable for naturally stacked or bulk material scenarios.
[0149] Understandably, the airflow nozzles are used to inject short-duration pulsed airflow into the straw stacking area to cause slight deformation or fiber rearrangement on the surface of the stack, thereby altering the scattering path of light in a localized area and enabling the hyperspectral camera to acquire a sequence of spectral changes before and after the disturbance. Because loosely stacked straw has a high porosity and an unstable surface structure, transient spectral changes often reflect the representativeness of the internal layers better than static structures.
[0150] For example, when there are large differences in stacking density or local shading, the magnitude of the change in the spectrum obtained after slight perturbation can be used to infer whether the spectrum of the region is dominated by random surface factors, and thus determine whether the region can be used as a valid sample for subsequent modeling.
[0151] In some optional implementations, the airflow nozzle can be controlled by supplying air via a solenoid valve, air pump, or compressed air pipeline. The spray intensity can be set according to the looseness of the stack, the stack height, and the size of the detection area. Those skilled in the art can select different nozzle shapes or spray angles according to actual needs to obtain more uniform or more localized disturbance effects. This application does not limit the nozzle type or specific implementation method, as long as it can apply controllable disturbance without damaging the stack structure.
[0152] In one example, acquiring straw hyperspectral data covering a preset wavelength range includes:
[0153] S1.1: Obtain the static spectrum of straw within the detection area;
[0154] Specifically, during static acquisition, the airflow nozzles remain closed, and the hyperspectral camera continuously acquires several frames of hyperspectral data under undisturbed conditions. A stable set of static spectral cubes is obtained by inter-frame averaging or median filtering to characterize the original surface response under the current stacking morphology and environmental conditions.
[0155] S1.2: The airflow nozzle is used to agitate the straw to rearrange the surface layer of the straw, and a spectral sequence is collected;
[0156] Specifically, during the airflow disturbance phase, short-duration, directional airflow is injected from nozzles above or to the side of the detection area, causing slight displacement or rearrangement of the straw fibers on the surface of the pile, while the overall structure of the pile remains relatively stable. The intensity and duration of the disturbance need to be matched with the height and compaction of the pile, causing sufficient deformation on the surface to alter the local light scattering path without blowing the straw out of the field of view or damaging the pile's morphology. Before the airflow is triggered, the hyperspectral camera maintains continuous acquisition, recording the start and end times of the airflow using timestamps or synchronous trigger signals, forming spectral sequences during and after the disturbance to reflect the spectral evolution of the pile during the dynamic process.
[0157] In this embodiment, the airflow nozzle can be connected to an adjustable compressed air source, and its switching control is achieved at the millisecond level via a solenoid valve. The nozzle outlet shape can be fan-shaped or a multi-hole array to create a relatively uniform velocity field in the detection area; the spray direction can be slightly tilted towards the surface of the pile, allowing the airflow to slide along the slope rather than impacting directly, thus reducing the risk of large-scale overturning. The hyperspectral camera is set to a high frame rate during this stage, such as several to tens of frames per second, to capture spectral changes at the initial moment of disturbance and during the gradual stabilization of the surface.
[0158] S1.3: Based on the spectral difference characteristics between the static spectrum and the spectral sequence, calculate a representative score to characterize the straw stacking volume within the detection area;
[0159] Specifically, the representativeness score is calculated using the static spectrum as a baseline, treating the spectral sequence during disturbance as a series of observations of the same pile under different surface layer arrangements. For regions with good volume representativeness—that is, regions where the internal moisture distribution is relatively uniform and the surface and internal optical properties are similar—slight surface rearrangement has limited impact on overall reflectance characteristics, and the difference between the static spectrum and the disturbed spectrum mainly manifests as small-amplitude, random disturbances. However, for regions with poor representativeness, such as pile peaks or local collapse areas, the surface layer may be composed of straw or impurities with significantly different compositions from the interior, or there may be strong shading. After airflow disturbance, the exposure state of the surface material will change significantly, resulting in a significant shift in the spectrum at specific wavelengths or spatial locations. By comparing the distribution of differences between the static spectrum and the spectra at each time point, the sensitivity of the spectrum in that region to random surface changes can be indirectly reflected.
[0160] In this embodiment, the static spectrum and the perturbed spectrum in the spectral sequence can be preprocessed uniformly, including but not limited to band clipping, wavelet denoising, and standard normal variable correction, to eliminate system noise and overall brightness changes during the acquisition process. Subsequently, the difference vector between the spectrum and the static spectrum at each time point during the perturbed period can be calculated within each spatial sub-block, and the band distribution of the difference vector can be statistically analyzed. For example, the difference range, direction of change, and evolution trend over time of the water content-sensitive band can be evaluated. If the difference is mainly concentrated in non-sensitive bands or exhibits a zero-mean, low-variance distribution at multiple time points, it indicates that the airflow perturbed only changed the microscopic arrangement without significantly altering the volumetric absorption characteristics, and this region can be considered highly representative. Conversely, if a continuous, unidirectional, and strong shift occurs in the key moisture absorption band, it suggests a significant difference between the surface structure and the interior, and the static spectrum in this region is less representative of the overall pile water content. The representativeness score can be constructed as a comprehensive index reflecting the amplitude of spectral changes, stability, and coupling degree with the moisture-sensitive band. After normalization, it can be mapped to a preset interval for comparison with the difference threshold.
[0161] S1.4: If the representative score is less than or equal to the preset difference threshold, the static spectrum is used as the straw hyperspectral data;
[0162] Specifically, when the representative score of a certain detection area is below the difference threshold, it indicates that the spectral changes in that area before and after airflow disturbance are mainly small-scale random disturbances, insufficient to indicate a systematic difference between the surface and the interior. In this case, the static spectrum can already reflect the optical response of the area under the current stacking condition well, and the benefit of further complex processing of the disturbance sequence is limited. Based on this judgment, the static spectrum can be directly used as the hyperspectral data for subsequent modeling, which simplifies the data processing flow and avoids introducing additional noise due to unnecessary transformations.
[0163] In this embodiment, the difference threshold can be obtained by statistically analyzing a large number of highly representative stacked samples. For example, a stack that has been manually inspected or offline verified to be internally uniform can be selected as a benchmark, its representative score distribution range can be calculated, and a certain quantile can be used as the threshold. In this way, when the score of a new detection area is less than or equal to the threshold, its spectrum can be considered to be sufficiently representative with a high probability.
[0164] S1.5: If the representative score is greater than the difference threshold, the static spectrum is weighted according to the spectral difference characteristics, and the weighted static spectrum is used as the straw hyperspectral data;
[0165] Specifically, when the representative score exceeds the difference threshold, it indicates a certain degree of consistency shift between the static spectrum and the perturbation sequence in key bands. This reflects a difference between the surface structure and the internal state of the detected area. If the static spectrum is directly used for modeling, the water content estimate may deviate from the average volume of the pile. In this case, the static spectrum can be weighted and corrected using spectral information from the perturbation sequence that is closer to the true internal state. The resulting weighted spectrum retains a single-frame structure in form, but its band intensity and shape are closer to the steady-state response after multi-frame synthesis. The weighting process can assign different weights to different bands or different time points based on spectral difference characteristics, thereby emphasizing the internal information while suppressing the influence of accidental surface states.
[0166] In this embodiment, the difference between each frame of the perturbation sequence and the static spectrum is first analyzed to identify time periods in which changes converge in the same direction within the moisture-sensitive band, and these time points are considered windows for the release of inner layer information. Then, the contribution weight of each time point is calculated based on the magnitude and stability of the difference, and the static spectrum is linearly combined or piecewise combined with the spectra of these time points according to the weights. For example, some bands can retain more static spectral information to reflect the overall structural characteristics of the heap; other bands can draw more on the spectrum that tends to stabilize after the perturbation to compensate for the deviation caused by surface anomalies. Through this band-adaptive weighting method, the information of the time dimension can be folded back into the single frame spectrum without increasing the data dimension, so that the weighted spectrum contains both the overall characteristics of static observation and the internal properties revealed by the perturbation response.
[0167] In some optional implementations, if the representative score is greater than the difference threshold, further corrections to the environmental parameter data and basic straw information are required because:
[0168] Representativeness scoring has shown a certain degree of inconsistency between the surface spectrum of the current detection area and the volume state of the stockpile. This inconsistency is not only reflected in the spectrum itself, but also often accompanied by misalignment in sampling time and space. For example, there is a distance difference between the installation location of the environmental sensor and the field of view of the hyperspectral camera, and the surface of the stockpile undergoes local movement during disturbance. This makes the temperature and humidity data and stockpile density data originally associated with the spectrum of this area actually closer to the state of neighboring areas or different time slices. If the original environmental parameters and stockpile density are still directly used in subsequent conditional modeling, while the hyperspectral data has already tended towards the true volume state through weighted correction, the conditional vector will still remain in the misaligned scenario. A new mismatch will occur between the two, causing the subsequent attention fusion and regression networks to be driven by contradictory information, weakening the effect brought by the aforementioned representativeness correction.
[0169] In this embodiment, by appropriately correcting the environmental parameter data and basic straw information when the representative score exceeds a threshold, these conditional quantities can be realigned to an effective scenario consistent with the weighted spectrum. For example, based on the time series of environmental parameters during the disturbance, temperature, humidity, light, and stacking density values can be selected or reconstructed within a time window that is more consistent with the spectral change trend. Alternatively, the stacking density of the current area can be interpolated or weighted smoothed based on the representative scores and density distribution of adjacent detection areas. The corrected conditional quantities obtained in this way no longer simply reflect the original reading of the sensor at a certain moment, but maintain a closer logical relationship with the state of the spectral data after representative correction. When the corrected conditional vector is input into the detection network, the scene cues and spectral representations used by the attention fusion subnetwork to allocate feature weights point to the same physical state, which helps the network focus its learning on real moisture-related changes rather than being interfered with by spurious differences introduced by spatiotemporal mismatch, thereby improving the stability and reliability of the moisture content prediction results as a whole.
[0170] In one example, if the representative score is greater than the difference threshold, the method further includes:
[0171] Collect environmental parameter data and basic information about straw;
[0172] Multiple candidate environmental parameter sets are extracted from the environmental parameter data and basic straw information;
[0173] A spectral feature vector is constructed based on the spectral difference characteristics, and the corresponding matching score is calculated based on the matching correlation between the spectral feature vector and each candidate environmental parameter in the candidate environmental parameter set.
[0174] The matching scores are normalized to obtain the matching weights of each candidate environmental parameter, and the candidate environmental parameter sets are weighted according to the matching weights to obtain environmental parameter data and basic straw information that match the straw hyperspectral data.
[0175] Specifically, when the representative score exceeds the difference threshold, it indicates that a directional, non-random systematic difference has emerged between the static and perturbed spectra. This difference is related to the stack structure, local optical path length, air humidity, or stack density. In hyperspectral imaging, ambient temperature, humidity, and illumination conditions can have measurable effects on the spectrum by altering the depth of the moisture absorption band, the baseline height of the scattering peak, and the effective optical path length of the near-infrared diffuse reflectance. Therefore, there is a discernible correlation between spectral difference patterns and specific environmental parameters.
[0176] In this embodiment, to obtain the environmental scenario most consistent with the spectral behavior, multiple candidate environmental parameter sets can be selected from the time-series environmental data recorded by the detection device. For example, sampling points of temperature, humidity, light intensity, and stacking density within a certain time window before and after the disturbance can be used, or synchronously recorded environmental information can be collected from spatially adjacent areas. Each candidate environmental parameter set contains a possible combination of environmental states, providing a reference scenario for spectral changes. Subsequently, feature extraction can be performed on the perturbed spectral sequence, integrating the difference between the static spectrum and the perturbed frame according to band and spatial location to form a spectral feature vector. This feature vector can be generated through weighted averaging, principal component extraction, or lightweight subnetworks, enabling it to prominently reflect the intensity and direction of changes in the moisture-sensitive band. The matching score can be calculated based on correlation coefficients, vector angles, Mahalanobis distance, spectral slope similarity, etc., to measure the consistency between the spectral difference structure and the environmental change trend of each candidate environmental parameter set. For example, when the increasing trend of temperature and humidity in the candidate environmental set is consistent with the direction of absorption peak enhancement shown in the spectral feature vector, its matching score is high.
[0177] Furthermore, normalizing the matching scores of all candidate environmental parameter sets forms a set of weighted matching weights. These weights are used to measure the credibility of each candidate environmental parameter set in explaining spectral differences. Subsequently, by weighting and fusing the candidate environmental parameter sets according to their matching weights, a corrected set of environmental parameters is obtained. This set is statistically closer to the actual spectral performance and reflects the real scene state corresponding to the spectral differences. For example, if a candidate parameter set has high humidity, and the spectral difference shows the common trend of deepening absorption regions when humidity increases, then this candidate set will have a larger weighting, while other candidate sets that do not conform to the spectral characteristics will automatically decrease. The corrected environmental parameter data and basic information obtained in this way not only retain the authenticity of the collected data, but also achieve automatic calibration through the physical mechanism of spectral differences. This allows the subsequent attention fusion network to obtain more matching scene cues when allocating band weights, reducing the disturbance to model inference caused by the spatiotemporal misalignment between the original environmental data and the weighted spectrum, and helping to improve the stability of the final water content prediction. Those skilled in the art can implement this process using conventional numerical similarity calculation methods and linear weighting, without relying on complex model structures.
[0178] In one example, the attention fusion subnetwork further includes:
[0179] The key vector and value vector are scaled according to the matching weights to adjust the attention distribution of the attention fusion subnetwork, wherein the scaling includes:
[0180] Based on the matching weights, a scaling factor matrix corresponding to the key vector and value vector is generated;
[0181] The key vector and value vector are normalized twice based on the scaling factor matrix to generate adjusted key vectors and value vectors that are consistent with the representative scores of the straw hyperspectral data.
[0182] Specifically, a set of scaling factors can be generated in the channel or feature dimensions by combining the representativeness score with the matching weights of each candidate environment parameter. This allows the key and value vectors in the corresponding dimensions to be amplified in scenarios with high matching degrees, resulting in a higher attention response in subsequent dot product operations. Conversely, for scenarios with low matching degrees, the influence of this conditional information in the attention space is automatically reduced by shrinking the corresponding scaling factor. In this way, the attention mechanism no longer relies solely on the parameter distribution implicitly learned during network training when calculating Query-Key similarity. It is also subject to external weight constraints related to the representativeness of the current hyperspectral data, making the attention distribution closer to the real coupling relationship between multi-source data.
[0183] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A non-contact detection method for straw moisture content based on near-infrared hyperspectrum, applied to a detection device, characterized in that, The detection device comprises a near-infrared hyperspectral imaging device and a processor, the near-infrared hyperspectral imaging device comprises a hyperspectral camera, a temperature and humidity sensor, an illumination sensor and a laser ranging sensor, and the method comprises: Acquiring straw hyperspectral data covering a preset wavelength range, and synchronously collecting environmental parameter data and straw basic information, wherein the straw basic information is straw stacking density information collected by the laser ranging sensor; Performing wave band clipping, wavelet denoising and standard normal variable correction on the straw hyperspectral data to obtain spectral pretreatment data, and performing normalization coding on the environmental parameter data and the straw basic information to obtain a condition vector; Inputting the spectral pretreatment data and the condition vector as input parameters into a preset detection network, processing the input parameters through the detection network to obtain a straw moisture content detection value, the detection network comprising a feature extraction subnetwork, an attention fusion subnetwork and an output module, the feature extraction subnetwork being composed of three feature extraction modules and being used for extracting three scales of spectral-spatial joint features from the spectral pretreatment data, and the attention fusion subnetwork being used for weighting and fusing the three scales of spectral-spatial joint features according to the environmental parameter data and the straw basic information to output fused features; The attention fusion subnetwork comprises: A query vector generation unit configured to linearly map the three scales of spectral-spatial joint features output by the three feature extraction modules respectively to generate corresponding query vectors; A condition coding layer configured to fuse and map the environmental parameter data and the straw basic information to generate a key vector and a value vector for attention calculation; A condition attention calculation layer configured to calculate attention weights based on the query vectors, the key vector and the value vector to obtain weight coefficients for each scale of features, wherein the weight coefficients are used to represent the credibility of different spectral regions under the current temperature and humidity and stacking density conditions; A feature weighting layer configured to perform channel-by-channel weighting adjustment on the corresponding spectral-spatial joint features according to the weight coefficients to obtain fused features; The output module comprises: A first granularity regression branch configured to regress and fit the spectral-spatial joint features corresponding to the first scale in the fused features to output a first granularity moisture content detection value for preliminary screening of straw moisture; A second granularity regression branch configured to regress and fit the spectral-spatial joint features corresponding to the second scale in the fused features and combine the straw variety to generate a second granularity moisture content detection value; A third granularity regression branch configured to regress and fit the spectral-spatial joint features corresponding to the third scale in the fused features to output a third granularity moisture content detection value; A multi-scale loss weighting branch configured to calculate mean square error losses for the first granularity moisture content detection value, the second granularity moisture content detection value and the third granularity moisture content detection value respectively, and calculate a straw moisture content detection value according to the mean square error losses.
2. The method according to claim 1, wherein the method is characterized by, The straw hyperspectral data is subjected to band clipping, wavelet denoising and standard normal variable correction to obtain spectral pretreatment data, including: The target band data is obtained by selecting the target band matched with the moisture absorption from the preset spectral range. The target band data is subjected to multi-scale wavelet decomposition based on the DB4 wavelet basis, the coefficients are compressed under the preset decomposition level, and the compressed coefficients are subjected to wavelet reconstruction to obtain the denoised spectral data. The spectral vectors of the denoised spectral data are subjected to standard normal variable correction, including mean centering processing of the spectral vectors and normalization according to the standard deviation, to obtain the spectral pretreatment data.
3. The method according to claim 1, wherein the method is characterized by, Each feature extraction module includes a spectral convolution layer and a spatial convolution layer, and each feature extraction module further includes a residual block, the residual block includes a batch normalization layer and a nonlinear activation layer, and is used for jump connection of the output of the feature extraction module in the feature transmission process; The spectral convolution layer is configured as one-dimensional convolution, which is used for convolution operation on the spectral dimension, the convolution kernel size of the one-dimensional convolution is 1x10, and the convolution channel number is increased step by step in each feature extraction module; the spatial convolution layer is configured as two-dimensional convolution, which is used for convolution operation on the spatial dimension corresponding to the spectral pretreatment data, and the convolution kernel size of the two-dimensional convolution is 3x3.
4. The method according to claim 3, wherein the method is characterized by, The near-infrared hyperspectral imaging device further includes an airflow nozzle, and the acquisition of the straw hyperspectral data covering the preset wavelength range includes: Acquiring a static spectrum of the straw in the detection area; The airflow nozzle is used to disturb the airflow of the straw to rearrange the surface layer of the straw, and a spectrum sequence is collected; According to the spectral difference characteristics between the static spectrum and the spectrum sequence, a representative score for representing the stacking volume of the straw in the detection area is calculated; If the representative score is less than or equal to a preset difference threshold, the static spectrum is taken as the straw hyperspectral data; If the representative score is greater than the difference threshold, the static spectrum is weighted according to the spectral difference characteristics, and the weighted static spectrum is taken as the straw hyperspectral data.
5. The method according to claim 4, wherein the method is characterized by, If the representative score is greater than the difference threshold, the method further includes: Collecting environmental parameter data and straw basic information; Extracting a plurality of candidate environmental parameter sets from the environmental parameter data and the straw basic information; Constructing a spectral feature vector according to the spectral difference characteristics, and calculating a corresponding matching score based on the matching correlation between the spectral feature vector and each candidate environmental parameter in the candidate environmental parameter set; The matching scores are normalized to obtain the matching weights of each candidate environmental parameter, and each candidate environmental parameter set is weighted according to the matching weights to obtain the environmental parameter data and the straw basic information matched with the straw hyperspectral data.
6. The method according to claim 5, wherein the method is characterized by, The attention fusion subnetwork further includes: The key vector and the value vector are scaled according to the matching weights to adjust the attention distribution of the attention fusion subnetwork, wherein the scaling includes: A scaling factor matrix corresponding to the key vector and the value vector is generated based on the matching weights; The key vector and the value vector are twice normalized according to the scaling factor matrix to generate adjusted key vectors and value vectors consistent with a representative score of the straw hyperspectral data.
7. A non-contact detection system for straw moisture content based on near-infrared hyperspectrum, for realizing the non-contact detection method for straw moisture content based on near-infrared hyperspectrum as claimed in any one of claims 1-6, characterized in that, The system comprises: The near-infrared hyperspectral imaging module is configured to acquire straw hyperspectral data covering a preset wavelength range through a hyperspectral camera, and simultaneously acquire environmental parameter data and straw basic information through a temperature and humidity sensor, an illumination sensor, and a laser ranging sensor; the near-infrared hyperspectral imaging module comprises an airflow nozzle for airflow disturbance of the straw to acquire a spectral sequence and calculate a representative score; The multi-source data processing module is configured to perform band clipping, wavelet denoising, and standard normal variable correction on the straw hyperspectral data to form spectral pretreatment data, and generate a condition vector according to the environmental parameter data and the straw basic information; when the representative score is greater than a preset difference threshold, a matching weight is calculated according to a plurality of candidate environmental parameter sets, and target environmental parameter data and straw basic information matched with the straw hyperspectral data are generated based on the matching weight; The water content detection module is configured to input the spectral pretreatment data, the target environmental parameter data, and the straw basic information into a preset detection network, process them through a feature extraction subnetwork, an attention fusion subnetwork, and an output module, and generate a straw water content detection value; the detection network comprises a feature extraction subnetwork, an attention fusion subnetwork, and an output module; the feature extraction subnetwork is composed of three feature extraction modules and is used to extract spectral-spatial joint features of three scales from the spectral pretreatment data; the attention fusion subnetwork is used to weight and fuse the spectral-spatial joint features of the three scales according to the environmental parameter data and the straw basic information, and output fused features; The attention fusion subnetwork comprises: A query vector generation unit configured to linearly map the spectral-spatial joint features of the three scales output by the three feature extraction modules to generate corresponding query vectors; A condition encoding layer configured to fuse and map the environmental parameter data and the straw basic information to generate a key vector and a value vector for attention calculation; A conditional attention calculation layer configured to calculate attention weights based on the query vectors, the key vector, and the value vector to obtain weight coefficients for each scale feature, wherein the weight coefficients are used to represent the credibility of different spectral regions under the current temperature and humidity and stacking density conditions; A feature weighting layer configured to perform channel-by-channel weighting adjustment on the corresponding spectral-spatial joint features according to the weight coefficients to obtain fused features; The output module comprises: A first granularity regression branch configured to regress and fit the spectral-spatial joint features corresponding to the first scale in the fused features to output a first granularity water content detection value for preliminary screening of straw moisture; A second granularity regression branch configured to regress and fit the spectral-spatial joint features corresponding to the second scale in the fused features and generate a second granularity water content detection value in combination with the straw variety; a third granularity regression branch configured to regress and fit the spectrum-space joint features corresponding to a third scale in the fused features to output a third granularity moisture content detection value; a multi-scale loss weighting branch configured to calculate mean square error losses respectively for the first granularity moisture content detection value, the second granularity moisture content detection value and the third granularity moisture content detection value, and to calculate a straw moisture content detection value according to the mean square error losses.
8. The non-contacting system for detecting the moisture content of straw based on near-infrared hyperspectrum according to claim 7, characterized in that, The multi-source data processing module comprises: a spectrum preprocessing unit configured to perform band clipping, wavelet denoising and standard normal variable correction on the straw hyperspectral data to generate spectrum preprocessed data; a condition vector generation unit configured to normalize and encode the environmental parameter data and the straw basic information to form an initial condition vector for attention fusion; a matching weight calculation unit configured to, when the representative score is greater than a preset difference threshold, calculate a matching weight corresponding to the spectrum difference feature from a plurality of candidate environmental parameter sets, and generate target environmental parameter data and straw basic information matched with the straw hyperspectral data based on the matching weight. a third granularity regression branch configured to regress and fit the spectrum-space joint features corresponding to a third scale in the fused features to output a third granularity moisture content detection value; a multi-scale loss weighting branch configured to calculate mean square error losses respectively for the first granularity moisture content detection value, the second granularity moisture content detection value and the third granularity moisture content detection value, and to calculate a straw moisture content detection value according to the mean square error losses. The multi-source data processing module comprises: a spectrum preprocessing unit configured to perform band clipping, wavelet denoising and standard normal variable correction on the straw hyperspectral data to generate spectrum preprocessed data; a condition vector generation unit configured to normalize and encode the environmental parameter data and the straw basic information to form an initial condition vector for attention fusion; a matching weight calculation unit configured to, when the representative score is greater than a preset difference threshold, calculate a matching weight corresponding to the spectrum difference feature from a plurality of candidate environmental parameter sets, and generate target environmental parameter data and straw basic information matched with the straw hyperspectral data based on the matching weight.
Citation Information
Patent Citations
Method for determining maize straw components by near-infrared spectrometer
CN106932365A
Capacitance acquisition device and method for predicting moisture content of straw
CN114062448A