Food impurity detection method based on spectrum technology

The food impurity detection method using spectral technology solves the problem of unstable impurity detection in high-speed production lines using traditional methods. It achieves stable output and high-accuracy detection under conditions of light fluctuations and high speed, reducing the false rejection rate and the missed detection rate.

CN122089666APending Publication Date: 2026-05-26MARINE BIOMEDICAL RES INST OF QINGDAO CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
MARINE BIOMEDICAL RES INST OF QINGDAO CO LTD
Filing Date
2026-02-03
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Traditional purely visual inspection methods are unstable in detecting non-metallic impurities and impurities with similar colors or semi-transparent structures on high-speed production lines. This leads to inconsistent confidence levels for the same impurity in different batches and locations, making it difficult to simultaneously output the type, location, and minimum rejection window, resulting in significant losses of good products.

Method used

A food impurity detection method based on spectral technology is adopted. It acquires spectral image data online, forms a standard spectral characterization in real time through self-calibration, compensates for motion and illumination disturbances, constructs a material spectral fingerprint library, screens and locates candidate regions, triggers local re-inspection in case of uncertainty, outputs multi-dimensional detection results, and performs closed-loop update and drift management.

Benefits of technology

It achieves stability and accuracy in impurity detection under fluctuating light conditions and high speed, reduces false rejection rate and false negative rate, and improves the consistency and real-time performance of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122089666A_ABST
    Figure CN122089666A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image enhancement, and provides a food impurity detection method based on a spectrum technology, which comprises the following steps: acquiring spectrum image data and built-in reference plate data on line, and normalizing original data through real-time self-calibration to form standard spectrum characterization; performing motion and illumination disturbance compensation on the standard spectrum characterization, and establishing a material spectrum fingerprint database containing material category and source information based on the collected standard spectrums of the impurity material and the contact part material; performing rapid screening and connected domain extraction on the compensated spectral representation to obtain a candidate region, calculating the similarity and the novelty of the candidate region and the fingerprint database, and triggering local reinspection when the similarity falls into an uncertain interval or the novelty exceeds a preset threshold value to determine the category and the position of an impurity; and outputting a multi-dimensional detection result, and performing controlled updating and version management on the fingerprint database and the candidate screening threshold value based on a confirmation sample.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image enhancement technology, specifically a method for detecting food impurities based on spectral technology. Background Technology

[0002] Food impurity testing utilizes specialized techniques and instruments to identify, quantify, and eliminate unwanted foreign objects or illegal additives in food to ensure food safety, compliance with regulations, and protection of consumer health and brand reputation.

[0003] Chinese patent application number CN202510294025.5 discloses a method for detecting food impurities based on spectral technology. This method includes: acquiring images of a mixture of normal and impurity foods, preprocessing them to generate an initial image; performing background segmentation on the initial image to obtain a target image; performing edge detection on the target image to identify individual food regions; calculating the filtering weights of pixels within each individual food region using a bilateral filtering algorithm; reconstructing the pixels within the individual food region based on the filtering weights to obtain the reconstructed spectral values; determining the reconstructed spectral values ​​of all pixels in the target image, performing filtering, and identifying and labeling impurity foods based on difference analysis; and optimizing the bilateral filtering algorithm to eliminate interference from normal food products on impurity foods, avoiding errors in the identification results, improving the distinction between impurity and normal food products in the spectral image, and increasing the accuracy of impurity food identification.

[0004] In high-speed production line online impurity detection scenarios, traditional purely visual detection methods suffer from instability in detecting non-metallic impurities, as well as impurities of similar color and semi-transparent material. This leads to inconsistent confidence levels for the same impurity in different batches and locations, making it difficult to simultaneously output solutions for type, location, and minimum rejection window, resulting in significant loss of good products. Therefore, there is an urgent need for an impurity detection method based on spectral technology that can stably output multidimensional results and reduce false rejections even under high-speed and fluctuating lighting conditions.

[0005] To address the aforementioned problems, this invention proposes a food impurity detection method based on spectral technology. This method collects and calibrates spectral data to form a standardized spectral characterization; compensates for motion and illumination disturbances to construct a material spectral fingerprint database; screens and locates candidate regions, triggering re-inspection based on uncertainty; outputs multi-dimensional detection results, and performs closed-loop updates and drift management. Summary of the Invention

[0006] In view of the existing problems mentioned above, a food impurity detection method based on spectral technology is proposed.

[0007] The technical solution adopted by this invention to solve the above-mentioned technical problems is: a food impurity detection method based on spectral technology, comprising: The system acquires spectral image data of the test object online and synchronous data from the built-in reference plate. Through real-time self-calibration, the raw data is normalized into a reflectance spectrum to form a standard spectral characterization. Motion and illumination disturbance compensation are performed on the standard spectral characterization, and a material spectral fingerprint library containing material category and source information is established based on the standard spectra of the collected impurity materials and contact component materials. The compensated spectral characterization is subjected to rapid screening and connected component extraction to obtain candidate regions. The similarity and novelty of the candidate regions with the fingerprint database are calculated. When the similarity falls into the uncertainty range or the novelty exceeds the preset threshold, local re-examination is triggered to determine the impurity category and location. The output includes multi-dimensional detection results containing impurity type, spatial location, minimum rejection window, and suspected source clues. Based on the confirmed samples, the fingerprint database and candidate screening thresholds are updated and version managed in a controlled manner.

[0008] As a preferred embodiment, the specific steps for normalizing the original data into a reflectance spectrum through real-time self-calibration to form a standard spectral characterization are as follows: A detection device is fixed above the production line conveyor belt and synchronized with a unified time base to obtain raw intensity spectral cubic data with timestamps. Within each scan line, the pixel set of the reference region corresponding to the reference plate is extracted, and the reference intensity vector for each wavelength channel is calculated using the following formula: , in This represents the wavelength channel, and t represents the timestamp. This represents the reference intensity vector of the reference plate region within the same time window. This represents the set of pixel regions of the reference plate in the image. Represents two-dimensional pixel coordinates, Represents the original spectral intensity at two-dimensional pixel coordinates (x, y); Under shading conditions, dark field intensity vectors are acquired and the dark field is updated according to a preset period. During real-time self-calibration, for each pixel of each scan line, dark current and fixed pattern noise are first eliminated by dark field subtraction, and then the same wavelength channel is normalized by reference plate intensity. The original intensity is converted into reflectance spectrum to form a standard spectral characterization. A drift criterion is set for the mean reflectance of the reference plate area. If it exceeds the preset threshold, the dark field is reacquired or the reference plate area is repositioned.

[0009] As a preferred embodiment, the specific steps for compensating for motion and illumination disturbances in the standard spectral characterization are as follows: Motion disturbance compensation is performed, scan lines are acquired, and the encoder synchronously outputs speed and pulse count. The cumulative displacement obtained by encoder integration is used as a unified spatial coordinate. The time index of each scan line is mapped to the displacement index, and resampling is performed according to the preset spatial sampling interval to obtain spectral representations with equal spacing in the transmission direction. During resampling, the reflectance spectra of two adjacent scan lines are linearly interpolated according to the displacement coordinate, and the boundary clipping is performed on the interpolated result. To perform illumination disturbance compensation, a conveyor belt reference area is pre-defined within the camera's field of view. The pixel positions of this reference area are determined through geometric calibration and written into the configuration file during installation and commissioning. Within each resampling scan line, the average reflectance of this reference area on the reference band set is calculated to obtain the reference brightness index for the current moment, using the following formula: , Where s represents the displacement coordinate. Indicates the reference brightness index. This represents the set of pixels representing a fixed reference area of ​​the conveyor belt. Represents the set of reference bands. This represents the reflectance spectrum characterization after motion compensation and resampling. Using the calibrated reference brightness as the target, the multiplicative gain compensation coefficient is calculated using the following formula: ,in Represents the reference displacement coordinates, and makes a uniform proportional correction to the reflectance spectrum across the entire band; In terms of fingerprint database construction, impurity materials and contact component materials are managed uniformly according to material entries, and the material category and source information are fixed in each entry. During database construction, each material is collected under three controlled surface states: dry, wet, and oil film. Material samples are placed in the same optical path, the same transmission direction, and the same speed range as in production to collect compensated spectral data. Material regions are obtained by threshold segmentation on the reference band for each frame of data. The mean vector and covariance matrix of multiple frames of spectral vectors of the same material under the same state are calculated as the statistical fingerprint of the material entry, and the collection date, state type, and version number are written into the index table. The fingerprint database is managed by version number only, without decrementing. When a new version is generated, the old version is retained to support auditing and backtracking.

[0010] As a preferred embodiment, the specific steps for performing rapid screening and connected component extraction on the compensated spectral characterization to obtain candidate regions are as follows: A fixed set of fast screening bands is selected from the full spectrum channels, and screening features are calculated for each pixel. ; Screening features are set to fixed thresholds Binarization is performed to obtain candidate masks. Then, morphological opening and closing operations are performed on the candidate masks to remove isolated noise and fill small holes. Finally, eight-neighbor connected component labeling is performed on the processed candidate masks to obtain a set of candidate regions. For each candidate region, calculate its centroid and the boundary of its bounding rectangle. Set an upper limit on the number of candidate regions within each unit displacement window. If the upper limit is exceeded, retain the top 10 candidate regions in descending order of their average screening features.

[0011] As a preferred embodiment, the specific steps for calculating the similarity and novelty of the candidate region with the fingerprint database are as follows: For each candidate region, the average spectral vector is extracted and its similarity is calculated with the average spectral vector of each entry in the material spectral fingerprint database. The similarity is calculated using SAM to reduce the impact of residual error in the brightness scale on the matching results. At the same time, a novelty score is calculated based on the normal food background subspace to discover unknown impurities not covered by the fingerprint database. The minimum spectral angle and novelty of the candidate region are calculated, and the similarity gray area interval and the novelty threshold are used as uncertainty triggering conditions: when the minimum spectral angle enters the similarity gray area interval, it is determined that the material matching is uncertain, or when the novelty exceeds the novelty threshold, it is determined that the anomaly outside the background is significant. Either result triggers local re-examination. In the compensated reflectance spectral characterization, the pixel set of the candidate region is read, and the mean value of the pixels in the region is calculated for each wavelength channel λ to obtain the average spectral vector of the candidate region. The average spectral vector is then normalized according to the L2 norm. Subsequently, the spectral angle is calculated for each entry in the fingerprint database, and the inner product is calculated for each entry. ,in This represents the normalized average spectral vector of the i-th candidate region. This represents the normalized mean spectral vector corresponding to the k-th material fingerprint, and then the spectral angle is calculated. The minimum spectral angle is selected, and the index k that minimizes the spectral angle is recorded as the candidate optimal material matching result. When the material category needs to be output, the material category label corresponding to the fingerprint entry k is directly output. The novelty is constructed using the residual energy of the background subspace. During the device initialization phase, the background subspace is trained with the set of regional average spectral vectors obtained from normal food samples. Principal component decomposition is performed on the set of average spectral vectors, and the first d principal component vectors are taken to form a matrix, which is then solidified into a projection matrix. During online calculation, the candidate vectors are... Calculate its projection in the background subspace and calculate the residual. Use the square of the L2 norm of the residual as the novelty score. When the online candidate satisfies the novelty score greater than the threshold, the candidate is determined to deviate from the normal food background and belong to the category of unknown impurities.

[0012] As a preferred embodiment, the specific steps for triggering local re-inspection to determine the type and location of impurities are as follows: During local re-inspection, the bounding rectangle of the candidate region is extended outwards by fixed pixel boundaries to form an extended region. Within the extended region, the average spectrum of the region is recalculated using the full spectrum channels, and the similarity and novelty evaluations are repeated. At the same time, the candidate mask is re-thresholded within the extended region to correct the boundaries. The fingerprint entry corresponding to the smallest spectral angle after re-inspection is output as the impurity category. When determining the location, the bounding rectangle boundary of the candidate region after re-inspection is used to give the pixel range of the impurity in the transmission direction and the lateral direction, and this range is bound to the displacement coordinate s to form an executable positioning result.

[0013] As a preferred embodiment, the specific steps for controlled updating and version management of the fingerprint database and candidate screening thresholds based on confirmed samples are as follows: First, the impurity type is output based on the matching fingerprint entry k determined by the re-examination. When the minimum spectral angle is less than or equal to the lower bound of the similarity gray area interval, the material category corresponding to the fingerprint entry is directly used as the impurity type. When the minimum spectral angle is greater than the upper bound of the similarity gray area interval and the novelty is greater than or equal to the novelty threshold, an unknown impurity is output along with its spectral summary. In other cases, impurities to be verified are output and the alarm level is increased. Second, the spatial position is output. The bounding rectangle is calculated based on the connected domain boundary of the candidate mask after re-examination and bound to the displacement coordinate s to form a traceable position description. The position along the conveying direction is converted from s to distance, and the lateral position is converted from pixel coordinates to millimeter coordinates according to the camera calibration ratio. When calculating the minimum rejection window, the rejection trigger center time and trigger duration window are calculated based on the geometric distance from the detection point to the rejection execution mechanism, the real-time belt speed, and the response delay of the execution mechanism. Regarding the output of suspected source clues, verifiable clues are generated by using the source information fields fixed in the fingerprint database entries. When the impurity type is a known material category, the top three source clues are output by sorting the entries in the same category from smallest to largest according to the spectral angle. The upstream time window is deduced by combining the displacement coordinates of the impurity and the belt speed, and a combination clue of the suspected component number and time window is given. Regarding controlled updates and version management, the fingerprint database and candidate screening thresholds are only updated when the sample conditions are confirmed to be met. The mean vector and covariance of the corresponding entries are updated using a small-step exponential update method, and the version number before and after the update is incremented. For confirmed unknown impurities, their spectral vector sets are clustered according to similarity to form new entries, which are written into the new version fingerprint database and recorded as newly added unknowns. A candidate screening threshold is applied. The update adopts a method of re-estimation using only the empty band background segment. After each maintenance, the distribution of the screening feature p in the empty band segment is statistically analyzed and the mean and standard deviation are recalculated. Based on this, a new threshold is generated and written into the new version parameter table.

[0014] Beneficial effects Compared with the prior art, the present invention has the following advantages: 1. By suppressing the stretching and compression caused by belt speed fluctuations through encoder displacement mapping and equal-interval resampling, and calculating the gain compensation coefficient with the reference brightness index of the conveyor belt reference area, the light source attenuation and temperature drift gain drift are offset, so that the detection results of the same impurity are consistent in different batches and different positions.

[0015] 2. Through a two-stage mechanism of rapid screening and uncertainty-triggered local re-examination, full-channel re-examination is enabled only for gray zone candidates or candidates with abnormal novelty. Without sacrificing real-time performance, threshold drift and boundary missegmentation are corrected, reducing the false rejection rate and the false negative rate. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation on the scope of this application.

[0017] Figure 1 This is a flowchart illustrating the present invention; Figure 2 This is a comparison diagram of the effects of the present invention and the prior art, where gray bars represent the prior art and black bars represent the present invention. Detailed Implementation

[0018] To make the technical means, creative features, objectives, and effects of this invention easier to understand, the invention is further described below with reference to specific embodiments. However, the following embodiments are merely preferred embodiments of this invention and not all of them. Other embodiments obtained by those skilled in the art based on the embodiments described herein without creative effort are all within the protection scope of this invention.

[0019] Example 1: To achieve the above objectives, please refer to Figures 1 to 2 This invention provides a method for detecting food impurities based on spectral technology, the method comprising the following steps: Step S1: Collect and calibrate spectral data to form a standardized spectral characterization; Step S2: Compensate for motion and illumination disturbances, and construct a material spectral fingerprint library; Step S3: Filter and locate candidate regions, and trigger a re-examination based on uncertainty; Step S4: Output multidimensional detection results and perform closed-loop update and drift management.

[0020] This method is implemented in the order of S1–S4, and its overall process is as follows: The system acquires spectral image data of the test object online and synchronous data from the built-in reference plate. Through real-time self-calibration, the raw data is normalized into a reflectance spectrum to form a standard spectral characterization. Motion and illumination disturbance compensation are performed on the standard spectral characterization, and a material spectral fingerprint library containing material category and source information is established based on the standard spectra of the collected impurity materials and contact component materials. The compensated spectral characterization is subjected to rapid screening and connected component extraction to obtain candidate regions. The similarity and novelty of the candidate regions with the fingerprint database are calculated. When the similarity falls into the uncertainty range or the novelty exceeds the preset threshold, local re-examination is triggered to determine the impurity category and location. The output includes multi-dimensional detection results containing impurity type, spatial location, minimum rejection window, and suspected source clues. Based on the confirmed samples, the fingerprint database and candidate screening thresholds are updated and version managed in a controlled manner.

[0021] S1. The specific steps for collecting and calibrating spectral data to form a standardized spectral characterization are as follows: A detection device is fixed above the production line conveyor belt, including a line-scan hyperspectral camera, a broadband illumination source, a conveyor encoder, and a built-in reference plate. The built-in reference plate is fixedly installed at the edge of the optical field of view and is under the same illumination condition as the object being tested, allowing the camera to simultaneously acquire spectral image data of both the object's region and the reference plate region in each scan line. The camera trigger, encoder pulses, and light source operating status are synchronized using a unified time reference to obtain raw intensity spectral cubic data with timestamps. The encoder generates N pulses (preferably N=1) to send a hardware trigger signal to the hyperspectral camera. Upon receiving the trigger signal, the camera begins exposure, and during exposure, a hardware signal line ensures the broadband illumination source remains stably lit. Within each scan line, the pixel set corresponding to the reference area of ​​the reference plate is extracted, and the reference intensity vector for each wavelength channel is calculated using the following formula: , in This represents the wavelength channel, and t represents the timestamp. This represents the reference intensity vector of the reference plate region within the same time window. This represents the set of pixel regions of the reference plate in the image. Represents two-dimensional pixel coordinates, Represents the original spectral intensity at two-dimensional pixel coordinates (x, y); Under shading conditions, dark field intensity vectors are acquired and updated at a preset period, preferably 60 minutes. During real-time self-calibration, for each pixel of each scan line, dark current and fixed pattern noise are first eliminated by dark field subtraction, and then the same wavelength channel is normalized using the reference plate intensity. The original intensity is converted into a reflectance spectrum to form a standard spectral characterization that is comparable across time and batches. The reflectance of the reference plate is a known calibration spectrum. The normalization calculation is performed line by line within the acquisition thread and the cubic data of the reflectance spectrum is output. To ensure online stability, a drift criterion is set for the mean reflectance of the reference plate area. If it exceeds a preset threshold, the dark field is reacquired or the reference plate area is repositioned. The reflectance benchmark is kept consistent under conditions of light source attenuation, temperature rise gain drift, and band speed change. The preset threshold is obtained by statistically analyzing the deviation distribution of the mean reflectance of the reference plate for at least 24 hours on continuously stable running samples. The threshold is taken as the 99th percentile of the deviation and rounded up, preferably 1%FS. S2. The specific steps for compensating for motion and illumination disturbances and constructing a material spectral fingerprint library are as follows: First, motion disturbance compensation is performed. Specifically, a line-scan hyperspectral camera acquires scan lines, and the conveyor belt encoder synchronously outputs speed and pulse count. The cumulative displacement obtained by encoder integration is used as a unified spatial coordinate. The time index of each scan line is mapped to the displacement index, and resampling is performed according to a preset spatial sampling interval, such as preferably 0.5 mm, to obtain spectral representations with equal spacing in the conveying direction. During resampling, the reflectance spectra of two adjacent scan lines are linearly interpolated according to the displacement coordinates, and the boundary clipping is performed on the interpolated results to ensure that the output data comes only from the effective sampling interval. Specifically, the reflectance spectra of two adjacent scan lines are linearly interpolated according to the displacement coordinates, and the interpolated results are clipped at the boundary. The line-scan hyperspectral camera continuously outputs the reflectance data of the scan lines at a fixed line frequency, with each scan line i corresponding to a time. The collected reflectivity matrix ,in For the pixel coordinates in the width direction of the conveyor belt, This is the wavelength channel; simultaneously, the conveyor belt encoder outputs a cumulative pulse count at the same time. Pre-calibrate the displacement coefficient per pulse and starting time Map the i-th scan line to the displacement coordinates based on the reference. ; with a preset spatial sampling interval A sequence of equally spaced target displacements is constructed, and a streaming two-line buffering method is used for resampling. Specifically, the previous scan line and the current scan line are buffered to maintain the target displacement to be output next. When detected At that time, when satisfied The linear interpolation coefficients are calculated under the given conditions, using the following formula: For each pixel and each wavelength channel point, interpolation is used to generate resampling scan lines, and the reflectance spectrum between two adjacent scan lines is mapped onto an equally spaced grid according to the displacement coordinates. Furthermore, illumination disturbance compensation is performed. A conveyor belt reference area is pre-defined within the camera's field of view. The pixel positions of this reference area are determined through geometric calibration and written into the configuration file during installation and debugging. Within each resampling scan line, the average reflectance of this reference area on the reference band set is calculated to obtain the reference brightness index for the current moment, using the following formula: , Where s represents the displacement coordinate. Indicates the reference brightness index. This represents the set of pixels representing a fixed reference area of ​​the conveyor belt. Represents the set of reference bands. This represents the reflectance spectrum characterization after motion compensation and resampling. Using the calibrated reference brightness as the target, the multiplicative gain compensation coefficient is calculated using the following formula: ,in It represents the reference displacement coordinates and makes a uniform proportional correction to the reflectivity spectrum across the entire band to offset the overall brightness drift caused by light source attenuation, optical path contamination, and camera gain temperature drift. In terms of fingerprint database construction, impurity materials and contact component materials are managed uniformly according to material entries, and the material category and source information are fixed in each entry. The source information records the component number, component name, and maintenance batch number in verifiable fields. During database construction, each material is collected under three controlled surface states: dry, wet, and oil film. Specifically, material samples are placed in the same optical path, the same transmission direction, and the same speed range as in production to collect no less than 50 frames of compensated spectral data. For each frame of data, the material region is obtained by threshold segmentation on the reference band, where the reference band is based on SWI, which is insensitive to changes in the food matrix and has a stable contrast for material boundaries. The R-narrow window is preferably in the 1100nm-1120nm range. The threshold is calculated from the mean and standard deviation of the background of an empty conveyor belt in this band. The mean is taken plus three times the standard deviation to ensure verifiability and stability across batches. The mean of the full-band reflectance of pixels in the material region is taken to form the material spectral vector of that frame. The mean vector and covariance matrix of the spectral vectors of multiple frames of the same material under the same condition are calculated as the statistical fingerprint of the material entry. The collection date, state type and version number are written into the index table. The fingerprint database is managed by version number only, without decrementing. When a new version is generated, the old version is retained to support auditing and backtracking, ensuring the stability and traceability of material matching and source association. S3. The specific steps for screening and locating candidate regions and triggering a re-examination based on uncertainty are as follows: First, a fixed set of fast screening bands is selected from the full spectrum channels, and screening features are calculated for each pixel. The screening feature is preferably the difference between the mean value of the reference band and the mean value of the water absorption sensitive band, in order to enhance the contrast between the food matrix and impurities such as plastics and rubber; the screening feature is applied according to a fixed threshold. Binarization is performed to obtain candidate masks, where The preferred method is to collect the p-mean value plus three times the standard deviation of the empty background band of no less than 1m; then perform morphological opening and closing operations on the candidate mask to remove isolated noise and fill small holes, and then perform eight-neighbor connected component labeling on the processed candidate mask to obtain a set of candidate regions. Specifically, the calculation of screening features for each pixel, taking into account the absorption differences of non-metallic impurities such as plastic film, rubber, and glove fragments in the short-wave infrared band, constructs pixel-level screening features using a fixed band. Specifically, the compensated reflectance spectrum is characterized as follows: Two sets of screening bands are pre-defined. The first set is a weak absorption reference window, preferably 1100nm-1120nm, used to characterize the local reflectance benchmark; the second set is an absorption sensitive window, preferably 1450nm-1470nm, used to characterize the reflectance depression characteristics of water-containing, hydroxyl-containing materials and food matrices at this location. For any pixel (x,y) at displacement coordinate s, the system calculates the mean reflectance of the two sets of bands respectively. , in This represents the set of wavelength channels with weak absorption. This refers to a set of wavelength channels that are more sensitive to differences in absorption. Then, normalized differential screening features are constructed, using the following formula: ,in This represents a fixed constant to prevent the denominator from being zero; For each candidate region, its centroid and circumscribed rectangle boundary are calculated as the initial spatial constraints for subsequent re-examination and elimination positioning. To suppress candidate outbreaks caused by complex textured food, an upper limit is set on the number of candidate regions within each unit displacement window. When the upper limit is exceeded, the top few are retained according to the average screening characteristics of the candidate regions from largest to smallest. The upper limit is preferably 10 candidate regions per 1m. Subsequently, the average spectral vector of each candidate region is extracted, and the similarity is calculated with the mean spectral vector of each entry in the material spectral fingerprint database. The similarity is calculated using SAM (spectral angle mapping) to reduce the influence of residual error in brightness scale on the matching results. At the same time, the novelty score is calculated based on the normal food background subspace to discover unknown impurities not covered by the fingerprint database. Specifically, the minimum spectral angle and novelty of the candidate region are calculated, and the similarity gray zone interval and the novelty threshold are used as uncertainty triggering conditions: when the minimum spectral angle enters the similarity gray zone interval, it is determined that the material matching is uncertain, or when the novelty exceeds the novelty threshold, it is determined that the background abnormality is significant. Either result triggers local re-examination. The similarity gray zone interval is determined experimentally. A large number of known impurity spectra and food background spectra are collected, and their minimum spectral angle with the fingerprint database is calculated. According to the confusion matrix analysis, the fuzzy interval between clear match and clear mismatch is defined as the gray zone, for example, 10° to 25°. Specifically, the calculation of the minimum spectral angle and novelty of the candidate region involves reading the pixel set of the candidate region from the compensated reflectance spectral characterization, averaging the pixels within the region for each wavelength channel λ to obtain the average spectral vector of the candidate region, normalizing the average spectral vector according to the L2 norm, and then calculating the spectral angle for each entry in the fingerprint database, and for each entry, calculating the inner product. ,in This represents the normalized average spectral vector of the i-th candidate region. This represents the normalized mean spectral vector corresponding to the k-th material fingerprint, and then the spectral angle is calculated. The minimum spectral angle is selected, and the index k that minimizes the spectral angle is recorded as the candidate optimal material matching result. When the material category needs to be output, the material category label corresponding to the fingerprint entry k is directly output. The novelty is constructed using the residual energy of the background subspace. During the device initialization phase, the background subspace is trained with the set of regional average spectral vectors obtained from normal food samples. Specifically, principal component decomposition is performed on the set of average spectral vectors, and the first d principal component vectors are taken to form a matrix, which is then solidified into a projection matrix. During online calculation, the candidate vectors are... Calculate its projection in the background subspace and calculate the residual. Use the square of the L2 norm of the residual as the novelty score. To facilitate threshold setting, the 99th percentile of the novelty distribution of normal food samples is statistically analyzed during the initialization phase and used as the threshold. This threshold is then fixed and remains unchanged during the current running cycle. When an online candidate satisfies the novelty score greater than the threshold, the candidate is determined to deviate from the normal food background and belong to the category of unknown impurities. During local re-inspection, the bounding rectangle of the candidate region is extended to form an extended region by fixed pixel boundaries. The average spectrum of the region is recalculated using the full spectrum channel only within the extended region, and the similarity and novelty evaluations are repeated. At the same time, the candidate mask is re-threshold segmented within the extended region to correct the boundary. Finally, the fingerprint entry corresponding to the smallest spectral angle after re-inspection is output as the impurity category. When determining the location, the bounding rectangle boundary of the candidate region after re-inspection is used to give the pixel range of the impurity in the transmission direction and the lateral direction. This range is bound to the displacement coordinate s to form an executable positioning result, thereby obtaining a stable impurity category and spatial location under real-time constraints. S4. The specific steps for outputting multidimensional detection results and performing closed-loop update and drift management are as follows: First, the impurity type is output based on the optimal matching fingerprint entry k determined by the re-examination: when the minimum spectral angle is less than or equal to the lower bound of the similarity gray area interval, the material category corresponding to the fingerprint entry is directly taken as the impurity type; when the minimum spectral angle is greater than the upper bound of the similarity gray area interval and the novelty is greater than or equal to the novelty threshold, an unknown impurity is output along with its spectral summary; otherwise, impurities to be verified are output and the alarm level is increased; second, the spatial position is output, the bounding rectangle is calculated based on the connected domain boundary of the candidate mask after re-examination, and it is bound to the displacement coordinate s to form a traceable position description, where the position along the conveying direction is converted from s to distance, and the lateral position is converted from pixel coordinates to millimeter coordinates according to the camera calibration ratio; when calculating the minimum rejection window, the rejection trigger center time and trigger duration window are calculated based on the geometric distance from the detection point to the rejection execution mechanism, the real-time belt speed, and the response delay of the execution mechanism; where the duration window is determined by the length of the impurity in the conveying direction and the uncertainty redundancy, and the uncertainty redundancy is converted into length using a fixed safety time; Regarding the output of suspected source clues, verifiable clues are generated by using the source information fields fixed in the fingerprint database entries. Specifically, when the impurity type is a known material category, the top three source clues are output by sorting the entries in the same category from smallest to largest according to the spectral angle. The displacement coordinates of the impurity and the belt speed are combined to deduce the upstream time window and give a combination clue of the suspected component number and time window, so that maintenance personnel can locate the wear, chipping or packaging damage of the contact components. Regarding controlled updates and version management, the fingerprint database and candidate screening thresholds are only updated when the sample conditions are confirmed to be met. The determination of confirmed samples comes from manual review after rejection. For confirmed known material categories, a small-step exponential update method is used to update the mean vector and covariance of the corresponding entries, and the version number before and after the update is incremented. The small-step exponential update uses a fixed update coefficient as the weight for the feature vector of the confirmed sample, and performs an exponential weighted fusion of the fingerprint mean based on the proportion of new samples and the proportion of historical statistics, so that the fingerprint parameters slowly adapt to the working conditions and suppress the drift caused by a single abnormal sample. For confirmed unknown impurities, their spectral vector sets are clustered according to similarity to form new entries, which are written into the new version of the fingerprint database and recorded as newly added unknowns. The candidate screening threshold is set. The update adopts a method of re-estimation using only the empty band background segment. Specifically, after each maintenance, the distribution of the screening feature p in the empty band segment is statistically analyzed and the mean and standard deviation are recalculated. Based on this, a new threshold is generated and written into the new version parameter table.

[0022] like Figure 2 A comparative graph showing the effectiveness of a food impurity detection method based on spectral technology is presented, where gray bars represent existing technologies and black bars represent the present invention. To facilitate comparability across different dimensions, the performance of existing technologies on four indicators is standardized: false rejection rate, false negative rate, positioning error, and recalibration frequency. The false rejection rate characterizes the proportion of good products mistakenly rejected; the false negative rate characterizes the proportion of impurities not detected; the positioning error characterizes the deviation level between the impurity's spatial boundary and the rejection position; and the recalibration frequency characterizes the frequency triggered by light drift and gain temperature drift. The calibration and maintenance frequency was measured. To unify them as positive indicators, the false rejection rate, missed detection rate, positioning error, and recalibration frequency were all converted into positive effect indices by decreasing the corresponding index and increasing the index. The comparative results show that the present invention establishes a comparable spectral benchmark through online reflectivity self-calibration, and implements two-stage screening and uncertainty-triggered local re-inspection after motion and illumination disturbance compensation. At the same time, combined with controlled updates and version management of the fingerprint database, the false rejection and missed detection rates are reduced simultaneously, the positioning accuracy is improved, and the recalibration frequency is reduced. This reduces the loss of good products, reduces the risk of safety missed detection, and improves stability under high-speed production line conditions.

[0023] Example 2: Based on the above-described Example 1, a food impurity detection method based on spectral technology is proposed for online impurity detection in high-speed production lines, specifically as follows: Step 1: Install a line-scan SWIR hyperspectral camera and a broadband illumination source above the discharge conveyor belt. Install an encoder on the side of the conveyor belt and fix an oil-resistant diffuse reflection reference plate at the edge of the camera's field of view, so that each scan line simultaneously covers the discharge area and the reference plate area. Use the encoder pulse as a spatial synchronization reference. Each pulse generated by the encoder triggers the camera to acquire one scan line. During camera exposure, the illumination source is kept constantly lit through hardware linkage to avoid flickering errors caused by high-speed movement. For each scan line, extract the reference intensity vector of each wavelength channel from the reference plate ROI and record it synchronously with the original intensity of the food area being tested. At the same time, dark field acquisition is performed in the equipment maintenance window and refreshed at a 60-minute cycle. During online calibration, dark field subtraction is performed on each pixel of the food area first, and then the reflectance spectrum is normalized to the same wavelength according to the known reflectance calibration spectrum of the reference plate to obtain the reflectance spectrum, thereby stably mapping the difference in reflectance between the transparent plastic film fragments and the food surface to the standard spectral characterization. When the mean reflectance of the reference plate deviates from the reference by more than 1%FS, dark field resampling or reference plate ROI repositioning is triggered to maintain reference consistency. Step 2: Read the encoder displacement and map the continuously acquired scan lines from the camera onto the displacement axis, generating an equidistant displacement grid at 0.5mm intervals. When the displacements of two adjacent scan lines are not equidistant, reconstruct the intermediate scan line by linearly interpolating the reflectance of the two lines channel by channel according to the displacement ratio, and perform clipping on the insufficient coverage areas at the beginning and end to obtain an unstretched equidistant spectral sequence. Then, select a constant exposed conveyor belt reference area at the edge of the field of view, calculate its average reflectance in 1100–1120nm as the reference brightness, and calculate the gain coefficient based on the reference brightness at power-on calibration, uniformly correcting the reflectance across the entire band to offset lamp attenuation and temperature drift. When constructing the fingerprint database, collect materials of contact components such as gloves, PET films, and conveyor belt baffles. Collect 50 frames each in dry, wet, and oil film states, segment the sample area according to the background mean of 1100–1120nm + 3σ threshold, take the mean of the entire band of the sample area to obtain the spectral vector, calculate the mean and covariance, and write the fingerprint entries containing material category and source component number to form a traceable database. Step 3: For the compensated reflectance spectrum, only two sets of rapid screening bands are selected: 1100–1120nm as the reference window and 1450–1470nm as the absorption sensitive window. The mean reflectance A and B of the two windows are calculated for each pixel, and screening features are constructed. After powering on, a 1m empty band background is collected, and the mean and standard deviation of the screening features are statistically analyzed. The threshold is fixed, and the candidate mask is obtained by binarization. After performing opening and closing operations on the candidate mask, the eight-neighbor connected component is marked to obtain candidate regions, which are limited to a maximum of 10 per 1m. The full-band average spectral vector is extracted for each candidate region, and the SAM spectral angle is calculated with the fingerprint database entries and the minimum value is taken. At the same time, the residual novelty is calculated using the PCA subspace of normal food background. When the minimum spectral angle falls into the gray area or the novelty exceeds the threshold, full-channel re-examination is enabled only for the local area 20 pixels outside the candidate bounding box. The angle and novelty are recalculated and the boundary is corrected. Finally, the impurity category and pixel location range are output. Step 4: For candidate regions after re-inspection, if the minimum spectral angle meets the determined matching threshold, the corresponding material category is output; if the spectral angle exceeds the rejection threshold and the novelty exceeds the threshold, it is marked as an unknown impurity and its full-band mean spectral summary is output; the rest are marked as pending verification and the alarm level is increased; when outputting the location, the horizontal pixel range is given by the bounding box of the connected domain after re-inspection, and the encoder displacement is converted into the distance in the conveying direction, thus forming a millimeter-level two-dimensional coordinate and timestamp traceable positioning; when the rejection is executed, the trigger time is calculated based on the detection point distance D, the real-time belt speed and the valve response delay, and the minimum rejection window is generated by adding the safety redundancy time to the length of the impurity along the conveying direction; when the source clue is output, the top three source component numbers are output in the same fingerprint entries of PET and rubber according to the spectral angle, and the time window of the upstream packaging film guide roller or baffle station is pushed back in combination with the belt speed; the confirmed sample is returned by the sampling inspection after rejection, and after confirmation, the corresponding material fingerprint statistics are updated in small steps and the version is incremented; after maintenance, a 1m empty belt background is collected to recalculate the candidate threshold and write it into the new version parameter table.

[0024] The embodiments of the present invention described above are subject to modification and change of method by those skilled in the art without departing from the embodiments and broader aspects of the present invention. The appended claims are intended to include all such modifications and changes of method that do not depart from the present invention.

Claims

1. A method for detecting food impurities based on spectral technology, characterized in that, include: The system acquires spectral image data of the test object online and synchronous data from the built-in reference plate. Through real-time self-calibration, the raw data is normalized into a reflectance spectrum to form a standard spectral characterization. Motion and illumination disturbance compensation are performed on the standard spectral characterization, and a material spectral fingerprint library containing material category and source information is established based on the standard spectra of the collected impurity materials and contact component materials. The compensated spectral characterization is subjected to rapid screening and connected component extraction to obtain candidate regions. The similarity and novelty of the candidate regions with the fingerprint database are calculated. When the similarity falls into the uncertainty range or the novelty exceeds the preset threshold, local re-examination is triggered to determine the impurity category and location. The output includes multi-dimensional detection results containing impurity type, spatial location, minimum rejection window, and suspected source clues. Based on the confirmed samples, the fingerprint database and candidate screening thresholds are updated and version managed in a controlled manner.

2. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The specific steps for normalizing the raw data into a reflectance spectrum through real-time self-calibration to form a standard spectral characterization are as follows: A detection device is fixed above the production line conveyor belt and synchronized with a unified time base to obtain raw intensity spectral cubic data with timestamps. Within each scan line, the pixel set of the reference region corresponding to the reference plate is extracted, and the reference intensity vector for each wavelength channel is calculated using the following formula: , in This represents the wavelength channel, and t represents the timestamp. This represents the reference intensity vector of the reference plate region within the same time window. This represents the set of pixel regions of the reference plate in the image. Represents two-dimensional pixel coordinates, This represents the original spectral intensity at the two-dimensional pixel coordinates (x, y).

3. The food impurity detection method based on spectral technology according to claim 2, characterized in that, The specific steps for normalizing the raw data into a reflectance spectrum through real-time self-calibration to form a standard spectral characterization also include: Under shading conditions, dark field intensity vectors are acquired and the dark field is updated according to a preset period. During real-time self-calibration, for each pixel of each scan line, dark current and fixed pattern noise are first eliminated by dark field subtraction, and then the same wavelength channel is normalized by reference plate intensity. The original intensity is converted into reflectance spectrum to form a standard spectral characterization. A drift criterion is set for the mean reflectance of the reference plate area. If it exceeds the preset threshold, the dark field is reacquired or the reference plate area is repositioned.

4. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The specific steps for compensating for motion and illumination disturbances in the standard spectral characterization are as follows: Motion disturbance compensation is performed, scan lines are acquired, and the encoder synchronously outputs speed and pulse count. The cumulative displacement obtained by encoder integration is used as a unified spatial coordinate. The time index of each scan line is mapped to the displacement index, and resampling is performed according to the preset spatial sampling interval to obtain spectral representations with equal spacing in the transmission direction. During resampling, the reflectance spectra of two adjacent scan lines are linearly interpolated according to the displacement coordinate, and the boundary clipping is performed on the interpolated result. To perform illumination disturbance compensation, a conveyor belt reference area is pre-defined within the camera's field of view. The pixel positions of this reference area are determined through geometric calibration and written into the configuration file during installation and commissioning. Within each resampling scan line, the average reflectance of this reference area on the reference band set is calculated to obtain the reference brightness index for the current moment, using the following formula: , Where s represents the displacement coordinate. Indicates the reference brightness index. This represents the set of pixels representing a fixed reference area of ​​the conveyor belt. Represents the set of reference bands. This represents the reflectance spectrum characterization after motion compensation and resampling.

5. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The specific steps for establishing a material spectral fingerprint database containing material category and source information are as follows: Using the calibrated reference brightness as the target, the multiplicative gain compensation coefficient is calculated using the following formula: ,in Represents the reference displacement coordinates, and makes a uniform proportional correction to the reflectance spectrum across the entire band; In terms of fingerprint database construction, impurity materials and contact component materials are managed uniformly according to material entries, and the material category and source information are fixed in each entry. During database construction, each material is collected in three controlled surface states: dry, wet, and oil film. The material samples are placed in the same optical path, the same transmission direction, and the same speed range as the production to collect compensated spectral data. The material region is obtained by threshold segmentation on the reference band for each frame of data. For multiple frames of spectral vectors of the same material under the same condition, the mean vector and covariance matrix are calculated as statistical fingerprints of the material entry, and the collection date, state type and version number are written into the index table. The fingerprint database is managed by version number, which only increases and never decreases. When a new version is generated, the old version is retained to support auditing and backtracking.

6. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The specific steps for performing rapid screening and connected component extraction on the compensated spectral characterization to obtain candidate regions are as follows: A fixed set of fast screening bands is selected from the full spectrum channels, and screening features are calculated for each pixel. ; Screening features are set to fixed thresholds Binarization is performed to obtain candidate masks. Then, morphological opening and closing operations are performed on the candidate masks to remove isolated noise and fill small holes. Finally, eight-neighbor connected component labeling is performed on the processed candidate masks to obtain a set of candidate regions. For each candidate region, calculate its centroid and the boundary of its bounding rectangle. Set an upper limit on the number of candidate regions within each unit displacement window. If the upper limit is exceeded, retain the top 10 candidate regions in descending order of their average screening features.

7. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The specific steps for calculating the similarity and novelty of candidate regions with the fingerprint database are as follows: For each candidate region, the region-averaged spectral vector is extracted and the similarity is calculated with the spectral mean vector of each entry in the material spectral fingerprint database. The similarity is calculated using SAM to reduce the influence of brightness scale residual error on the matching results. At the same time, the novelty score is calculated based on the normal food background subspace to discover unknown impurities not covered by the fingerprint database. The minimum spectral angle and novelty of the candidate region are calculated, and the similarity gray area interval and the novelty threshold are used as uncertainty triggering conditions: when the minimum spectral angle enters the similarity gray area interval, it is determined that the material matching is uncertain, or when the novelty exceeds the novelty threshold, it is determined that the background abnormality is significant. Either result triggers local re-examination.

8. The food impurity detection method based on spectral technology according to claim 7, characterized in that, The specific steps for calculating the similarity and novelty of candidate regions with the fingerprint database also include: In the compensated reflectance spectral characterization, the pixel set of the candidate region is read, and the mean value of the pixels in the region is calculated for each wavelength channel λ to obtain the average spectral vector of the candidate region. The average spectral vector is then normalized according to the L2 norm. Subsequently, the spectral angle is calculated for each entry in the fingerprint database, and the inner product is calculated for each entry. ,in This represents the normalized average spectral vector of the i-th candidate region. This represents the normalized mean spectral vector corresponding to the k-th material fingerprint, and then the spectral angle is calculated. The minimum spectral angle is selected, and the index k that minimizes the spectral angle is recorded as the candidate optimal material matching result. When the material category needs to be output, the material category label corresponding to the fingerprint entry k is directly output. The novelty is constructed using the residual energy of the background subspace. During the device initialization phase, the background subspace is trained with the set of regional average spectral vectors obtained from normal food samples. Principal component decomposition is performed on the set of average spectral vectors, and the first d principal component vectors are taken to form a matrix, which is then solidified into a projection matrix. During online calculation, the candidate vectors are... Calculate its projection in the background subspace and calculate the residual. Use the square of the L2 norm of the residual as the novelty score. When the online candidate satisfies the novelty score greater than the threshold, the candidate is determined to deviate from the normal food background and belong to the category of unknown impurities.

9. The method for detecting food impurities based on spectral technology according to claim 1, characterized in that, The specific steps for triggering local re-inspection to determine the type and location of impurities are as follows: During local re-inspection, the bounding rectangle of the candidate region is extended outwards by fixed pixel boundaries to form an extended region. Within the extended region, the average spectrum of the region is recalculated using the full spectrum channels, and the similarity and novelty evaluations are repeated. At the same time, the candidate mask is re-thresholded within the extended region to correct the boundaries. The fingerprint entry corresponding to the smallest spectral angle after re-inspection is output as the impurity category. When determining the location, the bounding rectangle boundary of the candidate region after re-inspection is used to give the pixel range of the impurity in the transmission direction and the lateral direction, and this range is bound to the displacement coordinate s to form an executable positioning result.

10. The method for detecting food impurities based on spectral technology according to claim 1, characterized in that, The specific steps for controlled updates and version management of the fingerprint database and candidate screening thresholds based on confirmed samples are as follows: First, the impurity type is output based on the matching fingerprint entry k determined by the re-examination. When the minimum spectral angle is less than or equal to the lower bound of the similarity gray area interval, the material category corresponding to the fingerprint entry is directly used as the impurity type. When the minimum spectral angle is greater than the upper bound of the similarity gray area interval and the novelty is greater than or equal to the novelty threshold, an unknown impurity is output along with its spectral summary. In other cases, impurities to be verified are output and the alarm level is increased. Second, the spatial position is output. The bounding rectangle is calculated based on the connected domain boundary of the candidate mask after re-examination and bound to the displacement coordinate s to form a traceable position description. The position along the conveying direction is converted from s to distance, and the lateral position is converted from pixel coordinates to millimeter coordinates according to the camera calibration ratio. When calculating the minimum rejection window, the rejection trigger center time and trigger duration window are calculated based on the geometric distance from the detection point to the rejection execution mechanism, the real-time belt speed, and the response delay of the execution mechanism. Regarding the output of suspected source clues, verifiable clues are generated by using the source information fields fixed in the fingerprint database entries. When the impurity type is a known material category, the top three source clues are output by sorting the entries in the same category from smallest to largest according to the spectral angle. The upstream time window is deduced by combining the displacement coordinates of the impurity and the belt speed, and a combination clue of the suspected component number and time window is given. Regarding controlled updates and version management, the fingerprint database and candidate screening thresholds are only updated when the sample conditions are confirmed to be met. The mean vector and covariance of the corresponding entries are updated using a small-step exponential update method, and the version number before and after the update is incremented. For confirmed unknown impurities, their spectral vector sets are clustered according to similarity to form new entries, which are written into the new version fingerprint database and recorded as newly added unknowns. A candidate screening threshold is applied. The update adopts a method of re-estimation using only the empty band background segment. After each maintenance, the distribution of the screening feature p in the empty band segment is statistically analyzed and the mean and standard deviation are recalculated. Based on this, a new threshold is generated and written into the new version parameter table.

Citation Information

Patent Citations

  • Food impurity detection method based on spectral technology

    CN119809998B