A visual inspection method for pinhole defects in food packaging films
Patent Information
- Application Number
- CN202611012058.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-08
- Publication Date
- 2026-10-30
AI Technical Summary
[0005]本发明提供了一种食品包装膜针孔缺陷视觉检测方法,促进解决了上述背景技术中所提到的问题
先将食品包装膜展开为二维检测面,并在相机检测视场中建立与膜宽方向、膜运行方向相对应的膜面检测坐标系,再划分计算采样点和核心采样点,使核心采样点位于有效检测区域内部并属于计算采样点。为后续邻域计算、偏振响应计算和缺陷区域定位提供稳定、统一的坐标基础,避免边界区域邻域不完整造成的计算偏差。本方案通过计算采样区和核心采样区的分层设置,将用于计算背景的区域和最终判定的区域区分开,使候选缺陷更集中在可靠检测范围内。与现有技术中直接对整幅图像进行阈值分割或仅设置固定检测框的方式相比,该方案不仅建立了物理方向明确的膜面坐标,还通过四个偏振采集角对同一检测区域同步采集,使后续能够从偏振维度提取膜结构变化,增强了检测流程的空间一致性和数据可比性。
Smart Images

Figure REF-OBJ-1783498682764-000002 
Figure REF-OBJ-1783498682764-000003 
Figure REF-OBJ-1783498682764-000004
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial machine vision inspection technology, specifically a visual inspection method for pinhole defects in food packaging films. Background Technology
[0002] Food packaging films are widely used in food sealing, barrier, moisture-proofing, and preservation packaging. During the blowing, lamination, stretching, printing, slitting, and winding processes, pinhole defects that penetrate the film thickness are easily generated due to factors such as raw material particles, tensile stress concentration, foreign object intrusion, lamination defects, and uneven local melting. These pinhole defects are typically small in size and their appearance is inconsistent. In transparent, semi-transparent, color-printed, and composite films, they are easily masked by film textures, printing patterns, localized wrinkles, surface contamination, and uneven lighting, making them difficult to reliably identify with conventional visual inspection.
[0003] Existing pinhole detection technologies for food packaging films mainly include manual light inspection, ordinary backlight imaging inspection, single-angle grayscale threshold detection, bright and dark spot extraction, and image recognition methods based on defect sample training. Manual light inspection relies on operator experience, resulting in poor consistency and unsuitability for high-speed continuous production. Ordinary backlight imaging inspection typically identifies suspected pinholes based on local brightness abrupt changes; however, food packaging films themselves have variations in thickness, stretch textures, and printed patterns, making it easy to misjudge pinholes based solely on grayscale changes, such as variations in print transmittance, oil stain reflections, scratches, and wrinkles. Single-angle grayscale threshold detection is sensitive to changes in light source intensity, camera exposure, film surface tension, and film transparency. When the batch, film material type, or printed background changes, the threshold needs to be readjusted, leading to insufficient detection stability. Some existing technologies introduce multi-angle imaging or sample training methods to improve detection capabilities, but multi-angle ordinary imaging usually still relies primarily on brightness differences, making it difficult to distinguish between penetrating pinholes and non-penetrating surface anomalies. Recognition methods based on training samples require a large number of defect samples and labeled data. Furthermore, pinhole defects in food packaging films are characterized by randomness, small size, and low frequency of occurrence, making sample collection difficult. When the film material, printing pattern, thickness, and production process change, the model recognition results are prone to drift, resulting in high engineering implementation costs.
[0004] Therefore, this case aims to propose a visual detection method for pinhole defects in food packaging films. It utilizes the response changes of the same film surface location under multiple polarization acquisition angles, combines the neighborhood of a fixed index ring to form a local benchmark, and then identifies pinholes from two dimensions: film structure disturbance and light transmission enhancement. Summary of the Invention
[0005] This invention provides a visual inspection method for pinhole defects in food packaging films, which helps to solve the problems mentioned in the background art.
[0006] This invention provides the following technical solution: a visual inspection method for pinhole defects in food packaging film, comprising: Establish a coordinate system for the detection of food packaging film surface, divide the calculation sampling points and core sampling points. The core sampling points belong to the calculation sampling points. Set four polarization acquisition angles and acquire the polarization grayscale channels of the same detection area. The digital grayscale values under each polarization acquisition angle are collected and converted into normalized grayscale. A fixed index ring neighborhood is established for the calculation sampling points and core sampling points. The average grayscale of the membrane texture neighborhood of each calculation sampling point under each polarization acquisition angle is calculated. Set a grayscale denominator protection value, and perform co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculation sampling point under the same polarization acquisition angle to form the co-location polarization response value and the four-corner polarization response group. Calculate the average transmission response at the four corners, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response set; The polarization modulation intensity and polarization closure error are calculated based on the first polarization difference term, the second polarization difference term, and the polarization closure residual. The amount of membrane structure missing is then calculated by combining the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark. Calculate the average light transmittance response benchmark at the four corners of the neighborhood, calculate the light transmittance enhancement based on the average light transmittance response at the four corners, and construct the threshold for determining the amount of membrane structure loss and the threshold for determining the amount of light transmittance enhancement. The core sampling points are judged one by one. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, the current core sampling point is written into the pinhole candidate point set and the pinhole candidate region is aggregated according to the eight-adjacency relationship. Calculate the intensity-weighted center location, physical area, and region score of the pinhole candidate region, combine them to generate a pinhole defect output record, and do not generate pinhole candidate regions, intensity-weighted center locations, physical areas, and region scores for core sampling points that are not written into the pinhole candidate point set.
[0007] Optionally, the establishment of a film surface detection coordinate system for the food packaging film, dividing it into calculation sampling points and core sampling points (the core sampling points being part of the calculation sampling points), setting four polarization acquisition angles, and acquiring polarization grayscale channels of the same detection area specifically includes: Unfold the food packaging film into a two-dimensional inspection surface; Establish a film surface detection coordinate system within the camera's detection field of view. Set the origin of the coordinate system at the intersection of the upper left corner of the detection field of view and the food packaging film feed boundary. Set the horizontal coordinate axis from left to right along the width direction of the food packaging film, and set the vertical coordinate axis from the feed side to the discharge side along the running direction of the food packaging film. A set of membrane surface sampling points is established within the camera's detection field of view. The set of membrane surface sampling points consists of all membrane surface sampling points. Each membrane surface sampling point is defined by a horizontal sampling number, a vertical sampling number, the distance between horizontally adjacent sampling points, and the distance between vertically adjacent sampling points. The horizontal sampling number increases sequentially from zero to the total number of horizontal sampling points minus one. The vertical sampling number increases sequentially from zero to the total number of vertical sampling points minus one. The total number of horizontal sampling points and the total number of vertical sampling points are both not less than twenty-six. A calculation sampling area is established in the set of membrane surface sampling points. The calculation sampling area consists of membrane surface sampling points with horizontal sampling number not less than six and not greater than the total number of horizontal sampling points minus seven, and vertical sampling number not less than six and not greater than the total number of vertical sampling points minus seven. The membrane surface sampling points in the calculation sampling area are used as calculation sampling points. A core sampling area is established in the set of membrane surface sampling points. The core sampling area consists of membrane surface sampling points with a horizontal sampling number of not less than twelve and not greater than the total number of horizontal sampling points minus thirteen, and a vertical sampling number of not less than twelve and not greater than the total number of vertical sampling points minus thirteen. The membrane surface sampling points in the core sampling area are used as core sampling points. Core sampling points are calculated sampling points, and the total number of membrane surface sampling points in the core sampling area is counted as the total number of core sampling points. Four polarization acquisition angles are set, and the four polarization acquisition angles are set to zero degrees, forty-five degrees, ninety degrees and one hundred and thirty-five degrees in a fixed order, so that the same sampling point on the film surface can form a grayscale response under the four polarization acquisition angles. The same detection area of the food packaging film is simultaneously sampled at four polarization acquisition angles, so that each film sampling point forms four polarization grayscale channels corresponding to the four polarization acquisition angles under the same acquisition trigger. The four polarization grayscale channels only have the difference of polarization acquisition angle, and the tension of the food packaging film, the brightness of the light source, the camera exposure time and the film running speed are kept under the same detection conditions.
[0008] Optionally, the step of acquiring digital grayscale values at each polarization acquisition angle and converting them into normalized grayscale values, establishing a fixed index ring neighborhood for the calculation sampling points and core sampling points, and calculating the average grayscale of the film texture neighborhood at each calculation sampling point at each polarization acquisition angle specifically includes: At each polarization acquisition angle, digital grayscale values are acquired at the sampling points on the film surface, and the digital grayscale values are limited to integers from zero to the maximum digital grayscale value corresponding to the camera bit depth; Read the maximum digital grayscale value corresponding to the camera bit depth, divide the digital grayscale value of each sampling point on the film surface under each polarization acquisition angle by the maximum digital grayscale value corresponding to the camera bit depth, and convert it into the normalized grayscale of the sampling point on the film surface under the corresponding polarization acquisition angle. A fixed index ring neighborhood is established for each computational sampling point. Each core sampling point is used as a computational sampling point and corresponds to a fixed index ring neighborhood in the same way. The membrane sampling points in the fixed index ring neighborhood corresponding to the core sampling point belong to the computational sampling points in the computational sampling area. The fixed index ring neighborhood corresponding to each computational sampling point consists of membrane sampling points in the camera detection field of view that satisfy the condition that the absolute value of the difference between the horizontal neighborhood sampling number and the horizontal sampling number of the current computational sampling point, and the absolute value of the difference between the vertical neighborhood sampling number and the vertical sampling number of the current computational sampling point are not less than two and not greater than six. For each calculated sampling point and each polarization acquisition angle, the normalized grayscale of all membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point is counted under the current polarization acquisition angle. The sum of the normalized grayscale is divided by the number of membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point to calculate the average grayscale of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle.
[0009] Optionally, the setting of the grayscale denominator protection amount involves performing co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculated sampling point under the same polarization acquisition angle to form a co-location polarization response quantity and a four-corner polarization response group, specifically including: Read the maximum digital grayscale value corresponding to the camera's bit depth, divide one by the maximum digital grayscale value corresponding to the camera's bit depth, calculate the minimum normalized grayscale interval that the camera can distinguish, and set the minimum normalized grayscale interval as the grayscale denominator protection value. For each calculated sampling point and each polarization acquisition angle, the normalized gray value of the current calculated sampling point under the current polarization acquisition angle is divided by the sum of the average gray value of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle and the gray value denominator protection amount, to calculate the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle. The calculation sampling area is used as a set of polarization response calculation objects, and four co-located polarization response quantities under four polarization acquisition angles are fixedly retained for each calculation sampling point in the calculation sampling area. For each calculation sampling point, the four co-located polarization response quantities of the current calculation sampling point under the four polarization acquisition angles are arranged in a fixed order according to the four polarization acquisition angles to form the four-corner polarization response group of the current calculation sampling point.
[0010] Optionally, the step of calculating the average transmission response at the four corners, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response set specifically includes: For each calculation sampling point, read the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles, sum the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles and divide by four to calculate the polarization DC term of the current calculation sampling point. The polarization DC term of the current calculation sampling point is the average transmission response of the four corners of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the first polarization acquisition angle and the co-located polarization response at the third polarization acquisition angle. Subtract the co-located polarization response at the third polarization acquisition angle from the co-located polarization response at the first polarization acquisition angle and divide by two to calculate the first polarization difference term of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the second polarization sampling angle and the co-located polarization response at the fourth polarization sampling angle. Subtract the co-located polarization response at the fourth polarization sampling angle from the co-located polarization response at the second polarization sampling angle and divide by two to calculate the second polarization difference term of the current calculation sampling point. For each calculated sampling point and each polarization acquisition angle, read the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, the polarization DC term of the current calculated sampling point, the first polarization difference term of the current calculated sampling point, the second polarization difference term of the current calculated sampling point, and the current polarization acquisition angle. Multiply the first polarization difference term of the current calculated sampling point by the cosine of twice the current polarization acquisition angle, and multiply the second polarization difference term of the current calculated sampling point by the sine of twice the current polarization acquisition angle. Then, subtract the polarization DC term of the current calculated sampling point, the product of the first polarization difference term of the current calculated sampling point and the cosine of twice the current polarization acquisition angle, and the product of the second polarization difference term of the current calculated sampling point and the sine of twice the current polarization acquisition angle from the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, to calculate the polarization closure residual of the current calculated sampling point under the current polarization acquisition angle.
[0011] Optionally, the step of calculating the polarization modulation intensity and polarization closure error based on the first polarization difference term, the second polarization difference term, and the polarization closure residual, and calculating the amount of membrane structure loss by combining the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark, specifically includes: For each calculation sampling point, read the first polarization difference term and the second polarization difference term of the current calculation sampling point, sum the square of the first polarization difference term and the square of the second polarization difference term of the current calculation sampling point, and calculate the polarization modulation intensity of the current calculation sampling point. For each calculation sampling point, read the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles, perform a square operation on the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles respectively, sum the four square operation results and divide by four to calculate the average closure residual square of the current calculation sampling point under the four polarization acquisition angles, and record the average closure residual square as the polarization closure error of the current calculation sampling point; For each core sampling point, read the polarization modulation intensity of all calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point, sum all polarization modulation intensities and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to calculate and form the neighborhood polarization modulation intensity benchmark of the current core sampling point. For each core sampling point, read the polarization closure error of all calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point, sum all polarization closure errors and divide by the number of calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point to calculate and form the neighborhood polarization closure error benchmark of the current core sampling point. For each core sampling point, the polarization modulation intensity of the current core sampling point is used as the polarization modulation intensity corresponding to the sampling point, minus the polarization modulation intensity benchmark of the current core sampling point to form the polarization modulation intensity difference of the current core sampling point. The polarization modulation intensity difference of the current core sampling point is divided by the sum of the polarization modulation intensity benchmark of the current core sampling point and the grayscale denominator protection amount to calculate the polarization modulation intensity mutation amount of the current core sampling point. For each core sampling point, the polarization closure error of the current core sampling point is used as the basis for calculating the sampling point. The polarization closure error difference of the current core sampling point is then calculated by subtracting the polarization closure error benchmark of the current core sampling point from the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. The polarization closure error abrupt change of the current core sampling point is then calculated by dividing the polarization closure error difference of the current core sampling point by the sum of the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. For each core sampling point, the amount of membrane structure missing at the current core sampling point is calculated by adding the polarization modulation intensity mutation amount and the polarization closure error mutation amount of the current core sampling point and then dividing by two.
[0012] Optionally, the calculation of the average transmittance response benchmark at the four corners of the neighborhood, the calculation of transmittance enhancement based on the average transmittance response at the four corners, and the construction of a threshold for determining the amount of membrane structure loss and a threshold for determining the amount of transmittance enhancement specifically include: For each core sampling point, read the average transmittance response of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point. Sum the average transmittance responses of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to form the benchmark of the average transmittance response of the neighborhood of the current core sampling point. For each core sampling point, the average transmittance response of the four corners corresponding to the current core sampling point when calculating the sampling point is divided by the sum of the average transmittance response reference of the neighboring four corners of the current core sampling point and the grayscale denominator protection amount, to calculate the transmittance enhancement amount of the current core sampling point relative to the average transmittance response reference of the neighboring four corners of the current core sampling point. Read the membrane structure missing amount of all core sampling points in the core sampling area, arrange all membrane structure missing amounts in non-descending order to form a membrane structure missing amount sorting sequence, and configure a sorting value index for each sorting value in the membrane structure missing amount sorting sequence. Read the light transmission enhancement amount of all core sampling points in the core sampling area, arrange all light transmission enhancement amounts in non-descending order to form a light transmission enhancement amount sorting sequence, and configure a sorting value index for each sorting value in the light transmission enhancement amount sorting sequence. In the sequence of membrane structure missing amount, the sort value index is selected as half of the total number of core sampling points to form the median benchmark of membrane structure missing amount; In the light transmission enhancement sorting sequence, the sorting value index is selected as half of the total number of core sampling points to form the median benchmark of light transmission enhancement. For the sorting sequence of membrane structure missing quantities, subtract the median benchmark of membrane structure missing quantity from each sorting value in the sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of membrane structure missing quantity. For the light transmission enhancement sorting sequence, subtract the median light transmission enhancement benchmark from each sorting value in the light transmission enhancement sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of light transmission enhancement. The median baseline of membrane structure loss is added to the mean absolute deviation of membrane structure loss to construct the threshold for determining membrane structure loss. Similarly, the median baseline of light transmission enhancement is added to the mean absolute deviation of light transmission enhancement to construct the threshold for determining light transmission enhancement.
[0013] Optionally, the step of determining each core sampling point individually involves writing the current core sampling point into the pinhole candidate point set when both the membrane structure missing amount at the current core sampling point and the light transmission enhancement amount at the current core sampling point exceed the light transmission enhancement threshold. The pinhole candidate regions are then aggregated according to an eight-adjacency relationship. Specifically, this includes: Read the membrane structure missing amount, light transmission enhancement amount, membrane structure missing amount judgment threshold and light transmission enhancement amount judgment threshold of each core sampling point in the core sampling area, and make judgments on each core sampling point in the core sampling area. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, write the current core sampling point into the pinhole candidate point set. For any two core sampling points in the pinhole candidate point set, an adjacency judgment is performed. When the absolute value of the difference between the horizontal sampling number and the vertical sampling number of the two core sampling points is not greater than one, and the absolute value of the difference between the horizontal sampling number and the vertical sampling number is greater than zero and not greater than two, an eight-adjacency relationship is established between the two core sampling points. Based on the eight-adjacency relationship, the set of pinhole candidate points is divided into several non-overlapping maximum connected regions. Each maximum connected region is used as a pinhole candidate region, and a pinhole candidate region number is assigned to each pinhole candidate region to form a region index set. For each core sampling point within each pinhole candidate region, the membrane structure loss at the current core sampling point is multiplied by the light transmission enhancement at the current core sampling point to calculate the regional positioning intensity that forms the current core sampling point. For each pinhole candidate region, the coordinate position of each core sampling point in the membrane detection coordinate system within the current pinhole candidate region is multiplied with the regional positioning intensity of the same core sampling point. The sum of the product results corresponding to all core sampling points within the current pinhole candidate region is then divided by the sum of the regional positioning intensities of all core sampling points within the current pinhole candidate region to calculate the intensity weighted center position of the current pinhole candidate region. For each pinhole candidate region, count the number of core sampling points in the current pinhole candidate region, multiply the number of core sampling points in the current pinhole candidate region by the horizontal adjacent sampling point distance and the vertical adjacent sampling point distance, and calculate the physical area forming the current pinhole candidate region; For each pinhole candidate region, read the regional positioning intensity of all core sampling points in the current pinhole candidate region, sum the regional positioning intensity of all core sampling points in the current pinhole candidate region and divide it by the number of core sampling points in the current pinhole candidate region to calculate the regional score of the current pinhole candidate region.
[0014] Optionally, the calculation of the intensity-weighted center location, physical area, and region score of the pinhole candidate region, combined to generate a pinhole defect output record, and the non-generation of pinhole candidate region, intensity-weighted center location, physical area, and region score for core sampling points not written into the pinhole candidate point set, specifically includes: Read the region index set, extract the intensity weighted center position, physical area and region score of each pinhole candidate region, and combine the intensity weighted center position, physical area and region score of the current pinhole candidate region to generate the corresponding pinhole defect output record. Write all pinhole defect output records generated from each pinhole candidate region into the pinhole defect output record set; When the region index set is empty, the pinhole defect output record set is set to an empty set; Read the pinhole defect output record set. When the pinhole defect output record set is empty, generate a detection status of no detected pinhole defects. Read the pinhole defect output record set. When the pinhole defect output record set is not empty, generate the detection status of the detected pinhole defect and output each pinhole defect output record in the pinhole defect output record set. Read the core sampling area and the set of pinhole candidate points. For core sampling points located within the core sampling area but not written into the set of pinhole candidate points, do not generate pinhole candidate regions, intensity weighted center positions, physical areas, or region scores. Also, ensure that the set of pinhole defect output records retains only the pinhole defect output records generated by the pinhole candidate regions.
[0015] The present invention has the following beneficial effects: First, the food packaging film is unfolded into a two-dimensional inspection surface. A film surface inspection coordinate system corresponding to the film width and movement direction is established within the camera's inspection field of view. Then, calculation sampling points and core sampling points are divided, ensuring that the core sampling points are located within the effective inspection area and belong to the calculation sampling points. This provides a stable and unified coordinate basis for subsequent neighborhood calculation, polarization response calculation, and defect region localization, avoiding calculation deviations caused by incomplete neighborhoods in boundary areas. This scheme separates the area used for background calculation from the area for final judgment through the layered setting of the calculation sampling area and the core sampling area, making candidate defects more concentrated within the reliable inspection range. Compared with existing technologies that directly perform threshold segmentation on the entire image or only set fixed detection boxes, this scheme not only establishes film surface coordinates with clearly defined physical directions but also simultaneously acquires data from the same inspection area through four polarization acquisition angles. This allows for subsequent extraction of film structure changes from the polarization dimension, enhancing the spatial consistency and data comparability of the inspection process.
[0016] First, the digital grayscale is converted to normalized grayscale based on the camera bit depth. Then, a fixed index ring neighborhood is established for the calculation sampling points and core sampling points, and the average grayscale of the film texture neighborhood is calculated at each polarization acquisition angle. This unifies the grayscale data under different camera bit depths, exposure intensities, or acquisition ranges to a comparable scale. Simultaneously, the film texture background level around the current sampling point is extracted through the ring neighborhood, transforming the detected object from an absolute brightness anomaly to a local anomaly relative to the neighborhood film texture background. This scheme utilizes the fixed index ring neighborhood to avoid noise in a very small area near the current sampling point while preserving the representativeness of the local film texture background. Compared with existing technologies that use global average grayscale, fixed global thresholds, or simple window averaging, this scheme is more suitable for local background changes in continuous film materials and can reduce misjudgments caused by film texture, gradual changes in illumination, and the inhomogeneity of the material itself.
[0017] A grayscale denominator protection value is set, and the normalized grayscale of the same calculated sampling point at the same polarization acquisition angle is compared with the average grayscale of the film texture neighborhood to form a co-located polarization response value. This response value is then grouped into four-corner polarization response groups according to a fixed order of the four polarization acquisition angles. Replacing the original grayscale response with a local relative response weakens the influence of light source intensity, overall film transmittance, and camera exposure differences on the detection results. Simultaneously, the grayscale denominator protection value prevents abnormal amplification when the neighborhood average grayscale is too low. This scheme compares the current sampling point with the neighborhood background at the same polarization angle, highlighting local abnormal light transmission characteristics. Compared with existing methods such as direct grayscale difference, single-angle image enhancement, or fixed brightness thresholds, this scheme combines spatial neighborhood background and polarization angle response, preserving local abrupt changes caused by pinholes while suppressing large-scale illumination and film texture background variations, thus exhibiting stronger field adaptability.
[0018] The average transmittance response at each of the four corners, the first polarization difference term, the second polarization difference term, and the polarization closure residual at each polarization sampling angle are extracted from the four-corner polarization response group. The polarization response at the same sampling point is decomposed into three levels of information: average transmittance level, polarization direction difference, and degree of polarization response non-closure. This allows pinhole detection to go beyond just brightness variations and simultaneously reflect both transmittance variations and membrane structure disturbances. This scheme, through multi-angle polarization response decomposition, can distinguish between these two types of phenomena. Compared to existing technologies that only use a single transmission image or simple multi-angle brightness superposition, this scheme evaluates sampling points from the perspective of the internal consistency of the polarization response, enabling a deeper understanding of the damage caused by pinholes to the membrane microstructure and improving the ability to identify small pinholes and weak-contrast pinholes.
[0019] The polarization modulation intensity is formed based on the first and second polarization difference terms, and the polarization closure error is formed based on the polarization closure residual. Neighborhood polarization modulation intensity and neighborhood polarization closure error benchmarks are established for the core sampling point. The degree of abrupt change of the current core sampling point relative to the neighborhood benchmarks is then used to determine the amount of membrane structure loss. This approach uses local polarization structure anomalies to describe the damage caused by pinholes to the continuous structure of the packaging film, rather than simply identifying bright or dark spots as defects. By comparing the polarization modulation intensity and polarization closure error in the neighborhood, this scheme can identify whether the current core sampling point has undergone an abnormal abrupt change relative to the surrounding film texture background. Compared to existing techniques that rely solely on brightness thresholds, edge detection, or morphological screening, this scheme elevates pinhole recognition from the image appearance level to the polarization structure level, helping to reduce the misdetection of normal textures as pinholes and improving the sensitivity to fine structural defects in transparent or semi-transparent food packaging films.
[0020] For each core sampling point, the average transmittance response benchmark at the four corners of its neighborhood is calculated. Then, the average transmittance response at the four corners of the core sampling point itself is compared with the neighborhood benchmark to form the transmittance enhancement. A corresponding judgment threshold is constructed based on the ranking of membrane structure defects and transmittance enhancement at all core sampling points within the core sampling area. The threshold is not externally fixed but generated by the data distribution within the current detection area, adapting to imaging differences under different batches of packaging film materials, different film thicknesses, different lighting conditions, and different production speeds. This scheme forms a robust threshold using a median benchmark and mean absolute deviation, suppressing the influence of extreme noise points on the threshold while retaining sensitivity to abnormally high values. Compared to existing technologies that manually set thresholds, rely on empirical parameter tuning, or use global average thresholds, this scheme has stronger adaptability, reduces setup costs, and improves stability and consistency in continuous production testing.
[0021] The core sampling points are evaluated point by point. Only when both the amount of membrane structure loss and the amount of light transmission enhancement simultaneously exceed the corresponding judgment threshold is the current core sampling point added to the pinhole candidate point set, and the candidate points are aggregated into pinhole candidate regions based on the eight-adjacency relationship. Using dual-indicator judgment avoids directly identifying a single anomaly caused solely by light transmission enhancement or polarization perturbation as a pinhole, thus improving the reliability of candidate points. Simultaneously, eight-adjacency aggregation transforms discrete sampling points into spatially continuous candidate regions, facilitating subsequent calculations of location, area, and scoring. This scheme requires both structural loss and light transmission enhancement to be present simultaneously, and further performs connected region aggregation, which can filter isolated noise and retain the spatial clustering characteristics of real pinhole formation. Compared with existing technologies using single-threshold point detection or simple connected domain segmentation, the advantage of this scheme lies in combining physically clear dual defect characteristics with spatial topological relationships, improving the authenticity and interpretability of pinhole candidate regions.
[0022] For each pinhole candidate region, the intensity-weighted center location, physical area, and region score are calculated, and these results are combined into a pinhole defect output record. Simultaneously, core sampling points not written into the pinhole candidate point set are not generated as candidate regions or defect outputs. The output results not only tell the system whether a pinhole exists, but also provide the pinhole's location in the membrane surface detection coordinate system, its actual area, and the severity of the region, facilitating subsequent rejection, alarm, traceability, and production quality statistics. This scheme uses region positioning intensity for weighted center calculation, which makes the output location more biased towards the region with the strongest defect response, rather than just taking the geometric center, thereby improving positioning accuracy. Compared with existing technologies that only output binary detection results or only connected component bounding boxes, this scheme forms a more complete defect record, facilitating integration with production equipment, rejection mechanisms, and quality management systems.
[0023] A set of pinhole defect output records is established. Based on whether the region index set and the pinhole defect output record set are empty, detection states of undetected or detected pinhole defects are generated respectively. Simultaneously, only records generated from pinhole candidate regions are retained in the output record set. This ensures that the detection results have clear data boundaries and output logic, preventing normal core sampling points that are not included in the candidate point set from being mistakenly generated with region information, location information, or scoring information. This scheme, through empty set processing, detection state generation, and output record filtering, enables the detection results to express both undetected normal states and structured defect records when detected. Compared to existing methods that merely mark abnormal points on the image or simply output the number of defects, this scheme is more suitable for closed-loop applications in industrial online inspection systems, improving data reliability, reducing post-processing ambiguity, and enhancing the usability of detection results in quality management. Attached Figure Description
[0024] Figure 1 This is a schematic diagram of the residual sampling area of the membrane surface detection coordinate system of the present invention.
[0025] Figure 2 This is a schematic diagram of the fixed index ring neighborhood of the present invention.
[0026] Figure 3 This is a schematic diagram illustrating the determination of the amount of membrane structure defects and the amount of light transmission enhancement in this invention.
[0027] Figure 4 This is a schematic diagram of the pinhole candidate region and output record of the present invention. Detailed Implementation
[0028] 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. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0029] An embodiment of a visual inspection method for pinhole defects in food packaging film includes: Establish a coordinate system for the detection of food packaging film surface, divide the calculation sampling points and core sampling points. The core sampling points belong to the calculation sampling points. Set four polarization acquisition angles and acquire the polarization grayscale channels of the same detection area. The digital grayscale values under each polarization acquisition angle are collected and converted into normalized grayscale. A fixed index ring neighborhood is established for the calculation sampling points and core sampling points. The average grayscale of the membrane texture neighborhood of each calculation sampling point under each polarization acquisition angle is calculated. Set a grayscale denominator protection value, and perform co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculation sampling point under the same polarization acquisition angle to form the co-location polarization response value and the four-corner polarization response group. Calculate the average transmission response at the four corners, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response set; The polarization modulation intensity and polarization closure error are calculated based on the first polarization difference term, the second polarization difference term, and the polarization closure residual. The amount of membrane structure missing is then calculated by combining the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark. Calculate the average light transmittance response benchmark at the four corners of the neighborhood, calculate the light transmittance enhancement based on the average light transmittance response at the four corners, and construct the threshold for determining the amount of membrane structure loss and the threshold for determining the amount of light transmittance enhancement. The core sampling points are judged one by one. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, the current core sampling point is written into the pinhole candidate point set and the pinhole candidate region is aggregated according to the eight-adjacency relationship. Calculate the intensity-weighted center location, physical area, and region score of the pinhole candidate region, combine them to generate a pinhole defect output record, and do not generate pinhole candidate regions, intensity-weighted center locations, physical areas, and region scores for core sampling points that are not written into the pinhole candidate point set.
[0030] By establishing a film surface detection coordinate system, dividing the sampling points and core sampling points, and collecting polarization grayscale channels of the same detection area at multiple polarization acquisition angles, the problems of inconsistent detection area coordinates, lack of spatial positioning basis for sampling points, and difficulty in corresponding data at different acquisition angles in existing detection methods are solved. Furthermore, through normalized grayscale, fixed index ring neighborhood, average grayscale of the film texture neighborhood, and processing of co-located polarization response, the detection object is transformed from simple grayscale brightness changes to polarization response changes relative to the local film texture background, solving the problem that film texture, material thickness variations, and light fluctuations on the food packaging film surface easily interfere with pinhole identification. Then, through the stepwise calculation of four-corner average transmittance response, polarization difference term, polarization closure residual, polarization modulation intensity, polarization closure error, film structure loss, and transmittance enhancement, pinhole defect evaluation is decomposed into two aspects: film structure abnormalities and local transmittance abnormalities, avoiding judgment of defects based solely on a single bright or dark spot. Finally, through dual-threshold point-by-point judgment, eight-adjacent aggregation, and defect record output, the problems of false alarms from isolated noise points, unclear defect area locations, and difficulty in structured output of defect results are solved. This method improves the stability of pinhole candidate point screening under conditions of continuous operation of packaging film, complex surface texture, and fluctuating imaging conditions, and outputs information such as location, area, and score for subsequent quality control. Compared to conventional single-frame grayscale threshold detection, this method combines local neighborhood references, polarization response changes, and connected region outputs into a single system, enabling the detection results to reflect not only brightness anomalies but also anomalies in the continuity of the film structure.
[0031] Reference Figure 1 The establishment of a film surface detection coordinate system for food packaging film, dividing it into calculation sampling points and core sampling points (core sampling points are part of the calculation sampling points), setting four polarization acquisition angles, and acquiring polarization grayscale channels of the same detection area, specifically includes: Unfold the food packaging film into a two-dimensional inspection surface; Establish a film surface detection coordinate system within the camera's detection field of view. Set the origin of the coordinate system at the intersection of the upper left corner of the detection field of view and the food packaging film feed boundary. Set the horizontal coordinate axis from left to right along the width direction of the food packaging film, and set the vertical coordinate axis from the feed side to the discharge side along the running direction of the food packaging film. A set of membrane surface sampling points is established within the camera's detection field of view. The set of membrane surface sampling points consists of all membrane surface sampling points. Each membrane surface sampling point is defined by a horizontal sampling number, a vertical sampling number, the distance between horizontally adjacent sampling points, and the distance between vertically adjacent sampling points. The horizontal sampling number increases sequentially from zero to the total number of horizontal sampling points minus one. The vertical sampling number increases sequentially from zero to the total number of vertical sampling points minus one. The total number of horizontal sampling points and the total number of vertical sampling points are both not less than twenty-six. A calculation sampling area is established in the set of membrane surface sampling points. The calculation sampling area consists of membrane surface sampling points with horizontal sampling number not less than six and not greater than the total number of horizontal sampling points minus seven, and vertical sampling number not less than six and not greater than the total number of vertical sampling points minus seven. The membrane surface sampling points in the calculation sampling area are used as calculation sampling points. A core sampling area is established in the set of membrane surface sampling points. The core sampling area consists of membrane surface sampling points with a horizontal sampling number of not less than twelve and not greater than the total number of horizontal sampling points minus thirteen, and a vertical sampling number of not less than twelve and not greater than the total number of vertical sampling points minus thirteen. The membrane surface sampling points in the core sampling area are used as core sampling points. Core sampling points are calculated sampling points, and the total number of membrane surface sampling points in the core sampling area is counted as the total number of core sampling points. Four polarization acquisition angles are set, and the four polarization acquisition angles are set to zero degrees, forty-five degrees, ninety degrees and one hundred and thirty-five degrees in a fixed order, so that the same sampling point on the film surface can form a grayscale response under the four polarization acquisition angles. The same detection area of the food packaging film is simultaneously sampled at four polarization acquisition angles, so that each film sampling point forms four polarization grayscale channels corresponding to the four polarization acquisition angles under the same acquisition trigger. The four polarization grayscale channels only have the difference of polarization acquisition angle, and the tension of the food packaging film, the brightness of the light source, the camera exposure time and the film running speed are kept under the same detection conditions.
[0032] By unfolding the food packaging film into a two-dimensional detection surface and establishing a film surface detection coordinate system within the camera's detection field of view based on the film's feed boundary and the detection field of view position, the problem of lacking a unified spatial reference in images for continuously moving film materials is solved. By aligning the horizontal coordinate axis with the film width direction and the vertical coordinate axis with the film's movement direction, subsequent detection results can correspond to the actual film width and movement direction positions, which is beneficial for subsequent positioning, alarms, and traceability.
[0033] The process involves acquiring digital grayscale values at each polarization acquisition angle and converting them into normalized grayscale values. A fixed index ring neighborhood is established for the calculation sampling points and core sampling points. The average grayscale value of the membrane texture neighborhood at each calculation sampling point at each polarization acquisition angle is calculated. Specifically, this includes: At each polarization acquisition angle, digital grayscale values are acquired at the sampling points on the film surface, and the digital grayscale values are limited to integers from zero to the maximum digital grayscale value corresponding to the camera bit depth; Read the maximum digital grayscale value corresponding to the camera bit depth, divide the digital grayscale value of each sampling point on the film surface under each polarization acquisition angle by the maximum digital grayscale value corresponding to the camera bit depth, and convert it into the normalized grayscale of the sampling point on the film surface under the corresponding polarization acquisition angle. A fixed index ring neighborhood is established for each computational sampling point. Each core sampling point is used as a computational sampling point and corresponds to a fixed index ring neighborhood in the same way. The membrane sampling points in the fixed index ring neighborhood corresponding to the core sampling point belong to the computational sampling points in the computational sampling area. The fixed index ring neighborhood corresponding to each computational sampling point consists of membrane sampling points in the camera detection field of view that satisfy the condition that the absolute value of the difference between the horizontal neighborhood sampling number and the horizontal sampling number of the current computational sampling point, and the absolute value of the difference between the vertical neighborhood sampling number and the vertical sampling number of the current computational sampling point are not less than two and not greater than six. For each calculated sampling point and each polarization acquisition angle, the normalized grayscale of all membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point is counted under the current polarization acquisition angle. The sum of the normalized grayscale is divided by the number of membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point to calculate the average grayscale of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle.
[0034] By acquiring digital grayscale values of membrane surface sampling points at each polarization acquisition angle and limiting these values to the effective range corresponding to the camera bit depth, the problems of inconsistent value ranges in the original acquired data and the impact of abnormal grayscale values on subsequent calculations are solved. By reading the maximum digital grayscale value corresponding to the camera bit depth and performing normalization, data from different device bit depths or different grayscale scales are transformed into a unified scale, facilitating subsequent calculations of the co-location ratio and polarization response. Furthermore, by establishing a fixed index ring neighborhood for each calculation sampling point, and specifying that this neighborhood consists of membrane surface sampling points maintaining a certain horizontal and vertical index distance from the current calculation sampling point, the problem of potential pinhole-related influence when directly using areas too close to the current point is solved, and the problem of membrane texture background mismatch caused by using areas too far away is also avoided. By statistically analyzing the normalized grayscale values of each membrane surface sampling point within the fixed index ring neighborhood at the current polarization acquisition angle and calculating the average grayscale value of the membrane texture neighborhood, a local membrane texture background benchmark can be established for each calculation sampling point at the corresponding polarization angle.
[0035] The setting of grayscale denominator protection quantity involves performing co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculation sampling point under the same polarization acquisition angle, forming co-location polarization response quantity and four-corner polarization response group, specifically including: Read the maximum digital grayscale value corresponding to the camera's bit depth, divide one by the maximum digital grayscale value corresponding to the camera's bit depth, calculate the minimum normalized grayscale interval that the camera can distinguish, and set the minimum normalized grayscale interval as the grayscale denominator protection value. For each calculated sampling point and each polarization acquisition angle, the normalized gray value of the current calculated sampling point under the current polarization acquisition angle is divided by the sum of the average gray value of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle and the gray value denominator protection amount, to calculate the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle. The calculation sampling area is used as a set of polarization response calculation objects, and four co-located polarization response quantities under four polarization acquisition angles are fixedly retained for each calculation sampling point in the calculation sampling area. For each calculation sampling point, the four co-located polarization response quantities of the current calculation sampling point under the four polarization acquisition angles are arranged in a fixed order according to the four polarization acquisition angles to form the four-corner polarization response group of the current calculation sampling point.
[0036] By reading the maximum digital grayscale value corresponding to the camera's bit depth and forming the minimum normalized grayscale interval that the camera can distinguish, and then setting this minimum normalized grayscale interval as the grayscale denominator protection value, the problem that excessively low average grayscale values in the film texture neighborhood may lead to abnormal response amplification during subsequent ratio processing is solved. By performing co-location ratio processing on each calculated sampling point and each polarization acquisition angle, the average grayscale value in the film texture neighborhood and the grayscale denominator protection value of the current normalized grayscale value at the same polarization angle as the current calculated sampling point are compared, forming the co-location polarization response value of the current calculated sampling point at the current polarization angle. This solves the problem that absolute grayscale is greatly affected by light intensity, overall light transmittance of the film material, and camera exposure changes.
[0037] Reference Figure 2 The calculation of the four-corner average transmission response, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response group specifically includes: For each calculation sampling point, read the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles, sum the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles and divide by four to calculate the polarization DC term of the current calculation sampling point. The polarization DC term of the current calculation sampling point is the average transmission response of the four corners of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the first polarization acquisition angle and the co-located polarization response at the third polarization acquisition angle. Subtract the co-located polarization response at the third polarization acquisition angle from the co-located polarization response at the first polarization acquisition angle and divide by two to calculate the first polarization difference term of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the second polarization sampling angle and the co-located polarization response at the fourth polarization sampling angle. Subtract the co-located polarization response at the fourth polarization sampling angle from the co-located polarization response at the second polarization sampling angle and divide by two to calculate the second polarization difference term of the current calculation sampling point. For each calculated sampling point and each polarization acquisition angle, read the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, the polarization DC term of the current calculated sampling point, the first polarization difference term of the current calculated sampling point, the second polarization difference term of the current calculated sampling point, and the current polarization acquisition angle. Multiply the first polarization difference term of the current calculated sampling point by the cosine of twice the current polarization acquisition angle, and multiply the second polarization difference term of the current calculated sampling point by the sine of twice the current polarization acquisition angle. Then, subtract the polarization DC term of the current calculated sampling point, the product of the first polarization difference term of the current calculated sampling point and the cosine of twice the current polarization acquisition angle, and the product of the second polarization difference term of the current calculated sampling point and the sine of twice the current polarization acquisition angle from the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, to calculate the polarization closure residual of the current calculated sampling point under the current polarization acquisition angle.
[0038] By reading and averaging the co-located polarization response at the current sampling point under four polarization acquisition angles, a polarization DC term is formed and used as the four-corner average transmittance response. This solves the problem that the response at a single polarization angle is easily affected by local reflections or angle-sensitive factors, allowing the overall transmittance level of the sampling point to be characterized more stably. By reading the co-located polarization response at the first set of relative polarization angles and the co-located polarization response at the second set of relative polarization angles, and calculating the first and second polarization difference terms, the difference in response under different polarization directions can be characterized, solving the problem that relying solely on average brightness cannot reflect changes in the polarization direction of the film surface. Furthermore, by reading the co-located polarization response, polarization DC term, polarization difference term, and polarization acquisition angle at the current polarization acquisition angle, and subtracting the response portion that can be explained by the average transmittance response and polarization direction differences, a polarization closure residual is formed. This solves the problem that conventional multi-angle detection only superimposes brightness and cannot evaluate response consistency.
[0039] Reference Figure 3 The step of calculating the polarization modulation intensity and polarization closure error based on the first polarization difference term, the second polarization difference term, and the polarization closure residual, and calculating the membrane structure loss amount by combining the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark, specifically includes: For each calculation sampling point, read the first polarization difference term and the second polarization difference term of the current calculation sampling point, sum the square of the first polarization difference term and the square of the second polarization difference term of the current calculation sampling point, and calculate the polarization modulation intensity of the current calculation sampling point. For each calculation sampling point, read the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles, perform a square operation on the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles respectively, sum the four square operation results and divide by four to calculate the average closure residual square of the current calculation sampling point under the four polarization acquisition angles, and record the average closure residual square as the polarization closure error of the current calculation sampling point; For each core sampling point, read the polarization modulation intensity of all calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point, sum all polarization modulation intensities and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to calculate and form the neighborhood polarization modulation intensity benchmark of the current core sampling point. For each core sampling point, read the polarization closure error of all calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point, sum all polarization closure errors and divide by the number of calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point to calculate and form the neighborhood polarization closure error benchmark of the current core sampling point. For each core sampling point, the polarization modulation intensity of the current core sampling point is used as the polarization modulation intensity corresponding to the sampling point, minus the polarization modulation intensity benchmark of the current core sampling point to form the polarization modulation intensity difference of the current core sampling point. The polarization modulation intensity difference of the current core sampling point is divided by the sum of the polarization modulation intensity benchmark of the current core sampling point and the grayscale denominator protection amount to calculate the polarization modulation intensity mutation amount of the current core sampling point. For each core sampling point, the polarization closure error of the current core sampling point is used as the basis for calculating the sampling point. The polarization closure error difference of the current core sampling point is then calculated by subtracting the polarization closure error benchmark of the current core sampling point from the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. The polarization closure error abrupt change of the current core sampling point is then calculated by dividing the polarization closure error difference of the current core sampling point by the sum of the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. For each core sampling point, the amount of membrane structure missing at the current core sampling point is calculated by adding the polarization modulation intensity mutation amount and the polarization closure error mutation amount of the current core sampling point and then dividing by two.
[0040] By reading the first and second polarization difference terms of the current calculation sampling point and forming the polarization modulation intensity, the problem of lacking a unified intensity evaluation for polarization direction differences is solved. By reading the polarization closure residuals of the current calculation sampling point at four polarization acquisition angles and calculating the polarization closure error, the problem of difficulty in stably evaluating membrane structure anomalies due to fluctuations in single-angle residuals is solved. Furthermore, by reading the polarization modulation intensity and polarization closure error of all calculation sampling points within the fixed index ring neighborhood of the current core sampling point, neighborhood polarization modulation intensity benchmarks and neighborhood polarization closure error benchmarks are formed respectively, enabling the current core sampling point to be compared with the surrounding membrane texture background, solving the problem of easy misjudgment when using a unified threshold when the polarization characteristics of different membrane surface regions are inherently different. Further, by comparing the polarization modulation intensity and polarization closure error corresponding to the current core sampling point as the calculation sampling point with the neighborhood benchmarks respectively, corresponding mutation quantities are formed, and the two types of mutation quantities are combined to form the membrane structure missing quantity, solving the problem that membrane structure damage caused by pinholes is difficult to accurately reflect from a single brightness feature.
[0041] Reference Figure 3 The calculation of the average transmittance response benchmark at the four corners of the neighborhood, the calculation of transmittance enhancement based on the average transmittance response at the four corners, and the construction of thresholds for determining membrane structure defects and transmittance enhancement specifically include: For each core sampling point, read the average transmittance response of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point. Sum the average transmittance responses of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to form the benchmark of the average transmittance response of the neighborhood of the current core sampling point. For each core sampling point, the average transmittance response of the four corners corresponding to the current core sampling point when calculating the sampling point is divided by the sum of the average transmittance response reference of the neighboring four corners of the current core sampling point and the grayscale denominator protection amount, to calculate the transmittance enhancement amount of the current core sampling point relative to the average transmittance response reference of the neighboring four corners of the current core sampling point. Read the membrane structure missing amount of all core sampling points in the core sampling area, arrange all membrane structure missing amounts in non-descending order to form a membrane structure missing amount sorting sequence, and configure a sorting value index for each sorting value in the membrane structure missing amount sorting sequence. Read the light transmission enhancement amount of all core sampling points in the core sampling area, arrange all light transmission enhancement amounts in non-descending order to form a light transmission enhancement amount sorting sequence, and configure a sorting value index for each sorting value in the light transmission enhancement amount sorting sequence. In the sequence of membrane structure missing amount, the sort value index is selected as half of the total number of core sampling points to form the median benchmark of membrane structure missing amount; In the light transmission enhancement sorting sequence, the sorting value index is selected as half of the total number of core sampling points to form the median benchmark of light transmission enhancement. For the sorting sequence of membrane structure missing quantities, subtract the median benchmark of membrane structure missing quantity from each sorting value in the sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of membrane structure missing quantity. For the light transmission enhancement sorting sequence, subtract the median light transmission enhancement benchmark from each sorting value in the light transmission enhancement sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of light transmission enhancement. The median baseline of membrane structure loss is added to the mean absolute deviation of membrane structure loss to construct the threshold for determining membrane structure loss. Similarly, the median baseline of light transmission enhancement is added to the mean absolute deviation of light transmission enhancement to construct the threshold for determining light transmission enhancement.
[0042] By reading the average transmittance response of all four corners of the calculated sampling points within the fixed index ring neighborhood of the current core sampling point and calculating a benchmark for the average transmittance response of the neighborhood four corners, the problem of difficulty in uniformly evaluating local transmittance enhancement when there are differences in the overall transmittance background of different membrane areas is solved. By comparing the average transmittance response of the current core sampling point itself with the benchmark for the average transmittance response of its neighborhood four corners, the transmittance enhancement amount is formed, which can reflect the degree of local transmittance anomaly of the current core sampling point relative to the surrounding membrane texture background, solving the problem of difficulty in distinguishing between normal membrane transmittance changes and pinhole transmittance enhancement. Furthermore, by reading the membrane structure missing amount and transmittance enhancement amount of all core sampling points in the core sampling area, sorting them, establishing a sorting value index, forming a median benchmark and a mean absolute deviation, and then constructing two judgment thresholds, the problem of insufficient adaptability of manually fixed thresholds to different materials, different illuminations, and different membrane thicknesses is solved.
[0043] Reference Figure 4 The step of determining each core sampling point individually involves writing the current core sampling point into the pinhole candidate point set when both the membrane structure missing amount and the light transmission enhancement amount are greater than the light transmission enhancement threshold. The pinhole candidate regions are then aggregated according to an eight-adjacency relationship. Specifically, this includes: Read the membrane structure missing amount, light transmission enhancement amount, membrane structure missing amount judgment threshold and light transmission enhancement amount judgment threshold of each core sampling point in the core sampling area, and make judgments on each core sampling point in the core sampling area. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, write the current core sampling point into the pinhole candidate point set. For any two core sampling points in the pinhole candidate point set, an adjacency judgment is performed. When the absolute value of the difference between the horizontal sampling number and the vertical sampling number of the two core sampling points is not greater than one, and the absolute value of the difference between the horizontal sampling number and the vertical sampling number is greater than zero and not greater than two, an eight-adjacency relationship is established between the two core sampling points. Based on the eight-adjacency relationship, the set of pinhole candidate points is divided into several non-overlapping maximum connected regions. Each maximum connected region is used as a pinhole candidate region, and a pinhole candidate region number is assigned to each pinhole candidate region to form a region index set. For each core sampling point within each pinhole candidate region, the membrane structure loss at the current core sampling point is multiplied by the light transmission enhancement at the current core sampling point to calculate the regional positioning intensity that forms the current core sampling point. For each pinhole candidate region, the coordinate position of each core sampling point in the membrane detection coordinate system within the current pinhole candidate region is multiplied with the regional positioning intensity of the same core sampling point. The sum of the product results corresponding to all core sampling points within the current pinhole candidate region is then divided by the sum of the regional positioning intensities of all core sampling points within the current pinhole candidate region to calculate the intensity weighted center position of the current pinhole candidate region. For each pinhole candidate region, count the number of core sampling points in the current pinhole candidate region, multiply the number of core sampling points in the current pinhole candidate region by the horizontal adjacent sampling point distance and the vertical adjacent sampling point distance, and calculate the physical area forming the current pinhole candidate region; For each pinhole candidate region, read the regional positioning intensity of all core sampling points in the current pinhole candidate region, sum the regional positioning intensity of all core sampling points in the current pinhole candidate region and divide it by the number of core sampling points in the current pinhole candidate region to calculate the regional score of the current pinhole candidate region.
[0044] By reading the membrane structure loss, light transmission enhancement, and corresponding judgment threshold of each core sampling point within the core sampling area, and adding the current core sampling point to the pinhole candidate point set when both indicators meet the conditions, the problem of easily mistaking normal bright spots, material textures, or local noise as pinholes by relying solely on a single abnormal indicator is solved. By performing adjacency judgment on any two core sampling points in the pinhole candidate point set and establishing an eight-adjacency relationship, and then dividing the candidate point set into non-overlapping maximum connected regions, the problems of single-point abnormal dispersion, unclear defect region boundaries, and difficulty in merging multiple pinhole candidate points are solved. Furthermore, by combining the membrane structure loss and light transmission enhancement to form a regional positioning intensity, and using the regional positioning intensity to calculate the intensity-weighted center position, the defect location can be more biased towards the region with strong response, rather than simply using the geometric center, solving the problem of inaccurate positioning when the response within the pinhole region is uneven. By statistically analyzing the number of core sampling points within the region and combining it with the sampling point spacing to form the physical area, and by forming a regional score through the regional positioning intensity, the problem of the detection results only stating "presence or absence of defects" without describing the location, extent, and severity is solved.
[0045] Reference Figure 4 The calculation of the intensity-weighted center location, physical area, and region score of the pinhole candidate region, combined to generate a pinhole defect output record, and the non-generation of pinhole candidate region, intensity-weighted center location, physical area, and region score for core sampling points not written into the pinhole candidate point set, specifically includes: Read the region index set, extract the intensity weighted center position, physical area and region score of each pinhole candidate region, and combine the intensity weighted center position, physical area and region score of the current pinhole candidate region to generate the corresponding pinhole defect output record. Write all pinhole defect output records generated from each pinhole candidate region into the pinhole defect output record set; When the region index set is empty, the pinhole defect output record set is set to an empty set; Read the pinhole defect output record set. When the pinhole defect output record set is empty, generate a detection status of no detected pinhole defects. Read the pinhole defect output record set. When the pinhole defect output record set is not empty, generate the detection status of the detected pinhole defect and output each pinhole defect output record in the pinhole defect output record set. Read the core sampling area and the set of pinhole candidate points. For core sampling points located within the core sampling area but not written into the set of pinhole candidate points, do not generate pinhole candidate regions, intensity weighted center positions, physical areas, or region scores. Also, ensure that the set of pinhole defect output records retains only the pinhole defect output records generated by the pinhole candidate regions.
[0046] By reading the region index set and extracting the intensity-weighted center position, physical area, and region score for each pinhole candidate region, and then combining them to generate the corresponding pinhole defect output record for the pinhole candidate region, the problem of lacking structured records in the detection results and the difficulty of subsequent equipment reading and processing is solved. By writing all the records generated for each pinhole candidate region into the pinhole defect output record set, multiple defect regions can be output in a unified set format, which facilitates subsequent alarm, marking, statistics, and quality traceability. Furthermore, by setting the pinhole defect output record set to an empty set when the region index set is empty, and generating a detection status of undetected or detected pinhole defects based on whether the output record set is empty, the problem of unclear expression of the no-defect status and the possibility of the system misreading empty data is solved. Further, by reading the core sampling area and the pinhole candidate point set, it is determined that core sampling points not written into the pinhole candidate point set will not generate pinhole candidate regions, intensity-weighted center positions, physical areas, and region scores, and only the output records generated by the pinhole candidate regions are retained, solving the problem of normal sampling points being mistakenly generated as defect records or generating redundant output.
[0047] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0048] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A visual inspection method for pinhole defects in food packaging film, characterized in that, include: Establish a coordinate system for the detection of food packaging film surface, divide the calculation sampling points and core sampling points. The core sampling points belong to the calculation sampling points. Set four polarization acquisition angles and acquire the polarization grayscale channels of the same detection area. The digital grayscale values under each polarization acquisition angle are collected and converted into normalized grayscale. A fixed index ring neighborhood is established for the calculation sampling points and core sampling points. The average grayscale of the membrane texture neighborhood of each calculation sampling point under each polarization acquisition angle is calculated. Set a grayscale denominator protection value, and perform co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculation sampling point under the same polarization acquisition angle to form the co-location polarization response value and the four-corner polarization response group. Calculate the average transmission response at the four corners, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response set; The polarization modulation intensity and polarization closure error are calculated based on the first polarization difference term, the second polarization difference term, and the polarization closure residual. The amount of membrane structure missing is then calculated by combining the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark. Calculate the average light transmittance response benchmark at the four corners of the neighborhood, calculate the light transmittance enhancement based on the average light transmittance response at the four corners, and construct the threshold for determining the amount of membrane structure loss and the threshold for determining the amount of light transmittance enhancement. The core sampling points are judged one by one. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, the current core sampling point is written into the pinhole candidate point set and the pinhole candidate region is aggregated according to the eight-adjacency relationship. Calculate the intensity-weighted center location, physical area, and region score of the pinhole candidate region, combine them to generate a pinhole defect output record, and do not generate pinhole candidate regions, intensity-weighted center locations, physical areas, and region scores for core sampling points that are not written into the pinhole candidate point set.
2. The visual inspection method for pinhole defects in food packaging film according to claim 1, characterized in that, The establishment of a film surface detection coordinate system for food packaging film involves dividing the area into computational sampling points and core sampling points. The core sampling points are part of the computational sampling points. Four polarization acquisition angles are set, and polarization grayscale channels within the same detection area are acquired. Specifically, this includes: Unfold the food packaging film into a two-dimensional inspection surface; Establish a film surface detection coordinate system within the camera's detection field of view. Set the origin of the coordinate system at the intersection of the upper left corner of the detection field of view and the food packaging film feed boundary. Set the horizontal coordinate axis from left to right along the width direction of the food packaging film, and set the vertical coordinate axis from the feed side to the discharge side along the running direction of the food packaging film. A set of membrane surface sampling points is established within the camera's detection field of view. The set of membrane surface sampling points consists of all membrane surface sampling points. Each membrane surface sampling point is defined by a horizontal sampling number, a vertical sampling number, the distance between horizontally adjacent sampling points, and the distance between vertically adjacent sampling points. The horizontal sampling number increases sequentially from zero to the total number of horizontal sampling points minus one. The vertical sampling number increases sequentially from zero to the total number of vertical sampling points minus one. The total number of horizontal sampling points and the total number of vertical sampling points are both not less than twenty-six. A calculation sampling area is established in the set of membrane surface sampling points. The calculation sampling area consists of membrane surface sampling points with horizontal sampling number not less than six and not greater than the total number of horizontal sampling points minus seven, and vertical sampling number not less than six and not greater than the total number of vertical sampling points minus seven. The membrane surface sampling points in the calculation sampling area are used as calculation sampling points. A core sampling area is established in the set of membrane surface sampling points. The core sampling area consists of membrane surface sampling points with a horizontal sampling number of not less than twelve and not greater than the total number of horizontal sampling points minus thirteen, and a vertical sampling number of not less than twelve and not greater than the total number of vertical sampling points minus thirteen. The membrane surface sampling points in the core sampling area are used as core sampling points. Core sampling points are calculated sampling points, and the total number of membrane surface sampling points in the core sampling area is counted as the total number of core sampling points. Four polarization acquisition angles are set, and the four polarization acquisition angles are set to zero degrees, forty-five degrees, ninety degrees and one hundred and thirty-five degrees in a fixed order, so that the same sampling point on the film surface can form a grayscale response under the four polarization acquisition angles. The same detection area of the food packaging film is simultaneously sampled at four polarization acquisition angles, so that each film sampling point forms four polarization grayscale channels corresponding to the four polarization acquisition angles under the same acquisition trigger. The four polarization grayscale channels only have the difference of polarization acquisition angle, and the tension of the food packaging film, the brightness of the light source, the camera exposure time and the film running speed are kept under the same detection conditions.
3. The visual inspection method for pinhole defects in food packaging film according to claim 2, characterized in that, The process involves acquiring digital grayscale values at each polarization acquisition angle and converting them into normalized grayscale values. A fixed index ring neighborhood is established for the calculation sampling points and core sampling points. The average grayscale value of the membrane texture neighborhood at each calculation sampling point at each polarization acquisition angle is calculated. Specifically, this includes: At each polarization acquisition angle, digital grayscale values are acquired at the sampling points on the film surface, and the digital grayscale values are limited to integers from zero to the maximum digital grayscale value corresponding to the camera bit depth; Read the maximum digital grayscale value corresponding to the camera bit depth, divide the digital grayscale value of each sampling point on the film surface under each polarization acquisition angle by the maximum digital grayscale value corresponding to the camera bit depth, and convert it into the normalized grayscale of the sampling point on the film surface under the corresponding polarization acquisition angle. A fixed index ring neighborhood is established for each computational sampling point. Each core sampling point is used as a computational sampling point and corresponds to a fixed index ring neighborhood in the same way. The membrane sampling points in the fixed index ring neighborhood corresponding to the core sampling point belong to the computational sampling points in the computational sampling area. The fixed index ring neighborhood corresponding to each computational sampling point consists of membrane sampling points in the camera detection field of view that satisfy the condition that the absolute value of the difference between the horizontal neighborhood sampling number and the horizontal sampling number of the current computational sampling point, and the absolute value of the difference between the vertical neighborhood sampling number and the vertical sampling number of the current computational sampling point are not less than two and not greater than six. For each calculated sampling point and each polarization acquisition angle, the normalized grayscale of all membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point is counted under the current polarization acquisition angle. The sum of the normalized grayscale is divided by the number of membrane surface sampling points in the fixed index ring neighborhood corresponding to the current calculated sampling point to calculate the average grayscale of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle.
4. The visual inspection method for pinhole defects in food packaging film according to claim 3, characterized in that, The setting of grayscale denominator protection quantity involves performing co-location ratio processing on the normalized grayscale and the average grayscale of the film texture neighborhood at the same calculation sampling point under the same polarization acquisition angle, forming co-location polarization response quantity and four-corner polarization response group, specifically including: Read the maximum digital grayscale value corresponding to the camera's bit depth, divide one by the maximum digital grayscale value corresponding to the camera's bit depth, calculate the minimum normalized grayscale interval that the camera can distinguish, and set the minimum normalized grayscale interval as the grayscale denominator protection value. For each calculated sampling point and each polarization acquisition angle, the normalized gray value of the current calculated sampling point under the current polarization acquisition angle is divided by the sum of the average gray value of the membrane texture neighborhood of the current calculated sampling point under the current polarization acquisition angle and the gray value denominator protection amount, to calculate the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle. The calculation sampling area is used as a set of polarization response calculation objects, and four co-located polarization response quantities under four polarization acquisition angles are fixedly retained for each calculation sampling point in the calculation sampling area. For each calculation sampling point, the four co-located polarization response quantities of the current calculation sampling point under the four polarization acquisition angles are arranged in a fixed order according to the four polarization acquisition angles to form the four-corner polarization response group of the current calculation sampling point.
5. The visual inspection method for pinhole defects in food packaging film according to claim 4, characterized in that, The calculation of the four-corner average transmission response, the first polarization difference term, the second polarization difference term, and the polarization closure residual based on the four-corner polarization response group specifically includes: For each calculation sampling point, read the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles, sum the four co-located polarization response values of the current calculation sampling point under the four polarization acquisition angles and divide by four to calculate the polarization DC term of the current calculation sampling point. The polarization DC term of the current calculation sampling point is the average transmission response of the four corners of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the first polarization acquisition angle and the co-located polarization response at the third polarization acquisition angle. Subtract the co-located polarization response at the third polarization acquisition angle from the co-located polarization response at the first polarization acquisition angle and divide by two to calculate the first polarization difference term of the current calculation sampling point. For each calculation sampling point, read the co-located polarization response at the second polarization sampling angle and the co-located polarization response at the fourth polarization sampling angle. Subtract the co-located polarization response at the fourth polarization sampling angle from the co-located polarization response at the second polarization sampling angle and divide by two to calculate the second polarization difference term of the current calculation sampling point. For each calculated sampling point and each polarization acquisition angle, read the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, the polarization DC term of the current calculated sampling point, the first polarization difference term of the current calculated sampling point, the second polarization difference term of the current calculated sampling point, and the current polarization acquisition angle. Multiply the first polarization difference term of the current calculated sampling point by the cosine of twice the current polarization acquisition angle, and multiply the second polarization difference term of the current calculated sampling point by the sine of twice the current polarization acquisition angle. Then, subtract the polarization DC term of the current calculated sampling point, the product of the first polarization difference term of the current calculated sampling point and the cosine of twice the current polarization acquisition angle, and the product of the second polarization difference term of the current calculated sampling point and the sine of twice the current polarization acquisition angle from the co-located polarization response of the current calculated sampling point under the current polarization acquisition angle, to calculate the polarization closure residual of the current calculated sampling point under the current polarization acquisition angle.
6. The visual inspection method for pinhole defects in food packaging film according to claim 5, characterized in that, The calculation of polarization modulation intensity and polarization closure error based on the first polarization difference term, the second polarization difference term, and the polarization closure residual, and the calculation of the membrane structure defect amount based on the neighborhood polarization modulation intensity benchmark and the neighborhood polarization closure error benchmark, specifically includes: For each calculation sampling point, read the first polarization difference term and the second polarization difference term of the current calculation sampling point, sum the square of the first polarization difference term and the square of the second polarization difference term of the current calculation sampling point, and calculate the polarization modulation intensity of the current calculation sampling point. For each calculation sampling point, read the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles, perform a square operation on the four polarization closure residuals of the current calculation sampling point under the four polarization acquisition angles respectively, sum the four square operation results and divide by four to calculate the average closure residual square of the current calculation sampling point under the four polarization acquisition angles, and record the average closure residual square as the polarization closure error of the current calculation sampling point; For each core sampling point, read the polarization modulation intensity of all calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point, sum all polarization modulation intensities and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to calculate and form the neighborhood polarization modulation intensity benchmark of the current core sampling point. For each core sampling point, read the polarization closure error of all calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point, sum all polarization closure errors and divide by the number of calculated sampling points in the neighborhood of the fixed index ring corresponding to the current core sampling point to calculate and form the neighborhood polarization closure error benchmark of the current core sampling point. For each core sampling point, the polarization modulation intensity of the current core sampling point is used as the polarization modulation intensity corresponding to the sampling point, minus the polarization modulation intensity benchmark of the current core sampling point to form the polarization modulation intensity difference of the current core sampling point. The polarization modulation intensity difference of the current core sampling point is divided by the sum of the polarization modulation intensity benchmark of the current core sampling point and the grayscale denominator protection amount to calculate the polarization modulation intensity mutation amount of the current core sampling point. For each core sampling point, the polarization closure error of the current core sampling point is used as the basis for calculating the sampling point. The polarization closure error difference of the current core sampling point is then calculated by subtracting the polarization closure error benchmark of the current core sampling point from the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. The polarization closure error abrupt change of the current core sampling point is then calculated by dividing the polarization closure error difference of the current core sampling point by the sum of the polarization closure error benchmark of the current core sampling point and the grayscale denominator protection amount. For each core sampling point, the amount of membrane structure missing at the current core sampling point is calculated by adding the polarization modulation intensity mutation amount and the polarization closure error mutation amount of the current core sampling point and then dividing by two.
7. The visual inspection method for pinhole defects in food packaging film according to claim 6, characterized in that, The calculation of the average transmittance response benchmark at the four corners of the neighborhood involves calculating the transmittance enhancement based on the average transmittance response at the four corners, and constructing thresholds for determining the amount of membrane structure loss and the amount of transmittance enhancement. Specifically, this includes: For each core sampling point, read the average transmittance response of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point. Sum the average transmittance responses of all four corners of the calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point and divide by the number of calculated sampling points in the fixed index ring neighborhood corresponding to the current core sampling point to form the benchmark of the average transmittance response of the neighborhood of the current core sampling point. For each core sampling point, the average transmittance response of the four corners corresponding to the current core sampling point when calculating the sampling point is divided by the sum of the average transmittance response reference of the neighboring four corners of the current core sampling point and the grayscale denominator protection amount, to calculate the transmittance enhancement amount of the current core sampling point relative to the average transmittance response reference of the neighboring four corners of the current core sampling point. Read the membrane structure missing amount of all core sampling points in the core sampling area, arrange all membrane structure missing amounts in non-descending order to form a membrane structure missing amount sorting sequence, and configure a sorting value index for each sorting value in the membrane structure missing amount sorting sequence. Read the light transmission enhancement amount of all core sampling points in the core sampling area, arrange all light transmission enhancement amounts in non-descending order to form a light transmission enhancement amount sorting sequence, and configure a sorting value index for each sorting value in the light transmission enhancement amount sorting sequence. In the sequence of membrane structure missing amount, the sort value index is selected as half of the total number of core sampling points to form the median benchmark of membrane structure missing amount; In the light transmission enhancement sorting sequence, the sorting value index is selected as half of the total number of core sampling points to form the median benchmark of light transmission enhancement. For the sorting sequence of membrane structure missing quantities, subtract the median benchmark of membrane structure missing quantity from each sorting value in the sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of membrane structure missing quantity. For the light transmission enhancement sorting sequence, subtract the median light transmission enhancement benchmark from each sorting value in the light transmission enhancement sorting sequence and take the absolute value. Sum all the absolute values and divide by the total number of core sampling points to calculate the average absolute deviation of light transmission enhancement. The median baseline of membrane structure loss is added to the mean absolute deviation of membrane structure loss to construct the threshold for determining membrane structure loss. Similarly, the median baseline of light transmission enhancement is added to the mean absolute deviation of light transmission enhancement to construct the threshold for determining light transmission enhancement.
8. The visual inspection method for pinhole defects in food packaging film according to claim 7, characterized in that, The step of determining each core sampling point individually involves writing the current core sampling point into the pinhole candidate point set when both the membrane structure missing amount at the current core sampling point and the light transmission enhancement amount at the current core sampling point exceed the light transmission enhancement threshold. The pinhole candidate regions are then aggregated according to an eight-adjacency relationship. Specifically, this includes: Read the membrane structure missing amount, light transmission enhancement amount, membrane structure missing amount judgment threshold and light transmission enhancement amount judgment threshold of each core sampling point in the core sampling area, and make judgments on each core sampling point in the core sampling area. When the membrane structure missing amount of the current core sampling point is greater than the membrane structure missing amount judgment threshold and the light transmission enhancement amount of the current core sampling point is greater than the light transmission enhancement amount judgment threshold, write the current core sampling point into the pinhole candidate point set. For any two core sampling points in the pinhole candidate point set, an adjacency judgment is performed. When the absolute value of the difference between the horizontal sampling number and the vertical sampling number of the two core sampling points is not greater than one, and the absolute value of the difference between the horizontal sampling number and the vertical sampling number is greater than zero and not greater than two, an eight-adjacency relationship is established between the two core sampling points. Based on the eight-adjacency relationship, the set of pinhole candidate points is divided into several non-overlapping maximum connected regions. Each maximum connected region is used as a pinhole candidate region, and a pinhole candidate region number is assigned to each pinhole candidate region to form a region index set. For each core sampling point within each pinhole candidate region, the membrane structure loss at the current core sampling point is multiplied by the light transmission enhancement at the current core sampling point to calculate the regional positioning intensity that forms the current core sampling point. For each pinhole candidate region, the coordinate position of each core sampling point in the membrane detection coordinate system within the current pinhole candidate region is multiplied with the regional positioning intensity of the same core sampling point. The sum of the product results corresponding to all core sampling points within the current pinhole candidate region is then divided by the sum of the regional positioning intensities of all core sampling points within the current pinhole candidate region to calculate the intensity weighted center position of the current pinhole candidate region. For each pinhole candidate region, count the number of core sampling points in the current pinhole candidate region, multiply the number of core sampling points in the current pinhole candidate region by the horizontal adjacent sampling point distance and the vertical adjacent sampling point distance, and calculate the physical area forming the current pinhole candidate region; For each pinhole candidate region, read the regional positioning intensity of all core sampling points in the current pinhole candidate region, sum the regional positioning intensity of all core sampling points in the current pinhole candidate region and divide it by the number of core sampling points in the current pinhole candidate region to calculate the regional score of the current pinhole candidate region.
9. A visual inspection method for pinhole defects in food packaging film according to claim 8, characterized in that, The calculation of the intensity-weighted center location, physical area, and region score of the pinhole candidate region is combined to generate a pinhole defect output record. For core sampling points not written into the pinhole candidate point set, no pinhole candidate region, intensity-weighted center location, physical area, or region score is generated. Specifically, this includes: Read the region index set, extract the intensity weighted center position, physical area and region score of each pinhole candidate region, and combine the intensity weighted center position, physical area and region score of the current pinhole candidate region to generate the corresponding pinhole defect output record. Write all pinhole defect output records generated from each pinhole candidate region into the pinhole defect output record set; When the region index set is empty, the pinhole defect output record set is set to an empty set; Read the pinhole defect output record set. When the pinhole defect output record set is empty, generate a detection status of no detected pinhole defects. Read the pinhole defect output record set. When the pinhole defect output record set is not empty, generate the detection status of the detected pinhole defect and output each pinhole defect output record in the pinhole defect output record set. Read the core sampling area and the set of pinhole candidate points. For core sampling points located within the core sampling area but not written into the set of pinhole candidate points, do not generate pinhole candidate regions, intensity weighted center positions, physical areas, or region scores. Also, ensure that the set of pinhole defect output records retains only the pinhole defect output records generated by the pinhole candidate regions.
