A method and system for optical non-destructive testing of surface defects of a cigarette case

CN123015517APending Publication Date: 2026-10-30GUANGDONG YUCAI INTELLIGENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611343990.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-01
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]本发明的目的在于提供一种烟盒表面缺陷光学无损检测方法及系统,旨在解决因烟盒空间位姿偏移导致材质边界与预设补偿分区边界错位,进而引起高亮伪影并导致合格品误判的技术问题,能够实时感知烟盒物理边界偏移,通过动态生成条带过渡区域并进行像素级参数修正,有效消除材质边界错位带来的高亮伪影,显著提升检测系统的鲁棒性与准确率

Benefits of technology

生成模块,用于根据修正前的所述边界条带过渡区域内像素点的分布特征,生成置信度权重映射图;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123015517A_ABST
    Figure CN123015517A_ABST
Patent Text Reader

Abstract

The application provides a cigarette case surface defect optical nondestructive detection method and system, and relates to the technical field of machine vision detection. The method comprises the following steps: obtaining the actual material boundary of the cigarette case, comparing the actual material boundary with the preset compensation partition boundary, identifying the mispositioned area and determining the transition area. For the transition area, the dynamic compensation parameter is calculated according to the spatial distance of the pixel to the boundary and the image is corrected; then the confidence weight mapping graph is generated according to the pixel distribution characteristics; finally, the corrected image and the confidence weight are fused to obtain the final detection image for surface defect detection. The method improves the detection accuracy through boundary compensation and confidence weighting. The method of the application aims to solve the technical problem that the material boundary is mispositioned with the preset compensation partition boundary due to the spatial pose offset of the cigarette case, which further causes highlight artifacts and leads to misjudgment of qualified products. The highlight artifacts caused by the mispositioning of the material boundary can be effectively eliminated, and the robustness and accuracy of the detection system are significantly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine vision inspection technology, and more specifically, to a method and system for optical non-destructive testing of surface defects in cigarette boxes. Background Technology

[0002] In automated production lines of high-end equipment manufacturing, non-contact, non-destructive online defect detection of cigarette boxes with locally highly reflective decorations such as hot stamping and coating is typically performed using multi-angle polarized light sources combined with spectral analysis technology for optical imaging. A dynamic compensation model is then used to apply pre-calibrated compensation parameters to the polarized image for regional compensation. Subsequently, a multi-scale image fusion algorithm generates a high-contrast image to trigger defect detection. However, in actual online inspection of cigarette boxes with large areas of hot stamping patterns, sub-millimeter-level spatial pose shifts often occur on the conveyor belt due to mechanical vibration and material position tolerances. This physical displacement causes the actual physical boundary of the hot stamping pattern on the cigarette box to not completely coincide with the preset compensation zone boundary in the dynamic compensation model. When the physical boundary of the hot stamping area shifts outside the preset high compensation zone and falls into the adjacent low compensation zone, the dynamic compensation model incorrectly matches a lower extinction coefficient to these boundary strip pixels at the material interface. This spatial jump in compensation parameters results in the ineffective suppression of localized strong reflections, forming abnormally bright strip artifacts in the image. Existing compensation methods based on offline fixed calibration partitions struggle to dynamically perceive and adapt to such real-time, minute physical offsets. This causes multi-scale image fusion algorithms to treat these bright artifacts as signals with obvious edge features when processing high-frequency details, preserving and enhancing them. Consequently, the normal hot stamping edges on the surface of qualified cigarette boxes are incorrectly identified as linear false defects, leading to the misjudgment and rejection of qualified products. Therefore, when performing polarization spectral detection on cigarette boxes with locally highly reflective patterns on automated production lines, if the spatial pose shift of the cigarette box due to transmission jitter causes misalignment between the material's physical boundaries and the preset compensation partition boundaries, the dynamic compensation model's mismatch of the extinction coefficient for boundary pixels will result in unsuppressed local reflections, forming bright artifacts. These artifacts are then amplified by the fusion algorithm as false defects, leading to a decrease in detection accuracy. This is a technical problem that urgently needs to be solved.

[0003] To address the aforementioned issues, existing technologies urgently need improvement. Summary of the Invention

[0004] The purpose of this invention is to provide an optical non-destructive testing method and system for cigarette box surface defects. It aims to solve the technical problem that misalignment between the material boundary and the preset compensation zone boundary caused by the spatial pose offset of the cigarette box leads to high-brightness artifacts and misjudgment of qualified products. The invention can detect the physical boundary offset of the cigarette box in real time, and effectively eliminate the high-brightness artifacts caused by the material boundary misalignment by dynamically generating strip transition areas and performing pixel-level parameter correction, thereby significantly improving the robustness and accuracy of the detection system.

[0005] In a first aspect, the present invention provides an optical non-destructive testing method for surface defects in cigarette boxes, comprising the following steps: S1. Obtain the actual material boundary of the cigarette box to be tested in the current frame image; S2. By comparing the actual material boundary with the preset compensation partition boundary, the boundary misalignment area is identified, and based on the boundary misalignment area, the boundary strip transition area is determined; the boundary strip transition area is used to correct the boundary misalignment area. S3. For the boundary strip transition region, calculate the dynamic compensation parameter of each pixel based on the spatial distance from the pixel in the boundary strip transition region to the actual material boundary, and perform compensation correction based on the dynamic compensation parameter to obtain the compensated image of the boundary strip transition region after correction. S4. Generate a confidence weight mapping map based on the distribution characteristics of pixels in the transition area of ​​the boundary strip before correction; S5. Based on the corrected compensated image and the confidence weight mapping, the final detection image is obtained by reconstructing the image, and the surface defects of the cigarette box to be tested are detected using the final detection image. The optical non-destructive testing method for surface defects of cigarette boxes provided by this invention has the advantages of being able to dynamically sense and adapt to the slight physical pose shift of the cigarette box during transmission, effectively eliminating the bright strip artifacts caused by the misalignment of material boundaries and compensation zone boundaries, thereby significantly reducing the false judgment rate of qualified products and improving the detection accuracy.

[0006] In a preferred embodiment, the actual material boundary includes pixel-level coordinates of the intersection of different materials.

[0007] Further optimization of the solution, the specific steps in step S1 include: S11. Acquire multi-polarization state images of the cigarette box to be tested; S12. Based on the multi-polarization state image, calculate the total light intensity image and the polarization degree image; S13. Based on adaptive weights that characterize local material differences, a comprehensive gradient field is generated by weighted fusion of the gradient information of the total light intensity image and the polarization degree image; S14. Perform edge detection on the integrated gradient field, and obtain the pixel-level coordinates of the actual material boundary by performing sub-pixel-level positioning on the edge detection results.

[0008] In the preferred embodiment, step S2, which involves comparing the actual material boundary with the preset compensation partition boundary to identify the boundary misalignment area, includes the following specific steps: S21. Calculate the shortest Euclidean distance from each sampling point on the actual material boundary to the compensation partition boundary, and compare the shortest Euclidean distance with a preset tolerance threshold to identify the boundary misalignment area.

[0009] In the preferred embodiment, step S2, based on the identified boundary misalignment region, includes the following specific steps for determining the boundary strip transition region: S22. Calculate the average normal offset of the boundary misalignment region, and based on the average normal offset, take the actual material boundary as the center and expand to both sides of the width to obtain the boundary strip transition region.

[0010] In a preferred embodiment, the spatial distance is a directed symbolic distance.

[0011] In a further preferred embodiment, step S3, the specific steps for calculating the dynamic compensation parameters of each pixel based on the spatial distance from the pixel within the boundary strip transition area to the actual material boundary, include: S31. Based on the directed sign distance from the pixel point in the boundary strip transition area to the actual material boundary, a mapping function is constructed to obtain the compensation weight of each pixel point; S32. Based on the compensation weight, and combined with the preset compensation coefficients for the high-reflectivity area and the normal area, calculate the dynamic compensation parameters for each pixel.

[0012] In a preferred embodiment, the confidence weight map includes the defect trigger confidence weight of each pixel within the boundary strip transition area.

[0013] A further preferred embodiment, the specific steps in step S4 include: S41. Obtain the local gradient magnitude and local gradient direction of each pixel within the boundary strip transition area, and obtain the normal direction of the actual material boundary; S42. Based on the relative relationship between the local gradient magnitude, the local gradient direction and the normal direction of the actual material boundary, determine the defect trigger confidence weight of each pixel in the boundary strip transition area, and generate the confidence weight mapping map based on the defect trigger confidence weight.

[0014] Secondly, the present invention provides an optical non-destructive testing system for surface defects in cigarette boxes, comprising: The acquisition module is used to obtain the actual material boundary of the cigarette box to be tested in the current frame image; The identification module is used to identify boundary misalignment areas by comparing the actual material boundary with the preset compensation partition boundary, and to determine the boundary strip transition area based on the boundary misalignment area; the boundary strip transition area is used to correct the boundary misalignment area. The compensation module is used to calculate the dynamic compensation parameters of each pixel in the boundary strip transition area based on the spatial distance from the pixel in the boundary strip transition area to the actual material boundary, and to perform compensation correction based on the dynamic compensation parameters to obtain the compensated image of the boundary strip transition area after correction. The generation module is used to generate a confidence weight mapping map based on the distribution characteristics of pixels in the transition area of ​​the boundary strip before correction. The reconstruction module is used to obtain the final detection image by reconstructing the image based on the corrected compensated image and the confidence weight mapping map, and to detect surface defects of the cigarette box to be tested using the final detection image.

[0015] As can be seen from the above, the optical non-destructive testing method for cigarette box surface defects provided by this invention introduces a dynamic boundary perception and compensation mechanism. Based on obtaining the actual material boundary of the cigarette box, it accurately identifies the boundary misalignment area caused by pose offset by comparing it with the preset compensation partition boundary, and constructs a transition strip. By dynamically compensating and correcting the transition area based on directed sign distance, the high-brightness artifacts caused by the jump in compensation coefficient at the material interface are eliminated. At the same time, combined with pixel-level confidence weight mapping, the fused detection image is filtered, fundamentally solving the problem of false high-brightness defects caused by cigarette box transmission jitter, ensuring accurate detection of cigarette boxes with complex hot stamping patterns, and significantly improving the finished product qualification rate of automated production lines.

[0016] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing embodiments of the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings. Attached Figure Description

[0017] Figure 1 This is a flowchart of an optical non-destructive testing method for surface defects in cigarette boxes provided in an embodiment of the present invention.

[0018] Figure 2 This is a schematic diagram of a non-destructive testing system for surface defects in cigarette boxes provided in an embodiment of the present invention.

[0019] Label Explanation: 100. Acquisition Module; 200. Recognition Module; 300. Compensation Module; 400. Generation Module; 500. Reconstruction Module. Detailed Implementation

[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0021] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0022] In automated production lines of high-end equipment manufacturing, non-contact, non-destructive online defect detection of cigarette boxes with locally highly reflective decorations such as hot stamping and coating typically employs multi-angle polarized light sources combined with spectral analysis for optical imaging. A dynamic compensation model is then used to apply pre-calibrated compensation parameters to the polarized image for regional compensation. Subsequently, a multi-scale image fusion algorithm generates a high-contrast image to trigger defect detection. However, in practical applications, due to mechanical vibration and material position tolerances, cigarette boxes often experience sub-millimeter-level spatial pose shifts on the conveyor belt. This physical displacement causes the actual physical boundary of the hot stamping pattern on the cigarette box to not completely coincide with the preset compensation zone boundary in the dynamic compensation model. When the physical boundary of the hot stamping area shifts outside the preset high compensation zone and falls into the adjacent low compensation zone, the dynamic compensation model incorrectly matches a lower extinction coefficient to these boundary strip pixels at the material interface. This spatial jump in compensation parameters results in the ineffective suppression of locally strong reflections, forming abnormally bright strip artifacts in the image. Existing compensation methods based on offline fixed calibration partitions are difficult to dynamically perceive and adapt to such real-time minute physical offsets. As a result, when processing high-frequency details, multi-scale image fusion algorithms will treat this bright artifact as a signal with obvious edge features and retain and enhance it. This causes the normal hot stamping edges on the surface of qualified cigarette boxes to be incorrectly identified as linear false defects, resulting in qualified products being wrongly rejected.

[0023] Specifically, in the online inspection scenario of cigarette boxes with large-area gold foil patterns, when the cigarette box experiences spatial pose shift due to transmission jitter, the physical boundaries of the material and the boundaries of the preset compensation zones become misaligned. At this time, the dynamic compensation model mismatches the extinction coefficient for the boundary pixels, causing local reflections to be unsuppressed and forming bright artifacts, which are then amplified by the fusion algorithm into false defects. On high-speed production lines, this phenomenon manifests as the inspection system falsely triggering normal gold foil edges, leading to a decrease in inspection accuracy and severely restricting the reliability of automated inspection systems.

[0024] If the problem of mismatch between the actual material boundary and the preset compensation zone boundary caused by the spatial pose offset of the cigarette box is not resolved, which leads to the mismatch of dynamic compensation model parameters, resulting in bright artifacts and causing qualified products to be misjudged as defects, the automated inspection system will be unable to maintain stable inspection performance when faced with slight pose fluctuations. This will cause a large number of qualified products to be incorrectly rejected due to artifact interference, which will not only increase the rework cost of the production line, but also reduce the automation level and production efficiency of the overall inspection process. Therefore, technical improvements to address this problem are necessary.

[0025] For reference, see the appendix. Figure 1 This invention provides a method for optical non-destructive testing of surface defects in cigarette boxes, comprising the following steps: S1. Obtain the actual material boundary of the cigarette box to be tested in the current frame image; the actual material boundary includes the pixel-level coordinates of the intersection of different materials; S2. By comparing the actual material boundary with the preset compensation zone boundary, the boundary misalignment area is identified, and based on the boundary misalignment area, the boundary strip transition area is determined; the boundary strip transition area is used to correct the boundary misalignment area. S3. For the boundary strip transition region, calculate the dynamic compensation parameter of each pixel based on the spatial distance from the pixel in the boundary strip transition region to the actual material boundary, and perform compensation correction based on the dynamic compensation parameter to obtain the compensated image of the boundary strip transition region after correction; the spatial distance is the directed signed distance. S4. Generate a confidence weight map based on the distribution characteristics of pixels in the transition area of ​​the boundary strip before correction; the confidence weight map contains the defect trigger confidence weight of each pixel in the transition area of ​​the boundary strip. S5. Based on the corrected compensated image and confidence weight mapping, the final detection image is obtained by reconstructing the image, and the surface defects of the cigarette box to be tested are detected using the final detection image.

[0026] For ease of understanding, the following explains some key terms in this embodiment: Actual material boundary: refers to the real physical boundary between different materials on the surface of the cigarette box being tested (e.g., the hot stamping area and the ordinary printing area). This boundary is represented by pixel-level coordinates, which can accurately reflect the position of the material interface.

[0027] Compensation zone boundaries: These refer to the virtual boundaries pre-defined in traditional dynamic compensation models to divide different compensation zones. These boundaries are typically determined based on standard design drawings of cigarette boxes or offline calibration results.

[0028] Boundary misalignment region: This refers to the area where the actual material boundary does not spatially coincide with the preset compensation zone boundary due to the pose shift of the cigarette box on the conveyor belt. Within this region, traditional compensation models may incorrectly apply compensation parameters.

[0029] Boundary strip transition region: This refers to a local image region defined to correct boundary misalignment. Centered on the actual material boundary, this region extends a certain width to both sides, aiming to provide a smooth transition band for compensation parameters, eliminating abrupt changes in compensation parameters caused by boundary misalignment.

[0030] Dynamic compensation parameters: These are compensation coefficients calculated for each pixel within the boundary strip transition area, based on factors such as its spatial distance to the actual material boundary, and used for suppressing or enhancing reflections. These parameters enable adaptive adjustment of the compensation.

[0031] Confidence weight map: This refers to an image with the same resolution as the original image, where each pixel value represents the confidence level of the probability that a high-frequency edge signal appearing at that location belongs to a real defect. This map is used to guide the enhancement of defect signals and the suppression of artifact signals during image reconstruction.

[0032] Directed signed distance: refers to the distance from a pixel to the actual material boundary, and includes directional information. For example, pixels located on the side of highly reflective material have a positive distance, while pixels located on the side of ordinary printed material have a negative distance. This helps to distinguish the material region where a pixel is located.

[0033] This application provides an optical non-destructive testing method for surface defects of cigarette boxes, which aims to solve the problem that in the optical non-destructive testing of surface defects of cigarette boxes, the spatial pose shift of the cigarette box during the transportation process causes the actual material boundary to not coincide with the boundary of the preset compensation zone, which in turn leads to the mismatch of dynamic compensation model parameters, resulting in high-brightness artifacts and causing qualified products to be misjudged as defects.

[0034] This method first obtains the actual material boundaries of the cigarette box under test in the current frame image. The actual material boundaries include pixel-level coordinates of the intersections of different materials. For example, image processing techniques, such as edge detection algorithms, can be used to identify the boundary between the hot-stamped area and the ordinary printed area on the cigarette box surface. In one implementation, a grayscale thresholding method can be used to identify the boundaries of areas with significant brightness differences in the image as the actual material boundaries. However, this method may lack sufficient accuracy in identifying areas with uneven lighting or low material contrast. In another implementation, a texture analysis-based method can be used to determine the material boundaries by calculating the differences in local texture features. However, this method has high computational complexity and may limit real-time performance.

[0035] Next, by comparing the actual material boundary with the preset compensation partition boundary, boundary misalignment regions are identified, and boundary strip transition regions are determined based on these regions. These boundary strip transition regions are used to correct boundary misalignment regions. For example, the pixel coordinates of the actual material boundary can be compared point-by-point with the pixel coordinates of the preset compensation partition boundary, and the distance between them can be calculated. If the distance exceeds a preset threshold, the region is considered to have boundary misalignment. In one implementation, a logical XOR operation can be performed on the actual material boundary and the preset compensation partition boundary to obtain non-overlapping areas as boundary misalignment regions. However, this method may not accurately quantify the degree of misalignment and cannot effectively handle sub-pixel level offsets. In another implementation, an image registration-based method can be used to align the actual material boundary with the preset compensation partition boundary, and the misalignment region can be identified by calculating the registration error. However, this method consumes significant computational resources and may not be suitable for high-speed online detection scenarios.

[0036] Then, for the boundary strip transition region, dynamic compensation parameters for each pixel are calculated based on the spatial distance from the pixel within the boundary strip transition region to the actual material boundary. Compensation correction is then performed based on these dynamic compensation parameters to obtain the compensated image for the boundary strip transition region. The spatial distance is a directed signed distance. For example, for each pixel within the boundary strip transition region, its Euclidean distance to the actual material boundary can be calculated, and a positive or negative sign can be assigned based on which side of the actual material boundary it is located on. Then, based on this directed signed distance, the dynamic compensation parameters for that pixel are calculated using a preset mapping function. In one implementation, linear interpolation can be used to adjust the compensation parameters within a linear range based on the distance from the pixel to the actual material boundary. However, this method may cause abrupt changes in the compensation parameters at the material boundary, failing to achieve a smooth transition. In another implementation, a piecewise function can be used to divide the boundary strip transition region into multiple sub-regions, each using different compensation parameters. However, this method may result in discontinuous compensation parameters at the boundaries of the sub-regions.

[0037] Subsequently, a confidence weight map is generated based on the distribution characteristics of pixels within the boundary strip transition region before correction. The confidence weight map contains the defect triggering confidence weight for each pixel within the boundary strip transition region. For example, the local gradient magnitude and direction of pixels within the boundary strip transition region, and their relative relationship with the normal direction of the actual material boundary, can be analyzed. If the local gradient direction of a pixel is highly parallel to the normal direction of the actual material boundary, the pixel is considered more likely to be a normal edge at the material interface, and its defect triggering confidence weight is low. Conversely, if the local gradient direction has a significant angle with the normal direction, the pixel is considered more likely to be a real defect, and its defect triggering confidence weight is high. In one implementation, the weight can be simply set based on the distance of the pixel to the actual material boundary, with a lower weight for closer pixels. However, this method may not be able to distinguish between normal textures parallel to the boundary and real scratches perpendicular to the boundary. In another implementation, a method based on local variance can be used, with a lower weight for larger variances. However, this method may be sensitive to noise and cannot accurately reflect the confidence of defects.

[0038] Finally, based on the corrected compensated image and the confidence weight map, the final detection image is obtained by reconstructing the image, and then used to detect surface defects in the cigarette box under test. For example, the corrected compensated image can be fused with the confidence weight map. During image reconstruction, regions with low confidence weights are suppressed, while regions with high confidence weights are enhanced. In one implementation, a simple pixel-level multiplication can be used, multiplying the corrected compensated image and the confidence weight map pixel by pixel to obtain the final detection image. However, this method may not fully utilize multi-scale information and is not effective for defect detection at different scales. In another implementation, a wavelet transform-based method can be used to decompose and reconstruct the image at different scales, introducing confidence weights during the reconstruction process. However, this method has high computational complexity and may limit real-time performance.

[0039] The following example will provide a more detailed explanation of the above technical solution: Imagine an automated cigarette box production line where cigarette boxes under test are moving at high speed on a conveyor belt. Due to mechanical vibration and incoming material tolerances, the actual physical boundary of the hot stamping pattern on the cigarette box experiences a sub-millimeter spatial pose offset from the preset compensation zone boundary. Traditional detection methods, when processing this offset, will generate abnormally bright band artifacts in the image due to spatial abrupt changes in the compensation parameters, causing qualified cigarette boxes to be misjudged as defective.

[0040] To address this issue, this application proposes an optical non-destructive testing method for surface defects in cigarette boxes. First, the system receives a total light intensity image and a polarization degree image as input. Gaussian low-pass filtering is applied to both the total light intensity image and the polarization degree image to smooth out minor printing noise and high-frequency noise from the image sensor. An edge detection operator is used to calculate the horizontal and vertical gradients of the light intensity image and the polarization degree image, respectively. The system linearly sums the light intensity gradient magnitude and the polarization degree gradient magnitude according to adaptive weights to generate a comprehensive gradient field. The adaptive weights are determined based on the local polarization degree variance. When the local polarization degree variance is large, it indicates a significant material difference in that area, and the system assigns a higher weight to the polarization degree gradient; conversely, it relies more on the light intensity gradient. After obtaining the comprehensive gradient field, the system performs non-maximum suppression, searching for local maxima along the direction of the comprehensive gradient, refining wider edge responses into candidate edge points with a single pixel width. Subsequently, the system employs a dual-threshold hysteresis tracking algorithm, setting two gradient magnitude thresholds (high and low). Points with a combined gradient magnitude exceeding the high threshold are marked as strong edge points, while points between the high and low thresholds are marked as weak edge points. Through eight-connected neighborhood analysis, weak edge points connected to strong edge points are retained, while isolated noise points are removed. To further improve the accuracy of boundary localization to meet the sensing requirements of sub-millimeter displacement, the system, based on single-pixel edges, utilizes sub-pixel edge localization algorithms, such as gradient-direction-based parabolic interpolation, to calculate the sub-pixel coordinates of the actual material physical boundary. These sub-pixel coordinate points are connected into continuous actual boundary curve segments and stored as a linked list structure with topological relationships. During extraction, the system removes extremely short, fragmented edge segments based on perimeter and area characteristics, as these are likely interference from tiny scratches or dust on the cigarette box surface, rather than true material boundaries. Through this series of steps, the system can accurately obtain the actual material boundary of the cigarette box under test in the current frame image.

[0041] Next, the system traverses each sub-pixel-level sampling point in the current actual boundary linked list and inputs its coordinates into a pre-constructed baseline boundary distance transformation map. It then quickly obtains the shortest Euclidean distance from the point to the preset boundary and the corresponding normal vector using bilinear interpolation. After solving for the transformation matrix of the current frame relative to the preset model using the least squares method, the system calculates the normal offset distance between the actual physical boundary and the preset compensation partition boundary. When the normal offset distance of a local region exceeds a set tolerance threshold, such as 0.5 pixels wide, the system determines that the region has entered a "boundary misalignment state." For these confirmed misalignment regions, the system no longer uses simple global translation for correction. Instead, it delineates a polygonal "boundary strip transition region" along the actual physical boundary. The centerline of this transition region is the current actual physical boundary, and its width dynamically depends on the calculated local offset. It typically extends several pixels to both sides of the boundary to ensure that the region completely covers the misalignment gap between the preset boundary and the actual boundary, as well as neighboring pixels that may be affected by the mismatch.

[0042] Subsequently, the system discards the static extinction coefficients of all pixels within the transition region that were previously bound to the preset dynamic compensation model. Next, based on the sub-pixel coordinates of the current actual physical boundary, the system recalculates the directed signed distance from each pixel within the transition region to the actual boundary. Pixels located on the highly reflective material side are defined as having positive distances, while those on the ordinary printed material side are defined as having negative distances. The system uses this directed signed distance to construct a continuous transitional spatial compensation function, employing a mathematical model based on a smoothing mapping function. Assuming the standard extinction coefficient of the highly reflective area is a higher value and the standard extinction coefficient of the ordinary area is a lower value, the actual extinction coefficient of a pixel within the transition region is calculated as follows: the lower value plus the difference between the higher and lower values, multiplied by a smoothing factor. This smoothing factor is the reciprocal of an exponential function with a base of the natural constant; the exponent includes the directed signed distance from the pixel to the actual boundary and a slope parameter controlling the steepness. The slope parameter is dynamically determined by the polarization contrast on both sides of the actual boundary of the local region: a larger contrast indicates a more drastic material change, and the slope parameter is set larger, resulting in a narrower transition band; a smaller contrast results in a smaller slope parameter, leading to a wider transition band. The system performs element-wise multiplication of the calculated continuous transition extinction coefficient matrix with the corresponding pixels of the original polarization intensity image to complete targeted reflection suppression processing. For pixels outside the transition region, the system continues to use the original preset compensation coefficients. This yields the corrected compensated image.

[0043] Further, the system extracts the boundary strip transition region defined in the previous step and, combined with the magnitude of the local offset, generates a pseudo-defect triggering confidence weight map with the same resolution as the original image. Each pixel value in this weight map represents the probability confidence that the high-frequency edge signal appearing at that location belongs to a real defect. For flat areas far from the material boundary, whether inside high-reflectivity areas or ordinary printing areas, their weight values ​​are uniformly set to the highest value, indicating that if high-frequency responses occur in these areas, they are highly likely to be real defects such as scratches, dents, or dirt. For pixels located within the boundary strip transition region, the system calculates the weight based on their distance from the actual physical boundary and the intensity of the compensation gradient. The closer a pixel is to the actual boundary centerline and the greater the gradient of the compensation coefficient change, the lower its weight value is set. In addition to distance and gradient, the system also introduces a direction consistency constraint to calculate the direction vector of the local image gradient. If the direction vector is highly parallel to the normal direction of the actual physical boundary, that is, the edge direction is parallel to the boundary, its weight is further reduced, because this is very likely to be the normal behavior of the material boundary line. If the direction vector has a significant angle with the boundary normal direction, such as presenting a vertically intersecting scratch, a higher weight value is retained to prevent real cross-boundary scratches from being incorrectly suppressed.

[0044] Finally, upon receiving the corrected compensated image and confidence weight map, the system performs multi-scale image fusion and feature enhancement to highlight minute scratches, dents, and printing defects. The system first uses a Gaussian kernel to perform multi-layer smoothing downsampling on the corrected compensated image, constructing a Gaussian pyramid. Then, it upsamples and subtracts adjacent Gaussian layers to construct a Laplacian pyramid. When enhancing the high-frequency coefficients of the Laplacian pyramid, the system employs an adaptive gain control strategy: the gain value actually applied to a given high-frequency coefficient is equal to the base enhancement coefficient multiplied by the corresponding weight value at that location. This means that in the transition region of boundary strips with low confidence weights, the high-frequency edge response parallel to the boundary will only receive a very weak enhancement or even be moderately smoothed, while in the high-reflectivity areas and ordinary areas with high confidence weights, minute scratch and dent signals will receive full gain amplification. After completing the adaptive weight adjustment of the high-frequency coefficients at each layer, the system starts from the top of the pyramid, upsamples layer by layer, and adds the adjusted high-frequency coefficients to perform multi-scale image reconstruction. The reconstructed final detection image not only achieves adaptive adjustment of illumination uniformity and contrast globally, effectively suppressing the strong reflection of the hot stamping material, but also perfectly preserves the smooth transition at the material interface even with sub-millimeter pose shifts, completely eliminating highlight or dark band artifacts caused by compensation misalignment. Furthermore, due to the directional consistency constraint, the true scratch signals crossing the boundary remain clearly visible in the reconstructed image.

[0045] By using the above method, this application can effectively solve the problem of mismatched compensation parameters caused by cigarette box pose deviation, eliminate high-brightness artifacts, and thus improve the accuracy of cigarette box surface defect detection.

[0046] This application's technical concept, by introducing a dynamic boundary perception and adaptive compensation mechanism, achieves real-time response to cigarette box pose shifts, thereby eliminating high-brightness artifacts caused by spatial jumps in compensation parameters and improving the accuracy of defect detection. Compared with traditional compensation methods based on offline fixed calibration partitions, this application can dynamically perceive and adapt to real-time minute physical shifts. Traditional methods, when the cigarette box experiences sub-millimeter spatial pose shifts, cannot completely align the actual physical boundary of the hot stamping pattern with the preset compensation partition boundary, causing the dynamic compensation model to incorrectly match a lower extinction coefficient at the material interface, forming abnormal high-brightness stripe artifacts. This application, by obtaining the actual material boundary of the cigarette box under test in the current frame image and comparing it with the preset compensation partition boundary, can accurately identify boundary misalignment areas and determine the boundary stripe transition area based on this. This dynamic perception mechanism allows the compensation correction range to be precisely locked in the local area affected by the shift, avoiding invalid processing of non-misaligned areas, significantly outperforming the static partitioning of traditional methods.

[0047] Furthermore, this application calculates dynamic compensation parameters for the boundary strip transition region based on the directed symbolic distance from the pixel to the actual material boundary, and performs compensation correction based on these parameters. This dynamic compensation parameter calculation method based on directed symbolic distance enables a smooth transition of the compensation coefficient at the material interface, effectively suppressing local reflections caused by physical boundary offsets and completely eliminating bright strip artifacts. In contrast, traditional methods, due to spatial abrupt changes in compensation parameters, cannot effectively suppress strong local reflections, leading to the generation of bright artifacts.

[0048] Furthermore, this application generates a confidence weight map based on the distribution characteristics of pixels within the boundary strip transition area. This map contains the defect trigger confidence weight for each pixel. During image reconstruction, based on the corrected compensated image and the confidence weight map, the smoothed compensated image information can be fused with the confidence weights, ensuring that the final detection image accurately reflects the real defect and avoiding misjudging normal hot stamping edges as false defects. Traditional methods, when processing high-frequency details, preserve and enhance high-brightness artifacts as signals with obvious edge features, causing normal hot stamping edges on the surface of qualified cigarette boxes to be incorrectly identified as linear false defects. This application, by introducing a confidence weight map, can quantify the reliability of each pixel as a defect signal, thereby suppressing the interference of artifact signals in subsequent image reconstruction, effectively avoiding misjudgment, and significantly improving the detection accuracy.

[0049] In summary, this application presents a complete optical non-destructive testing method for cigarette box surface defects by dynamically acquiring actual material boundaries, identifying boundary misalignment regions, adaptively calculating dynamic compensation parameters, generating confidence weight mapping maps, and performing image reconstruction. This method demonstrates significant technological advancements and innovation in addressing the detection challenges caused by cigarette box pose deviations, effectively improving the accuracy and reliability of cigarette box surface defect detection in automated production lines.

[0050] Traditional optical non-destructive testing methods for cigarette box surface defects often suffer from sub-millimeter spatial pose shifts on conveyor belts due to mechanical vibrations and material position tolerances when processing cigarette boxes with large-area hot stamping patterns. This physical displacement causes the actual physical boundary of the hot stamping pattern on the cigarette box to not completely coincide with the boundary of the preset compensation zone in the dynamic compensation model. When the physical boundary of the hot stamping area shifts outside the preset high compensation zone and falls into the adjacent low compensation zone, the dynamic compensation model will incorrectly match a lower extinction coefficient to these boundary strip pixels at the material interface. This spatial jump in compensation parameters results in the failure to effectively suppress local strong reflections, forming abnormally bright strip artifacts in the image. Existing compensation methods based on offline fixed calibration zones are unable to dynamically perceive and adapt to this real-time minute physical shift. As a result, when processing high-frequency details, multi-scale image fusion algorithms will treat this bright artifact as a signal with obvious edge features and preserve and enhance it. This causes the normal hot stamping edge on the surface of a qualified cigarette box to be incorrectly identified as a linear false defect, leading to the misjudgment and rejection of qualified products. Therefore, when performing polarization spectroscopy detection on cigarette boxes with locally highly reflective patterns on automated production lines, if the cigarette box experiences spatial pose shift due to transmission jitter, causing the material's physical boundary to misalign with the preset compensation zone boundary, the dynamic compensation model's mismatch of the extinction coefficient for boundary pixels will result in local reflections not being suppressed, forming high-brightness artifacts. These artifacts are then amplified into false defects by the fusion algorithm, leading to a decrease in detection accuracy. This is a technical problem that urgently needs to be solved.

[0051] In some embodiments, the specific steps in step S1 include: S11. Acquire multi-polarization state images of the cigarette box to be tested; S12. Based on the multi-polarization state image, calculate the total light intensity image and polarization degree image; S13. Based on adaptive weights that characterize local material differences, a comprehensive gradient field is generated by weighted fusion of gradient information from the total light intensity image and the polarization degree image; S14. Perform edge detection on the integrated gradient field, and obtain the pixel-level coordinates of the actual material boundary by performing sub-pixel-level positioning on the edge detection results.

[0052] The acquisition of multi-polarization images of the cigarette box under test refers to obtaining image data containing information about different polarization directions through an optical imaging system. This step aims to capture richer physical information from the source to overcome the limitations of traditional intensity images in distinguishing complex materials, especially highly reflective materials. As a specific implementation method, an industrial camera equipped with a micro-polarizer array can be used to simultaneously capture image data in multiple polarization directions (e.g., 0 degrees, 45 degrees, 90 degrees, 135 degrees) in a single exposure, thus avoiding time differences and motion artifacts caused by multiple exposures. Another implementation method is to use a camera with a rotating polarizer for sequential acquisition, or to use multiple cameras, each with a polarizer of a specific polarization direction fixed in front of it, to obtain multi-polarization images.

[0053] Calculating the total intensity image and degree of polarization image based on multi-polarization state images refers to extracting images characterizing the overall reflection intensity and polarization characteristics of an object's surface from the acquired multi-polarization state images. This step transforms the raw polarization data into more physically meaningful parameters, which helps in subsequent material differentiation. For example, according to Stokes vector theory, the intensity images (I0, I45, I90, I135) in four polarization directions can be calculated into a total intensity image (S0=I0+I90) and a degree of polarization image (DoP=sqrt((I0-I90)^2+(I45-I135)^2) / S0). As another calculation method, approximate total intensity and degree of polarization information can also be derived directly from two or three polarization images using a specific optical model. For example, a polarization contrast image can be constructed using the difference and sum of orthogonal polarization images as an alternative to the degree of polarization image.

[0054] Based on adaptive weights characterizing local material differences, a comprehensive gradient field is generated by weighted fusion of gradient information from the total intensity image and the polarization degree image. This involves intelligently combining the edge information of the total intensity image and the polarization degree image to highlight the true boundaries at material interfaces. This step dynamically adjusts the weights to more effectively utilize the advantageous gradient information of different material regions. One specific implementation example is as follows: the adaptive weights can be determined based on the local polarization degree variance. When the local polarization degree variance is large, it indicates significant material differences in that region, and the polarization degree gradient is given a higher weight; conversely, it relies more on the total intensity gradient. Another implementation method is to dynamically adjust the weights based on the texture features of the local region or a preset material type probability map. For example, in areas where highly reflective materials are known to exist, the weight of the polarization degree gradient is increased.

[0055] Edge detection on the integrated gradient field, followed by sub-pixel-level localization of the edge detection results to obtain pixel-level coordinates of the actual material boundary, refers to accurately identifying and locating the physical boundary of the material within the fused gradient field. This step aims to obtain high-precision boundary coordinates to meet the sensing requirements of sub-millimeter displacement. As a specific implementation, non-maximum suppression can be performed on the integrated gradient field first, refining the wider edge response into candidate edge points of single-pixel width. Then, a double-threshold hysteresis tracking algorithm is used to connect the edges. Based on this, to achieve sub-pixel-level localization, parabolic interpolation based on the gradient direction can be used to interpolate the gradient magnitude in the direction perpendicular to the edge, thereby calculating the sub-pixel coordinates of the actual material's physical boundary. Another edge detection method can use the Laplacian operator or the Gaussian-Laplacian operator (LoG) to detect zero-crossing points in the image, which typically correspond to image edges. For sub-pixel localization, in addition to parabolic interpolation, the sub-pixel position of the edge can also be accurately determined by fitting a mathematical model of the local gradient distribution (e.g., a Gaussian function).

[0056] This application's solution introduces multi-polarization state imaging technology to acquire image data containing rich physical information from the source, laying the foundation for subsequent accurate extraction of material boundaries. By acquiring multi-polarization state images of the cigarette box under test, the system can capture deeper information about the interaction between light and the surface material of the cigarette box, rather than just simple intensity information. Based on these multi-polarization state images, the system further calculates the total light intensity image and the degree of polarization image. The total light intensity image reflects the overall brightness of the object, while the degree of polarization image can significantly distinguish different materials, especially highly reflective materials (such as hot stamping) and ordinary printed materials, because they have significant differences in polarization characteristics. Subsequently, the system performs weighted fusion of the gradient information of the total light intensity image and the degree of polarization image based on adaptive weights characterizing local material differences, generating a comprehensive gradient field. This adaptive weighted fusion mechanism enables the system to intelligently highlight the edge features at material boundaries according to the actual situation of local materials, effectively suppressing background noise and interference from highly reflective areas. For example, in areas with large differences in degree of polarization, the degree of polarization gradient is given a higher weight, thus more accurately reflecting the material boundary. Finally, edge detection is performed on the integrated gradient field, and the pixel-level coordinates of the actual material boundary are obtained by sub-pixel-level localization of the edge detection results. This sub-pixel-level localization technology overcomes the limitations of traditional pixel resolution, ensuring extremely high accuracy of the material boundary coordinates.

[0057] The following is a concrete example to illustrate this. The system constructs a multi-source optical acquisition architecture based on hardware synchronous triggering. A high-precision incremental photoelectric encoder is installed on the drive shaft of the conveyor belt, which outputs pulse signals in real time as the conveyor belt runs. When the pulse count reaches the preset trigger threshold, i.e., when the cigarette box precisely reaches the center of the field of view of the optical inspection station, the programmable logic controller sends a microsecond-level hard trigger signal to the vision acquisition system. After receiving this signal, the vision acquisition system synchronously controls the multi-angle polarization light source and the polarization industrial camera. The multi-angle polarization light source consists of an array of broadband light-emitting diodes of different wavelengths, and a polarizer with a precisely calibrated transmission axis is installed in front of the optical path to project a structured light field onto the surface of the cigarette box at a specific angle. The internal image sensor of the polarization industrial camera is covered with a micro-polarizer array, which can simultaneously capture image data in four different polarization directions within a single extremely short exposure time, namely 0 degrees, 45 degrees, 90 degrees, and 135 degrees polarized images. The acquired raw image data stream is transmitted to the memory buffer of the industrial control computer via gigabit Ethernet or high-speed coaxial cable. In memory, the image preprocessing module first de-mosaics and separates the polarization channels of the raw data, extracting four independent two-dimensional polarization intensity matrices. Then, the system calculates pixel-level Stokes vectors based on these four polarization intensity matrices. Specifically, the first Stokes parameter represents the total light intensity, obtained by adding the grayscale values ​​of corresponding pixels in the zero-degree polarization image and the ninety-degree polarization image; the second Stokes parameter represents the intensity difference between horizontally and vertically linearly polarized light, obtained by subtracting the ninety-degree polarization image from the zero-degree polarization image; and the third Stokes parameter represents the intensity difference between forty-five-degree and one hundred-thirty-five-degree linearly polarized light, obtained by subtracting the one hundred-thirty-five-degree polarization image from the forty-five-degree polarization image. Based on these Stokes vectors, the system further calculates the degree of polarization and polarization angle of each pixel. The degree of polarization is calculated by taking the square root of the sum of the squares of the second and third Stokes parameters, and then dividing by the first Stokes parameter. The system receives the total light intensity image and the degree of polarization image as input for this step. Gaussian low-pass filtering is applied to both the total intensity image and the polarization image to smooth out minor printing noise and high-frequency noise from the image sensor. Edge detection operators are used to calculate the horizontal and vertical gradients of the intensity image and the polarization image, respectively. The system linearly sums the intensity gradient magnitude and the polarization gradient magnitude using adaptive weights to generate a comprehensive gradient field. The adaptive weights are determined based on the local polarization variance; a larger local polarization variance indicates a significant material difference in that region, and the system assigns a higher weight to the polarization gradient; conversely, a smaller local polarization variance indicates a greater reliance on the intensity gradient. After obtaining the comprehensive gradient field, the system performs non-maximum suppression, searching for local maxima along the direction of the comprehensive gradient to refine wider edge responses into candidate edge points with a single pixel width.Subsequently, the system employs a dual-threshold hysteresis tracking algorithm, setting two gradient magnitude thresholds: high and low. Points with a combined gradient magnitude exceeding the high threshold are marked as strong edge points, while points between the high and low thresholds are marked as weak edge points. Through eight-connected neighborhood analysis, weak edge points connected to strong edge points are retained, while isolated noise points are removed. To further improve the accuracy of boundary localization to meet the sensing requirements of sub-millimeter displacement, the system, based on single-pixel edges, utilizes sub-pixel edge localization algorithms, such as gradient-direction-based parabolic interpolation, to calculate the sub-pixel coordinates of the actual material physical boundary. These sub-pixel coordinate points are connected into continuous actual boundary curve segments and stored as a linked list structure with topological relationships. During the extraction process, the system discards extremely short, fragmented edge segments based on perimeter and area characteristics, as these are highly likely to be interference from tiny scratches or dust on the cigarette box surface, rather than true material boundaries.

[0058] Through the above technical solution, this application can effectively overcome the challenges posed by the complex surface materials and light interference of cigarette boxes, accurately extracting pixel-level coordinates at the interface of different materials. This high-precision actual material boundary information provides a reliable geometric benchmark for subsequent identification of boundary misalignment areas and determination of boundary strip transition areas. When combined with the aforementioned optical non-destructive testing method for cigarette box surface defects, the accurate actual material boundary allows the dynamic compensation model to more accurately correct boundary misalignment areas, avoiding incorrect matching of compensation parameters due to inaccurate boundary positioning, thereby effectively suppressing the bright strip artifacts formed by strong local reflections. This fundamentally solves the problem in traditional methods where normal hot stamping edges on the surface of qualified cigarette boxes are incorrectly identified as linear false defects, significantly improving the accuracy of cigarette box surface defect detection and the robustness of the system, and reducing the false rejection rate.

[0059] In some embodiments, the specific steps in step S2 include: S21. Calculate the shortest Euclidean distance from each sampling point on the actual material boundary to the compensation zone boundary, and compare the shortest Euclidean distance with the preset tolerance threshold to identify the boundary misalignment area; S22. Calculate the average normal offset of the boundary misalignment region, and based on the average normal offset, take the actual material boundary as the center and expand to both sides of the width to obtain the boundary strip transition region.

[0060] The calculation of the shortest Euclidean distance from each sampling point on the actual material boundary to the compensation zone boundary aims to quantify the spatial deviation between the actual material boundary and the preset compensation zone boundary. This distance reflects the degree of pose shift of the cigarette box on the conveyor belt. One implementation is to query a pre-constructed distance transformation map; that is, generate a distance transformation map for the preset compensation zone boundary, and then input the coordinates of the sampling points on the actual material boundary into the map to directly obtain their shortest Euclidean distance. Another implementation is to use an improved version of the iterative nearest point algorithm for calculation. The actual boundary point set is used as the source point cloud, and the preset boundary point set is used as the target point cloud. Through iterative matching and optimization, the shortest Euclidean distance from each actual boundary sampling point to the preset boundary is calculated.

[0061] The shortest Euclidean distance is compared with a preset tolerance threshold to identify boundary misalignment regions. The purpose is to distinguish between acceptable minor fluctuations and significant misalignments requiring special handling. This tolerance threshold defines the allowable displacement range; areas exceeding this range are marked as misaligned. This tolerance threshold can be a preset fixed pixel width threshold, such as 0.5 pixels wide; when the shortest Euclidean distance exceeds this value, it is determined to be a misalignment. Alternatively, the tolerance threshold can be dynamically adjusted based on local image features or material properties. For example, the threshold can be appropriately relaxed in areas with complex textures or high material contrast, while being more stringent in flat areas.

[0062] Calculating the average normal offset of the boundary misalignment region aims to obtain the overall displacement trend and magnitude of the misalignment region. This offset represents the average deviation of the actual material boundary within the misalignment region from the preset compensation zone boundary. One approach is to average the normal offset vectors of each sampling point within the misalignment region; that is, to calculate the normal vector from each misalignment point to the preset boundary and then statistically average these vectors. Another approach is to perform local model fitting between the actual boundary point set and the preset boundary point set, such as using the least squares method, to calculate the average normal offset, thus obtaining a more robust overall offset.

[0063] Based on the average normal offset, a boundary strip transition region is obtained by expanding outwards from the actual material boundary to both sides. The purpose is to dynamically define the precise area requiring compensation and correction. The width and position of this transition region are adjusted according to the actual offset to ensure that the compensation range is neither too large nor too small. One implementation is to symmetrically expand a preset width to both sides from the actual material boundary, which can be proportional to the average normal offset. Another implementation is to expand asymmetrically to both sides based on the magnitude and direction of the offset. For example, when the average normal offset indicates that the actual boundary has shifted to one side, the expansion width on that side can be appropriately increased to ensure complete coverage of the misaligned area.

[0064] This application's solution achieves refined perception and region reconstruction of cigarette box pose displacement by introducing geometric distance measurement and statistical offset calculation. First, by calculating the shortest Euclidean distance between the actual material boundary sampling point and the preset compensation zone boundary, and comparing it with a tolerance threshold, minor positional fluctuations within the allowable range can be effectively filtered out, thus accurately locating the area where significant misalignment truly occurs and avoiding misprocessing of normal areas. Second, after identifying the misaligned area, the average normal offset of that area is further calculated. This feature quantifies the overall displacement trend of the cigarette box and reflects the specific degree to which the material boundary deviates from the preset trajectory. Finally, based on this average normal offset, a boundary strip transition region is generated by extending outwards from the actual material boundary. This dynamic expansion mechanism ensures that the transition region closely matches the actual material interface position, providing an accurate physical spatial range for subsequent targeted dynamic compensation parameter calculations. This effectively solves the problem of compensation region mismatch caused by pose displacement, ensuring that the extinction treatment of highly reflective areas covers the actual offset boundary, eliminating the spatial basis for high-brightness artifacts at the source.

[0065] The following is a specific example to illustrate this. When performing optical non-destructive testing on a cigarette box with a gold foil pattern, the system first obtains the actual material boundary of the cigarette box in the current frame image through step S1. Subsequently, in order to identify boundary misalignment areas, the system traverses each sub-pixel-level sampling point in the actual material boundary linked list and inputs its coordinates into a pre-constructed baseline boundary distance transformation map. Bilinear interpolation is then used to quickly obtain the shortest Euclidean distance from the point to the preset compensation partition boundary and the corresponding normal vector. If the normal offset distance of a certain local area exceeds a set tolerance threshold, such as 0.5 pixels wide, the system determines that the area has entered a boundary misalignment state. For these confirmed misalignment areas, the system uses an improved version of the iterative nearest-point algorithm to estimate the global and local spatial pose offsets. The actual boundary point set is used as the source point cloud, and the preset boundary point set is used as the target point cloud. A random sampling consensus algorithm is introduced to remove outliers in the matching pairs. After solving for the transformation matrix of the current frame relative to the preset model using the least squares method, the average normal offset of the boundary misalignment area is calculated. Finally, based on the average normal offset, a polygonal boundary strip transition region is defined along the actual physical boundary, centered on the actual material boundary. The width of this transition region dynamically depends on the calculated local offset, typically extending several pixels to both sides of the boundary to ensure that the region completely covers the misalignment gap between the preset boundary and the actual boundary, as well as neighboring pixels that may be affected by the mismatch. If the offset is too large and exceeds the preset maximum correction range, the system will enter an abnormal flow handling process, directly determining the cigarette box as a positionally defective product and triggering a rejection action.

[0066] Through the above technical solution, this application can accurately quantify the sub-millimeter spatial pose shift of the cigarette box on the conveyor belt caused by mechanical vibration and material position tolerance, and dynamically adjust the compensation area. This allows subsequent dynamic compensation correction to be precisely applied to the actual material interface, effectively avoiding spatial jumps in compensation parameters, thereby completely suppressing localized strong reflections and eliminating abnormally bright stripe artifacts formed in the image. Therefore, this application significantly reduces the probability of normal hot stamping edges on the surface of qualified cigarette boxes being incorrectly identified as linear false defects, improving the accuracy and reliability of optical non-destructive testing of cigarette box surface defects, and is particularly suitable for online inspection of cigarette boxes with locally highly reflective patterns.

[0067] In some embodiments, step S3, which involves calculating the dynamic compensation parameters for each pixel based on the spatial distance from the pixel within the boundary strip transition area to the actual material boundary, includes the following specific steps: S31. Based on the directed sign distance from the pixel point in the boundary strip transition area to the actual material boundary, the compensation weight of each pixel point is obtained by constructing a mapping function; S32. Based on the compensation weight, and combined with the preset compensation coefficients for high reflectivity areas and normal areas, calculate the dynamic compensation parameters for each pixel.

[0068] Directed signed distance is a metric that simultaneously represents the distance of a pixel to a boundary and its relative position (e.g., which side of the boundary it is on). Its purpose is to precisely quantify the spatial offset of a pixel relative to the actual material boundary, providing fine spatial location information for subsequent compensation parameter calculations. One possible implementation is to first calculate the Euclidean distance from the pixel to the actual material boundary, and then combine this with the normal direction of the actual material boundary to determine the sign of the distance. For example, pixels located on the highly reflective material side are designated as having positive distances, while pixels located on the ordinary printed material side are designated as having negative distances. Another possible implementation is to use a distance transformation algorithm to generate a distance field, where the value of each pixel represents its distance to the nearest boundary, and the sign of the distance is assigned through predefined region divisions or boundary normal directions.

[0069] The mapping function transforms the directed signed distance into compensation weights, thus achieving a smooth and continuous transition of compensation parameters with spatial location. This function dynamically adjusts the contribution of each pixel in the compensation process based on its distance from the actual material boundary, avoiding abrupt changes in the compensation parameters. One possible implementation is to use smooth nonlinear functions such as the Sigmoid or tanh functions as the mapping function. These functions map the input value (directed signed distance) to a continuous output value (compensation weight) between 0 and 1, changing rapidly in the central region and slowly at the extremes. Another possible implementation is to use an exponential function, such as the reciprocal of an exponential function with the natural constant as its base. The exponent part includes the directed signed distance and a slope parameter controlling the steepness, thereby achieving fine control over the compensation weight change curve.

[0070] The compensation weight is a value calculated using a mapping function based on the directed signed distance from a pixel to the actual material boundary. Its function is to characterize the proportion or contribution of that pixel during the dynamic compensation process. One possible implementation is that the compensation weight can be a floating-point number between 0 and 1, used for linear interpolation of preset compensation coefficients between highly reflective and ordinary areas to obtain the final compensation parameters for that pixel. Another possible implementation is that the compensation weight can be directly used as a multiplication factor to adjust the intensity of the base compensation coefficient, allowing it to change smoothly within the transition region.

[0071] The preset compensation coefficients for high-reflectivity and ordinary areas are pre-set or calibrated compensation values ​​for different material types (such as highly reflective materials like hot stamping and coating versus ordinary printing materials). These coefficients reflect the inherent optical characteristics of different materials and form the basis for differentiated compensation. One possible approach is to obtain these preset compensation coefficients through offline experimental calibration. For example, under standard lighting conditions, multiple measurements can be taken on different material areas, and the average extinction coefficient or gain factor that effectively suppresses reflection can be calculated and stored in the system's configuration file or lookup table. Another possible approach is to establish an empirical model based on the material's physical properties (such as reflectivity and polarization), and calculate the corresponding preset compensation coefficients using this model.

[0072] Dynamic compensation parameters are calculated based on compensation weights and preset compensation coefficients, and are the final parameters used to compensate and correct each pixel within the boundary strip transition area. Their function is to specifically suppress strong local reflections while ensuring a smooth transition at material boundaries. One possible implementation is as an extinction coefficient, which is multiplied element-wise by the pixel intensity of the original image to reduce the brightness of highly reflective areas. Another possible implementation is as a gain factor, used to adjust the pixel brightness value to achieve the desired compensation effect.

[0073] This application's solution effectively solves the problem of inaccurate compensation in boundary transition regions by introducing a mechanism combining directed symbolic distance and a mapping function to achieve refined dynamic calculation of compensation parameters. Specifically, after accurately obtaining the actual material boundary of the cigarette box under test in the current frame image in step S1, and identifying the boundary misalignment region and determining the boundary strip transition region in step S2, this solution first calculates the directed symbolic distance to the actual material boundary for each pixel within the boundary strip transition region. This directed symbolic distance can accurately quantify the degree of offset of the pixel relative to the material boundary line in spatial position, providing a reliable physical basis for subsequent smooth and continuous compensation transition. On this basis, the directed symbolic distance is transformed into compensation weight by constructing a mapping function. This mapping mechanism ensures that the compensation weight can smoothly transition with changes in spatial position, avoiding image artifacts caused by abrupt changes in compensation parameters. Subsequently, based on the compensation weight and combined with the preset compensation coefficients for high-reflectivity areas and ordinary areas, the dynamic compensation parameters for each pixel are calculated. This approach embodies the differentiated processing of the optical properties of different materials. By weightedly fusing spatial location information with preset material property values, the compensation parameters not only reflect the positional characteristics of pixels in the transition zone but also take into account the specific compensation needs of different material regions. Finally, these dynamic compensation parameters are used to compensate and correct the image, resulting in a corrected image. This overall scheme, based on accurately acquiring the actual material boundaries and dynamically determining the transition region of the boundary strips, further provides a refined pixel-level compensation strategy. This enables more targeted reflection suppression at material boundaries even when the cigarette box experiences sub-millimeter spatial pose shifts, significantly improving the quality and reliability of the final detection image and avoiding the problem of misidentifying normal hot stamping edges as linear false defects.

[0074] As a specific implementation method, in step S3, the dynamic compensation parameter of each pixel is calculated based on the spatial distance from the pixel within the boundary strip transition area to the actual material boundary as follows: First, the system discards the static extinction coefficients of all pixels within the boundary strip transition area that were originally bound in the preset dynamic compensation model. Next, based on the sub-pixel coordinates of the current actual physical boundary, the system recalculates the directed sign distance from each pixel within the transition area to the actual material boundary. During this process, the pixel distance on the side of the highly reflective material can be defined as positive, and the pixel distance on the side of the ordinary printed material as negative. Subsequently, the system uses this directed sign distance to construct a continuous transitional spatial compensation function, employing a mathematical model based on a smoothing mapping function. For example, assuming the standard extinction coefficient of the highly reflective area is a higher value and the standard extinction coefficient of the ordinary area is a lower value, the actual extinction coefficient (i.e., the dynamic compensation parameter) of a pixel within the transition area can be calculated as: the lower value plus the difference between the higher and lower values, multiplied by a smoothing factor. The smoothing factor can be the reciprocal of an exponential function with a natural constant as its base. The exponent includes the directed signed distance from the pixel to the actual material boundary and a slope parameter controlling the steepness. The magnitude of the slope parameter is dynamically determined by the polarization contrast on both sides of the actual material boundary in the local region: a higher contrast indicates a more abrupt material change, and the slope parameter is set larger, resulting in a narrower transition band; conversely, a lower contrast results in a smaller slope parameter, leading to a wider transition band. Finally, the system performs element-wise multiplication of the calculated continuous transition extinction coefficient matrix (i.e., the dynamic compensation parameter matrix) with the corresponding pixels of the original polarization intensity image to complete targeted reflection suppression. For pixels outside the transition region, the system continues to use the original preset compensation coefficients.

[0075] Through the above technical solution, this application effectively solves the problem of the lack of specificity in the spatial distribution of compensation parameters caused by the use of a unified compensation logic in traditional methods. By calculating the directed symbolic distance from the pixel to the actual material boundary and constructing a mapping function, the compensation weight is adjusted in a refined and continuous manner. Then, combined with the preset compensation coefficients of different materials, dynamic compensation parameters that are highly adapted to local material characteristics are calculated. This allows the compensation correction to more accurately suppress strong local reflections in the boundary strip transition area, avoiding the generation of bright artifacts. Especially when the cigarette box experiences sub-millimeter spatial pose shift due to transmission jitter, this solution can dynamically adapt to the misalignment between the physical boundary of the material and the preset compensation zone boundary, ensuring a smooth transition of compensation parameters. This significantly reduces the probability of normal hot stamping edges on the surface of qualified cigarette boxes being incorrectly identified as linear false defects, improving the accuracy and reliability of detection.

[0076] In some embodiments, the specific steps in step S4 include: S41. Obtain the local gradient magnitude and local gradient direction of each pixel within the boundary strip transition area, and obtain the normal direction of the actual material boundary; S42. Based on the relative relationship between the local gradient magnitude, the local gradient direction and the normal direction of the actual material boundary, determine the defect trigger confidence weight of each pixel in the boundary strip transition area, and generate a confidence weight mapping map based on the defect trigger confidence weight.

[0077] Obtaining the local gradient magnitude and direction of each pixel within the transition region of the boundary strip refers to calculating the intensity and direction of brightness change for each pixel within a local region using image processing techniques. The local gradient magnitude represents the drastic degree of brightness change around the pixel, typically obtained by calculating the square root of the sum of the squares of the gray-level differences in the horizontal and vertical directions, using gradient operators such as Sobel, Prewitt, or Roberts. The local gradient direction represents the direction of brightness change, usually obtained by calculating the arctangent of the gray-level differences in the horizontal and vertical directions. This gradient information effectively captures high-frequency details such as edges and textures in the image, forming the basis for image feature recognition.

[0078] Obtaining the normal direction of the actual material boundary refers to determining the direction vector perpendicular to the actual material boundary. The actual material boundary is the physical dividing line that distinguishes different material regions, and its normal direction provides important geometric reference information. This normal direction can be calculated based on the pixel-level coordinates of the identified actual material boundary. For example, it can be achieved by locally fitting the boundary curve, calculating the tangent direction of the fitted curve at each point, and then obtaining the normal direction perpendicular to the tangent. Alternatively, it can be achieved using a distance transformation map, where the value of each pixel represents its distance to the nearest boundary, and the gradient direction of the distance transformation map is the normal direction of the boundary.

[0079] The defect trigger confidence weight is determined based on the relative relationship between the local gradient magnitude, local gradient direction, and the normal direction of the actual material boundary. This involves comprehensively considering the local image features of the pixel and the geometric features of the material boundary to assess the likelihood that the high-frequency signal at that pixel is a real defect. This relative relationship can include the angle, parallelism, or perpendicularity between the local gradient direction and the normal direction. For example, when the local gradient direction is highly parallel to the normal direction of the actual material boundary, it indicates that the high-frequency signal may simply be the outline of the material boundary itself or a residual artifact caused by incomplete compensation. Conversely, when there is a significant angle between the local gradient direction and the normal direction, especially when they are close to perpendicular, it is more likely to indicate a real defect crossing the boundary, such as a scratch. The defect trigger confidence weight is a value between 0 and 1, used to quantify the reliability of a pixel being identified as a defect; a higher weight indicates a higher probability of a real defect.

[0080] Generating a confidence weight map involves organizing the calculated defect trigger confidence weights for each pixel into a two-dimensional image with the same resolution as the original image. Each pixel value in this map corresponds to its defect trigger confidence weight. As auxiliary information, the confidence weight map can guide subsequent image processing and defect identification. For example, during image fusion or enhancement, different enhancement intensities can be applied to high-frequency signals in different regions based on the weights, effectively suppressing artifacts and highlighting true defects.

[0081] This application's solution achieves refined modeling of defect triggering confidence by introducing correlation analysis between local gradient features and material boundary geometric features. First, by acquiring the local gradient magnitude and direction of pixels within the boundary strip transition region, subtle edge change information in the image can be captured. This information is crucial for distinguishing normal material textures from abnormal defects. Second, by acquiring the normal direction of the actual material boundary, a geometric reference is established, allowing subsequent analysis to be based on the geometric positional relationship of pixels relative to the material boundary. Finally, the defect triggering confidence weight is determined based on the relative relationship between the local gradient magnitude, local gradient direction, and the normal direction of the actual material boundary. The unique aspect of this process is its deep fusion of image gradient features and physical boundary geometric constraints. This effectively identifies artifact features caused by boundary misalignment and assigns them lower confidence weights. Consequently, in subsequent image reconstruction and defect detection, these artifact signals are automatically masked or weakened, ensuring that the final detected image more accurately reflects the true surface defects. This scheme is closely integrated with steps S1, S2, and S3 of the aforementioned optical non-destructive testing method for cigarette box surface defects. Building upon step S1 for accurately acquiring the actual material boundary, step S2 for identifying boundary misalignment areas and determining boundary strip transition areas, and step S3 for dynamic compensation and correction, this scheme further refines the generation of the confidence weight mapping map in step S4. This enables the entire testing process to more intelligently distinguish between genuine and counterfeit products when dealing with complex boundary areas, significantly improving the robustness of testing under complex lighting and pose shift conditions.

[0082] As a specific implementation, the system can extract the boundary strip transition region defined in the previous step and, combined with the magnitude of the local offset, generate a pseudo-defect trigger confidence weight map with the same resolution as the original image. Each pixel value in this weight map represents the probability confidence that the high-frequency edge signal appearing at that location belongs to a real defect. For flat areas far from the material boundary, whether inside high-reflectivity areas or ordinary printing areas, their weight values ​​can be uniformly set to the highest value, indicating that if high-frequency responses appear in these areas, they are very likely to be real defects such as scratches, dents, or dirt. For pixels located within the boundary strip transition region, the system can calculate the weight based on their distance from the actual physical boundary and the severity of the compensation gradient. The closer to the center line of the actual boundary and the greater the gradient of the compensation coefficient change, the lower the weight value can be set. This is because at the material boundary, even after continuous transition correction, due to the abrupt change in the reflectivity of the physical material itself, some normal edge contour signals will still remain. If these contour signals are given too high a confidence level, they are easily misjudged as linear defects in subsequent fusion enhancement. In addition to distance and gradient, the system can also introduce directional consistency constraints to calculate the direction vector of the local image gradient. If this direction vector is highly parallel to the normal direction of the actual physical boundary, i.e., the edge direction is parallel to the boundary, its weight can be further reduced, as this is highly likely to be the normal behavior of the material boundary line. If the direction vector has a significant angle with the boundary normal direction, such as presenting a vertically intersecting scratch, a higher weight value can be retained to prevent real cross-boundary scratches from being incorrectly suppressed. The final generated confidence weight map serves as an auxiliary channel and is passed to the downstream multi-scale image processing module along with the corrected compensation image.

[0083] Through the above technical solution, this application effectively solves the problem in traditional methods where relying solely on simple pixel distribution features makes it difficult to accurately distinguish between real defect signals and artifacts caused by boundary misalignment. By comprehensively considering the relative relationship between local gradient magnitude, local gradient direction, and the normal direction of the actual material boundary, this application can more accurately assess the probability that the high-frequency signal of each pixel in the boundary strip transition area belongs to a real defect, thereby generating a more accurate defect triggering confidence weight map. In subsequent image reconstruction and defect detection, this map can effectively suppress the interference of artifacts caused by boundary misalignment on defect judgment, significantly reduce the false alarm rate, and greatly improve the accuracy of defect triggering, thereby improving the overall reliability and robustness of optical non-destructive testing of cigarette box surface defects.

[0084] Reference Appendix Figure 2This invention provides an optical non-destructive testing system for cigarette box surface defects (this system employs the optical non-destructive testing method for cigarette box surface defects described in the above embodiments; the specific process is described in the corresponding steps above). It can be implemented through the following optical non-destructive testing system for cigarette box surface defects, specifically including: The acquisition module 100 is used to acquire the actual material boundary of the cigarette box to be tested in the current frame image; The identification module 200 is used to identify boundary misalignment areas by comparing the actual material boundary with the preset compensation partition boundary, and to determine the boundary strip transition area based on the boundary misalignment area; the boundary strip transition area is used to correct the boundary misalignment area. The compensation module 300 is used to calculate the dynamic compensation parameters of each pixel in the boundary strip transition area based on the spatial distance from the pixel in the boundary strip transition area to the actual material boundary, and to perform compensation correction based on the dynamic compensation parameters to obtain the compensated image after the boundary strip transition area is corrected. The generation module 400 is used to generate a confidence weight mapping map based on the distribution characteristics of pixels in the transition area of ​​the boundary strip before correction. The reconstruction module 500 is used to obtain the final detection image by reconstructing the image based on the corrected compensated image and the confidence weight map, and to detect surface defects of the cigarette box under test using the final detection image.

[0085] In this context, the units described as separate components may or may not be physically separate. Similarly, the components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0086] Furthermore, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0087] In this document, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between these entities or operations.

[0088] The above description is merely an embodiment of the present invention and is not intended to limit the scope of protection of the present invention. For those skilled in the art, the present invention can have various modifications and variations. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for non-destructive optical inspection of surface defects in cigarette boxes, characterized in that, Includes the following steps: S1. Obtain the actual material boundary of the cigarette box to be tested in the current frame image; S2. By comparing the actual material boundary with the preset compensation partition boundary, the boundary misalignment area is identified, and based on the boundary misalignment area, the boundary strip transition area is determined; the boundary strip transition area is used to correct the boundary misalignment area. S3. For the boundary strip transition region, calculate the dynamic compensation parameter of each pixel based on the spatial distance from the pixel in the boundary strip transition region to the actual material boundary, and perform compensation correction based on the dynamic compensation parameter to obtain the compensated image of the boundary strip transition region after correction. S4. Generate a confidence weight mapping map based on the distribution characteristics of pixels in the transition area of ​​the boundary strip before correction; S5. Based on the corrected compensated image and the confidence weight mapping, the final detection image is obtained by reconstructing the image, and the surface defects of the cigarette box to be tested are detected using the final detection image.

2. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 1, characterized in that, The actual material boundary includes pixel-level coordinates of the intersection of different materials.

3. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 2, characterized in that, The specific steps in step S1 include: S11. Acquire multi-polarization state images of the cigarette box to be tested; S12. Based on the multi-polarization state image, calculate the total light intensity image and the polarization degree image; S13. Based on adaptive weights that characterize local material differences, a comprehensive gradient field is generated by weighted fusion of the gradient information of the total light intensity image and the polarization degree image; S14. Perform edge detection on the integrated gradient field, and obtain the pixel-level coordinates of the actual material boundary by performing sub-pixel-level positioning on the edge detection results.

4. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 1, characterized in that, In step S2, the specific steps for identifying boundary misalignment areas by comparing the actual material boundary with the preset compensation partition boundary include: S21. Calculate the shortest Euclidean distance from each sampling point on the actual material boundary to the compensation partition boundary, and compare the shortest Euclidean distance with a preset tolerance threshold to identify the boundary misalignment area.

5. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 1, characterized in that, In step S2, the specific steps for determining the boundary strip transition region based on the boundary misalignment region include: S22. Calculate the average normal offset of the boundary misalignment region, and based on the average normal offset, take the actual material boundary as the center and expand to both sides of the width to obtain the boundary strip transition region.

6. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 1, characterized in that, The spatial distance is a directed symbolic distance.

7. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 6, characterized in that, In step S3, the specific steps for calculating the dynamic compensation parameters of each pixel based on the spatial distance from the pixel within the boundary strip transition area to the actual material boundary include: S31. Based on the directed sign distance from the pixel point in the boundary strip transition area to the actual material boundary, a mapping function is constructed to obtain the compensation weight of each pixel point; S32. Based on the compensation weight, and combined with the preset compensation coefficients for the high-reflectivity area and the normal area, calculate the dynamic compensation parameters for each pixel.

8. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 1, characterized in that, The confidence weight map includes the defect trigger confidence weight of each pixel within the boundary strip transition area.

9. The optical non-destructive testing method for surface defects of cigarette boxes according to claim 8, characterized in that, The specific steps in step S4 include: S41. Obtain the local gradient magnitude and local gradient direction of each pixel within the boundary strip transition area, and obtain the normal direction of the actual material boundary; S42. Based on the relative relationship between the local gradient magnitude, the local gradient direction and the normal direction of the actual material boundary, determine the defect trigger confidence weight of each pixel in the boundary strip transition area, and generate the confidence weight mapping map based on the defect trigger confidence weight.