A machine vision-based online detection method and system for food packaging airtightness
By using an improved MaskR-CNN network and grayscale stretching preprocessing, the problems of false detection and missed detection in food packaging sealing inspection were solved. Stable detection and adaptive threshold updating of irregularly shaped packaging were achieved, improving the adaptability and accuracy of the detection system.
Patent Information
- Application Number
- CN202610744052.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-27
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2046-05-27
AI Technical Summary
Existing methods for testing the airtightness of food packaging have problems such as being destructive, offline testing, limited sampling ratio, and high dependence on manual labor. Furthermore, in the production environment, surface reflection, complex printing patterns, background interference from conveyor belts, and changes in lighting make it difficult to stably extract the contour of the sealed area, leading to false detections and missed detections.
An improved MaskR-CNN network is adopted, which replaces some standard convolutions in the deep residual backbone feature extraction network with deformable convolutions, adds a dual-path attention module and an edge-aware sub-branch, and combines gray-scale stretching preprocessing and multi-index judgment to adaptively update the threshold, thereby reducing the false detection and false negative rates.
It improves the feature extraction capability for irregular food packaging shapes, enhances edge perception and adaptive threshold, reduces false detection and false negative rates, and improves the adaptability and accuracy of the online food packaging sealing detection system.
Smart Images

Figure CN122415587B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of online monitoring technology. More specifically, this invention relates to a machine vision-based online detection method and system for the airtightness of food packaging. Background Technology
[0002] The airtightness of food packaging directly affects the shelf life, quality and safety of food, and the brand reputation of enterprises. Current airtightness testing methods, such as water bath methods, vacuum attenuation methods, or manual pressure leak detection, generally suffer from problems such as destructive testing, limited sampling ratios, offline testing processes, and high reliance on manual labor, making it difficult to meet the online inspection needs of continuous production lines. With the development of machine vision and deep learning technologies, image-based online inspection methods can perform non-contact identification of packaging surfaces. However, in actual production environments, food packaging is often affected by factors such as surface reflection, complex printed patterns, background interference from conveyor belts, and changes in lighting and noise, making it difficult to stably extract the contour of the sealed area, thus leading to false positives and false negatives.
[0003] While instance segmentation networks, such as Mask R-CNN, can extract deep semantic features and achieve pixel-level segmentation, their standard convolutional structure is insufficiently adaptable to random geometric deformations, pose shifts, and sealing edge curvatures that occur during packaging and transmission. Furthermore, conventional feature pyramids lack the ability to filter and enhance effective channel information during multi-scale fusion, easily introducing background noise. Traditional mask branches have limited ability to perceive edge details, and in areas with high boundary accuracy requirements, such as sealing contours, they are prone to problems like blurred edge segmentation, positioning errors, and insufficient response to subtle defects. Conventional loss functions also struggle to specifically constrain edge pixel errors. In addition, the background grayscale distribution of production line images fluctuates with production batches, materials, and equipment status; single global preprocessing methods and fixed manual thresholds are difficult to maintain stability over long periods, potentially reducing the reliability and adaptability of online detection systems. Summary of the Invention
[0004] To address the technical problems of relying on offline sampling inspection, unstable edge extraction, insufficient defect identification, and difficulty in adaptive thresholding, this invention proposes an online detection method and system for the airtightness of food packaging based on machine vision, which can enhance edge perception and adaptive thresholding, and reduce the false detection and missed detection rates.
[0005] In a first aspect, the present invention provides an online detection method for the airtightness of food packaging based on machine vision, comprising: a model training phase: constructing an improved MaskR-CNN network, replacing some standard convolutions in the backbone feature extraction part with deformable convolutions, adding a dual-path attention module at the lateral connection of the feature pyramid, and obtaining the channel weights by weighting the global average pooling vector and the global max pooling vector with coefficients determined by the sum of the absolute value of the standard deviation of the feature map divided by the arithmetic mean and a preset small constant, and then applying the Sigmoid function; adding an edge-aware sub-branch to the mask branch; extracting the gradient magnitude using the Sobel operator and concatenating it with the original mask features pixel by pixel. The output edge mask is trained using Dice loss and edge-sensitive weighted cross-entropy loss. In the online detection stage, images of conveyor belt packaging are acquired and preprocessed. The preprocessed images are input into the trained network, and the output edge mask and the main mask are weighted and fused into a final mask according to the weight determined by the edge pixel ratio. The sealing contour is extracted, and the rate of curvature change and width uniformity are calculated and judged. If the number of qualified samples does not reach the preset number, a preset initial threshold is used for judgment. After reaching the preset number, if both indicators are lower than the threshold formed by the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, it is judged as qualified. Otherwise, it is judged as unqualified, and the coordinates are output and not included in the threshold update.
[0006] By adopting the above technical solutions, some standard two-dimensional convolutional layers in the deep residual backbone feature extraction network are replaced with deformable convolutions, improving the feature extraction capability for irregular food packaging shapes. At the lateral connections of the multi-scale feature pyramid network, a dual-path attention module based on weights calculated using specific statistics is used to highlight key region features and suppress some background interference. An edge-aware sub-branch is added to the fully convolutional instance mask branch, which, together with the edge extraction operator and the edge-sensitive joint cross-entropy loss function, enhances the ability of the mask region convolutional neural network to locate the blurred boundaries of food packaging. The grayscale stretching preprocessing mechanism used in the online detection stage can reduce the impact of changes in production line lighting, and adaptively update the judgment threshold based on the statistical data of historical qualified samples in the same batch during the multi-index judgment stage, thereby reducing the false judgment rate and improving the adaptability of the online food packaging sealing detection system.
[0007] Preferably, the acquisition and preprocessing of the conveyor belt packaging image includes: performing smoothing filtering and noise reduction processing on the acquired packaging image; extracting the background area of the conveyor belt through threshold segmentation and calculating the gray-scale distribution statistical characteristics of the background area; determining a lower limit gray-scale value and an upper limit gray-scale value based on the gray-scale distribution statistical characteristics, wherein the lower limit gray-scale value and the upper limit gray-scale value are determined based on a preset truncation ratio of the total number of pixels in the background area; and using the determined lower limit gray-scale value and upper limit gray-scale value, performing gray-scale stretching and truncation processing on the original image pixels to obtain a preprocessed image with enhanced contrast.
[0008] By adopting the above technical solution, the acquired conveyor belt packaging images are denoised. While suppressing environmental noise interference, the blurring effect on the key edge features of the food packaging sealing line is minimized. By generating a pre-processed image with a more stable grayscale distribution, the adverse interference of high-frequency reflective noise from the production line on the contour extraction of the food packaging sealing area is effectively reduced.
[0009] Preferably, the channel weights are obtained by: calculating the standard deviation and arithmetic mean of the intensity of all pixels in each channel of the feature map; determining the weight coefficient, which is the sum of the absolute value of the difference between the standard deviation and the arithmetic mean and a preset small constant; using the weight coefficient as the weight of the global max pooling vector, subtracting the weight coefficient from 1 as the weight of the global average pooling vector, adding the corresponding bits of the two weighted vectors and passing them through the Sigmoid function to obtain the channel absolute weight allocation sequence; setting a preset upper limit and a suppression factor, and during backpropagation, if the weight coefficient is greater than the preset upper limit, then the learning rate or gradient of the spatial offset parameter of the corresponding deformable convolutional layer is multiplied by the suppression factor for shrinkage restriction.
[0010] By employing the above technical solution, the standard deviation and arithmetic mean of the intensity of all pixels in the current channel of the feature map are calculated to obtain the local mutation response coefficient. This coefficient is then used as a weighting parameter to perform a weighted summation of the global average pooling vector and the global max pooling vector. The result is then processed by an activation function to obtain the channel absolute weight allocation sequence, thereby enhancing the effective semantic channel response in the convolutional neural network of the mask region. During backpropagation of the model parameters, the weight coefficients are compared with the preset upper limit to trigger the shrinkage constraint logic, suppressing excessive jitter of the receptive field caused by strong local mutation regions, thereby improving the stability of the network model convergence.
[0011] Preferably, the step of extracting gradient magnitude using the Sobel operator includes: determining the side length resolution of the candidate target region feature map derived from the RoIAlign layer; for the input feature map with a side length resolution of 14×14 pixels, applying a discrete differential Sobel filter with a kernel matrix side length of 3×3 to the entire grid with a span of 1 and zero-pixel filling of the outer boundary; for the input feature map with a side length resolution of 28×28 pixels, using a 5×5 smooth Sobel filter with fixed parameters, performing a convolution operation with the same phase length and corresponding boundary filling method to obtain the horizontal gradient matrix representing the horizontal gray-level change and the vertical gradient matrix representing the vertical gray-level change.
[0012] By adopting the above technical solution, the side length resolution of the feature map of the candidate target region derived from the candidate target region alignment layer is verified, and the 3×3 discrete differential filter or 5×5 smooth filter is adaptively switched to decouple the gradient matrix in the horizontal and vertical directions, thereby enhancing the adaptive ability and robustness of the mask region convolutional neural network for extracting the gradient features of food packaging target edges at different multi-scales.
[0013] Preferably, the step of multiplying the original mask features by pixels and then concatenating them to output the edge mask includes: calculating the sum of the squares of the horizontal and vertical gradients obtained by the Sobel operator and taking the square root to obtain an undirected absolute metric edge activation intensity scalar; concatenating the edge enhancement feature map with the original mask features along the channel dimension to form a hybrid feature tensor; inputting the hybrid feature tensor into a series of convolutional layers for feature mapping, wherein the first convolutional layer uses a 3×3 convolutional kernel and outputs 256 channels, the second convolutional layer outputs the same number of channels and connects them to activation functions, and finally generates an edge probability map through a single-channel output layer, and uses the edge probability map as the edge mask.
[0014] By employing the above technical solution, the gradient feature values in the horizontal and vertical directions are calculated to generate an undirected absolute measure edge activation intensity scalar. This scalar is then multiplied pixel-by-pixel with the feature weight variables after activation by the original mask branches to generate an edge enhancement feature layer. The original feature map array is extracted, and the edge enhancement feature layer is stitched and mapped along the channel dimension with the original feature map array that retains global semantics to generate a continuous edge probability map. This enhances the response intensity of the sealed edge region of food packaging, reduces the interference of background noise in flat areas on edge prediction, and thus improves the overall accuracy of food packaging sealed edge positioning.
[0015] Preferably, the output edge mask and the main mask are weighted and fused into a final state mask according to the weight determined by the edge pixel ratio, including: converting the edge mask into a binary edge map using a preset pixel threshold, and counting the number of edge pixels with a value of 1 in the target region or bounding box; dividing the number of edge pixels by the total number of pixels in the target region or bounding box to obtain the edge pixel ratio; adding a reference constant to the calculated edge pixel ratio, and taking the minimum value of the sum and the constant value 1 to obtain the fusion weight for the current judgment period; taking each pixel of the matrix as the origin, multiplying the edge mask by the fusion weight, multiplying the main mask by 1 and subtracting the fusion weight to obtain the main mask weight, and adding the two pixel by pixel to obtain the final state mask matrix.
[0016] Preferably, the method of jointly training the network using Dice loss and edge-sensitive weighted cross-entropy loss includes: calculating the Dice loss between the main mask prediction result and the real region mask; generating real edges from the real region mask and dividing pixels within 3 pixels of the real edges into edge-sensitive regions using Chebyshev distance or morphological dilation; calculating the proportion of real edge pixels to the total number of pixels in the real mask, and using 1 plus this proportion as the weighting coefficient for the edge-sensitive regions; calculating the cross-entropy loss between the edge mask prediction result and the real edges, where the loss of pixels located in the edge-sensitive regions is multiplied by the weighting coefficient, and the loss weight of the remaining pixels is 1, to obtain the edge-sensitive weighted cross-entropy loss; and weighting and summing the Dice loss and the edge-sensitive weighted cross-entropy loss according to a preset ratio, using the sum as the total loss for backpropagation and network parameter updates.
[0017] Preferably, the step of extracting the sealing contour and calculating the rate of curvature change and width uniformity includes: processing the final state mask using the Canny operator to extract the closed-loop pixel sequence of the sealing contour; calculating the instantaneous first-order bending deflection difference of the curve angle measured by the second-order parameter direction change at the center position of each adjacent connected three points using the partial derivative of the quadratic spline interpolation function, and obtaining the overall variance as the measured rate of curvature change; calculating the sequence of shortest perpendicular distances between the inner and outer contours of the sealing contour, and taking the statistical variance of the deviation set as the width uniformity.
[0018] Preferably, the determination includes: setting a cache list of historical qualified samples with a preset length of M; if the number of qualified samples in the list is less than M, then a preset initial threshold is used as the set threshold; if the number of qualified samples in the list has reached M, then the mean and standard deviation of all historical curvature change rates and width uniformity in the list are calculated respectively, and the mean plus twice the standard deviation is used as the set threshold; if the curvature change rate and width uniformity of the current sample are both lower than the set threshold, then it is determined to be qualified, and the two indicators of the current sample are written into the cache list; when the list is full, the earliest data is removed and written in according to the first-in-first-out rule.
[0019] Secondly, this invention provides an online detection system for the airtightness of food packaging based on machine vision, comprising the following modules: a model training module: constructing an improved MaskR-CNN network, replacing some standard convolutions in the backbone feature extraction part with deformable convolutions, adding a dual-path attention module at the horizontal connection of the feature pyramid, and obtaining the channel weights by weighting the global average pooling vector and the global max pooling vector with coefficients determined by the sum of the absolute value of the standard deviation of the feature map divided by the arithmetic mean and a preset small constant, and then applying the Sigmoid function; adding an edge-aware sub-branch to the mask branch, extracting the gradient magnitude using the Sobel operator, and concatenating it with the original mask features pixel by pixel. The output edge mask is used to train the network using Dice loss and edge-sensitive weighted cross-entropy loss. The online detection module acquires and preprocesses images of conveyor belt packaging, inputs the preprocessed images into the trained network, outputs the edge mask and the main mask, and fuses them into a final mask by weighting according to the weight determined by the proportion of edge pixels. It extracts the sealing contour and calculates the rate of curvature change and width uniformity and makes a judgment. If the number of qualified samples does not reach the preset number, it is judged by the preset initial threshold. After reaching the preset number, if both indicators are lower than the threshold composed of the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, it is judged as qualified. Otherwise, it is judged as unqualified and the coordinates are output and not included in the threshold update.
[0020] By adopting the above technical solution, utilizing the built-in image preprocessing logic, and employing Gaussian smoothing filtering for noise reduction, the system minimizes the blurring effect on key edge features of the food packaging sealing line while suppressing environmental noise interference. Combining Otsu's threshold segmentation method with a double-ended pixel accumulation mechanism based on grayscale histogram statistics, a double-ended grayscale stretching and truncation algorithm is executed to convert the original image's grayscale pixels into preprocessed image pixels with a more stable output grayscale distribution. This effectively reduces the adverse effects of high-frequency reflective noise from the production line on the extraction of contour features of the food packaging sealing area, thereby comprehensively ensuring the long-term stable operation of the online food packaging sealing inspection system.
[0021] The present invention has the following beneficial effects: This invention replaces some standard two-dimensional convolutional layers in the deep residual backbone feature extraction network with deformable convolutions, enhancing the feature extraction capability for irregular packaging shapes. A dual-path attention module with weights calculated based on specific statistics is introduced at the lateral connections of the feature pyramid network to highlight key region features and suppress some background interference. An edge-aware sub-branch is added to the fully convolutional instance mask branch, and the model's accuracy in locating blurred packaging boundaries is improved by combining the edge extraction operator with the edge-sensitive joint loss function.
[0022] Furthermore, the grayscale stretching preprocessing mechanism can reduce the impact of illumination changes and dynamically update the judgment threshold based on the statistical data of historical qualified samples in the same batch during the multi-index judgment stage, thereby reducing the false judgment rate and improving the adaptability of online detection. Attached Figure Description
[0023] Figure 1 This is a comparison of histograms before and after grayscale stretching; Figure 2 This is a schematic diagram illustrating the mapping relationship between the proportion of edge pixels and the mask fusion weight; Figure 3 This is a diagram showing the comparison of detection performance between different experimental groups. Detailed Implementation
[0024] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0025] In the first embodiment, the present invention proposes an online detection method for the airtightness of food packaging based on machine vision, including: Model training stage: Constructing an improved MaskR-CNN network, replacing some standard convolutions in the backbone feature extraction part with deformable convolutions, adding a dual-path attention module at the horizontal connection of the feature pyramid, and obtaining the channel weights by weighting the global average pooling vector and the global max pooling vector with coefficients determined by the sum of the absolute value of the standard deviation of the feature map divided by the arithmetic mean and a preset small constant, and then using the Sigmoid function. An edge-aware sub-branch is added to the mask branch, the gradient magnitude is extracted using the Sobel operator, and the edge mask is output by multiplying it with the original mask features pixel by pixel. The network is jointly trained using Dice loss and edge-sensitive weighted cross-entropy loss.
[0026] The system reads food packaging sample images, uses image processing algorithms to perform flipping and cropping operations to expand the dataset, calls annotation software to generate corresponding real mask labels, and converts the image pixel matrix into the data tensor format required for network input.
[0027] The ResNet50 feature extraction network structure is instantiated, and the standard two-dimensional convolutional layers in the third and fourth stages of the backbone network are replaced to achieve deformable convolution to adapt to the local geometric deformation of the sealed edge.
[0028] At each scale of the feature pyramid network's lateral connection path, the spatial standard deviation of the feature map channel dimension is calculated, and the corresponding arithmetic mean is calculated. The standard deviation is divided by the sum of the absolute value of the standard deviation and the mean, plus a preset constant, to obtain the local mutation response coefficient of each channel. The local mutation response coefficient is used as the weighting coefficient of the global max pooling vector, and the difference between 1 and the local mutation response coefficient is used as the weighting coefficient of the global average pooling vector, so that channels with more significant local mutations are more biased towards retaining the maximum response feature. A global average pooling vector is generated through adaptive global average pooling, and a global max pooling vector is generated through adaptive global max pooling. The two feature vectors are then weighted by scalar multiplication and element-wise addition using the aforementioned weighting coefficients, and fed into the Sigmoid activation function to calculate the attention weight vector. Finally, a channel-dimensional multiplication operation is performed with the original input feature map to complete the weighting.
[0029] Parallel sub-branches are constructed in the mask prediction head network. 3×3 Sobel convolution kernel tensors are set in the horizontal and vertical directions. The dilation coefficient and number of padding pixels of the convolution are calculated according to the spatial resolution of the current input feature map. Two-dimensional spatial convolution is performed respectively. The Euclidean distance between the horizontal and vertical gradients is calculated to obtain the gradient magnitude feature map. The gradient magnitude is multiplied pixel by pixel with the original mask feature map. Then, it is concatenated with the original mask feature map along the channel dimension. After dimensionality reduction by a 1×1 convolutional layer, the predicted edge mask is output.
[0030] A pre-defined optimization algorithm is used as the optimizer. For the main mask prediction, Dice loss is used to calculate the overlap deviation between the predicted region and the real region mask. For edge prediction, real edge labels are extracted from the real region mask, and morphological dilation is performed on the real edge labels with a radius of 3 pixels to generate edge-weighted neighborhoods. The cross-entropy loss between the edge mask prediction result and the real edge label is calculated pixel by pixel. The proportion of real edge pixels to the total number of pixels in the real region mask is calculated to obtain the proportion of training edge pixels. A positive loss weight corresponding to 1 and the sum of the proportion of training edge pixels is assigned in the edge-weighted neighborhood to obtain the edge-sensitive weighted cross-entropy loss. The two losses are added together according to a pre-defined ratio, backpropagation gradient descent is performed, and the network weight parameters are saved.
[0031] In an optional embodiment, the channel weights are obtained by weighting the global average pooling vector and the global max pooling vector with coefficients determined by the sum of the absolute values of the standard deviation and the arithmetic mean of the feature map and a preset small constant, and then applying the sigmoid function. This includes: calculating the standard deviation and arithmetic mean of the intensity of all pixels in the current channel of the feature map respectively; calculating the local mutation response coefficient with a value between 0 and 1 by dividing the standard deviation by the sum of the absolute values of the standard deviation and the arithmetic mean and a preset small constant; setting this value as the weight coefficient of the global max pooling vector; calculating the difference between 1 and the weight coefficient as the weight coefficient of the global average pooling vector; adding the corresponding bits of the two vectors multiplied by the corresponding coefficients and inputting them into the sigmoid function to calculate the absolute channel weight allocation sequence; setting a preset upper limit and a suppression factor; comparing the weight coefficient with the preset upper limit during backpropagation of the model parameters; when the weight coefficient is greater than the preset upper limit, multiplying the learning rate or gradient update magnitude of the spatial offset parameter in the corresponding deformable convolutional layer by the suppression factor for shrinkage restriction.
[0032] The mask region convolutional neural network receives the H×W×C three-dimensional feature tensor after denoising and stretching preprocessing. The network is composed of a deep residual backbone network, a multi-scale feature pyramid, a candidate region generation network, a RoIAlign layer, a fully connected prediction branch, and a fully convolutional instance mask branch, which are sequentially spliced together. The output includes class confidence, target bounding box regression coordinates, and a two-dimensional binary target mask.
[0033] In the lateral connection stage of the feature pyramid network, a parameterized dual-path attention mechanism is employed to enhance channels and suppress background. For a single-layer feature tensor, the spatial arithmetic mean and standard deviation are calculated channel by channel. The standard deviation is divided by the sum of the standard deviation, the absolute value of the arithmetic mean, and a small constant to obtain the local mutation response coefficient. The local mutation response coefficient is used as the weighting coefficient of the global max pooling vector, and the difference between 1 and the local mutation response coefficient is used as the weighting coefficient of the global average pooling vector. The global average pooling vector and the global max pooling vector are multiplied by their respective coefficients, then element-wise added, and activated by the Sigmoid function to generate a channel weight sequence of 0 to 1, which is then multiplied and weighted by the original channel feature points.
[0034] In addition, an empirical constant is set as the oversaturation response threshold. If the local mutation response coefficient is greater than the threshold, the suppression logic is triggered. In the optimizer, the learning rate or gradient update magnitude of the spatial offset parameter of the deformable convolutional layer corresponding to that layer is multiplied by 0.5 to suppress the excessive jitter of the receptive field caused by strong local mutation regions and improve the convergence stability of the model.
[0035] In an optional embodiment, the gradient magnitude is extracted using the Sobel operator, including: determining the side length resolution of the candidate target region feature map derived from the RoIAlign layer; for the input feature map with a side length resolution of 14×14 pixels, applying a discrete differential Sobel filter with a kernel matrix side length of 3×3 to the entire grid with a span of 1 and zero-pixel filling of the outer boundary; for the input feature map with a side length resolution of 28×28 pixels, using a 5×5 smooth Sobel filter with fixed parameters, performing a convolution operation with the same phase length and corresponding boundary filling method to obtain the horizontal gradient matrix representing the horizontal gray-level change and the vertical gradient matrix representing the vertical gray-level change.
[0036] To verify the resolution of the feature map output by the RoIAlign layer, if the input feature map resolution is 14×14, a 3×3 discrete first-order differential Sobel filter is called, and a sliding convolution operation with a stride of 1 and zero-pixel padding on the outer boundary is performed. If the input feature map is in a shallow network layer or the target box is large, and the resolution is 28×28, a larger 5×5 Sobel filter with embedded smooth descent weights is switched to perform convolution with the same stride and padding logic. Regardless of the size of the convolution kernel used, the gradient matrices in the horizontal and vertical directions are decoupled.
[0037] In an optional embodiment, the edge mask is output by multiplying the original mask features pixel by pixel and then concatenating them. This includes: performing an addition operation on the squares of the horizontal gradient feature values and the squares of the vertical gradient feature values under the same spatial coordinates in the feature space, and then taking the square root to obtain an undirected absolute metric edge activation intensity scalar; according to the row and column index sequence, performing a pixel-by-pixel multiplication on the feature weight variables activated by the original mask branch at the matrix index position corresponding to the obtained undirected absolute metric edge activation intensity scalar to generate an edge enhancement feature layer; extracting the original feature map array, concatenating the edge enhancement feature layer and the original feature map along the channel dimension to obtain a hybrid feature tensor with expanded channel number; inputting the hybrid feature tensor into consecutive convolutional layers for feature mapping, wherein the first convolutional layer uses a 3×3 convolutional kernel and outputs 256 channels, the second convolutional layer outputs the same number of channels and connects them to activation functions, and finally generating an edge probability map through a single-channel output layer, and using the edge probability map as the edge mask.
[0038] After obtaining the directional gradient matrix, the network extracts the horizontal and vertical gradient values at the same coordinate system, squares them, adds them together, and then takes the square root to generate an undirected absolute edge activation intensity scalar layer. Based on the spatial row and column indices, this activation intensity layer is multiplied pixel-by-pixel with the feature weight layer of the original mask branch to generate an edge enhancement feature layer. This operation enhances the response of edge regions and reduces the impact of background noise in flat areas on edge prediction. The edge enhancement feature tensor is concatenated with the original feature map that preserves global semantics along the depth channel dimension to obtain a hybrid tensor with doubled channel count. This hybrid tensor is then fed into two consecutive convolutional network layers: the first layer is a 3×3 convolutional kernel with a bias term and 256 output channels, representing a dimensionality reduction layer; the second layer is a connected layer with 256 channels and an activation function. Subsequently, a second forward propagation mapping and binary classification calculation are performed through a single-channel output layer, outputting an edge prediction mask with a dimension of H×W×1, composed of single-channel edge probability values.
[0039] In an optional embodiment, the network is jointly trained using Dice loss and edge-sensitive weighted cross-entropy loss, including: calculating the Dice loss between the main mask prediction result and the real region mask, respectively, as the region overlap loss; extracting real edge labels based on the real region mask, and calculating the standard cross-entropy loss between the edge mask prediction result and the real edge label pixel by pixel, as the edge pixel classification loss; extracting real edges based on the manually annotated real mask, and dividing pixels within 3 pixels of the real edge into edge-sensitive regions by Chebyshev distance or morphological dilation; calculating the proportion of real edge pixels to the total number of pixels in the real mask to obtain the training edge pixel proportion, and calculating the sum of 1 and the training edge pixel proportion as the additional weight of the edge-sensitive region; multiplying the edge pixel classification loss in the edge-sensitive region by the additional weight, and keeping the original weight of the edge pixel classification loss in the non-edge-sensitive region, to obtain the edge-sensitive weighted cross-entropy loss; weighting and summing the Dice loss and the edge-sensitive weighted cross-entropy loss according to a preset ratio to obtain the total loss, and performing backpropagation and network parameter updates based on the total loss.
[0040] During the loss feedback evaluation phase, the model's region overlap error is represented by the Dice loss between the main mask prediction and the ground truth region mask; the edge pixel classification error is represented by the cross-entropy loss between the edge mask prediction and the ground truth edge label. Ground truth edges are extracted based on the ground truth region mask, and pixels within 3 pixels of the ground truth edge are classified as edge-sensitive regions. An additional compensation weight is applied to the edge pixel classification loss within this region, with the compensation weight being 1 + the proportion of training edge pixels. The weighted edge pixel classification loss and the Dice loss are accumulated and normalized according to a preset ratio to generate a total loss scalar, which is used to drive backpropagation and parameter updates.
[0041] Online detection phase: Images of conveyor belt packaging are acquired and preprocessed. The preprocessed images are input into the trained network, which outputs edge masks and main masks and fuses them into a final mask based on the weights determined by the proportion of edge pixels. The sealing contour is extracted, and the rate of curvature change and width uniformity are calculated and judged. If the number of qualified samples does not reach the preset number, a preset initial threshold is used for judgment. After reaching the preset number, if both indicators are lower than the threshold formed by the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, the sample is judged as qualified. Otherwise, the sample is judged as unqualified, and the coordinates are output and not included in the threshold update.
[0042] An industrial camera is used to acquire packaging images by triggering a photoelectric sensor. The color image is converted into a single-channel grayscale image. The grayscale histogram distribution of pixels in the background area around the image is statistically analyzed, and the cumulative probability density of the histogram is calculated. The grayscale index values corresponding to the cumulative probability reaching 5% and 95% are extracted as upper and lower cutoff points using a traversal query algorithm. Grayscale stretching and truncation are performed on all pixels in the image. The range normalization algorithm is applied to linearly map the pixel values to the range of 0 to 255.
[0043] The preprocessed image tensor is input into the model with loaded weights, and a continuous edge mask probability map and a main mask probability map are output in parallel. The total number of pixels with response values exceeding a fixed threshold of 0.5 in the edge probability map is counted and divided by the total number of pixels in the target region or bounding box to obtain the proportion of detected edge pixels. The baseline constant is added to the proportion of detected edge pixels, and the sum is truncated to no more than 1, which is used as the fusion weight parameter. The fusion weight is multiplied by the edge mask, and the difference obtained by adding 1 minus the fusion weight is multiplied by the main mask to obtain a continuous fusion mask. Binarization segmentation is performed after passing a decision threshold of 0.5 to extract the target sealed region.
[0044] Extract the outermost closed sealing contour point set of the binary mask. For the curvature change rate index, use spline interpolation to smoothly fit the discrete contour points. Calculate the first and second derivatives of the curve space coordinates and substitute them into the plane curve curvature calculation formula to obtain the absolute curvature point by point. Calculate the curvature difference sequence of adjacent pixel positions and obtain the variance as the curvature change rate. For the width uniformity index, extract the shortest Euclidean distance from the inner contour point to the outer contour point of the sealing ring to form a width sequence, and obtain the variance of this width sequence as the width uniformity.
[0045] Initialize the initial empirical threshold constant and the continuous qualified product count variable in the detection system memory. When the count value is lower than the preset quantity, compare the two currently calculated indicators with the set initial curvature threshold and initial width threshold respectively. When the count value reaches the preset quantity, calculate the average of the historical indicators of qualified batches stored in the recent queue, calculate the standard deviation of the historical indicator sequence, and add twice the standard deviation to the mean as the latest judgment threshold for the current detection cycle. If the currently calculated rate of curvature change and width uniformity are both less than the corresponding threshold, it is judged as qualified and a release signal is output to the programmable logic controller, the count value is incremented by 1, and the data of the two indicators in this round are appended to the historical sequence buffer queue to update the threshold for the next time. If any indicator is greater than or equal to the judgment threshold, it is judged as unqualified and a rejection signal is output. The coordinates of the abnormal area are determined according to the final state mask, sealing contour, local curvature abnormal point, local width abnormal point, or the outer rectangle of the abnormal connected area, and output together to locate the abnormal position. The threshold update cycle of the current cycle is skipped to prevent abnormal defective product data from polluting the normal historical threshold data pool.
[0046] In an optional embodiment, the process of acquiring and preprocessing a conveyor belt packaging image includes: performing Gaussian smoothing filtering on the acquired packaging image using a 5×5 Gaussian kernel for noise reduction; extracting the conveyor belt background region by threshold segmentation using the Otsu method and combining it with a preset background sampling area around the image, and calculating a 256-level grayscale histogram; starting from grayscale levels 0 and 255 respectively, progressively accumulating the number of pixels corresponding to the corresponding grayscale levels in the directions of increasing and decreasing grayscale levels, stopping the accumulation when the total number of pixels accumulated in one direction reaches 5% of the total number of pixels in the background region, and obtaining the lower limit grayscale value and upper limit grayscale value corresponding to the stopping position respectively; When the lower grayscale value and the upper grayscale value are the same, the upper grayscale value is increased by 1. According to the linear formula, the grayscale value of the output pixel is set to 255 multiplied by the difference between the original image grayscale value and the lower grayscale value, and then divided by the difference between the upper grayscale value and the lower grayscale value. The pixels with the original image grayscale value are converted into output pixels. At the same time, the grayscale values less than the lower grayscale value are set to 0, and the grayscale values greater than the upper grayscale value are set to 255, thus obtaining the preprocessed image.
[0047] In the image preprocessing stage of food packaging inspection, the vision system uses a high-resolution industrial camera to detect target images on the conveyor belt. A Gaussian smoothing filter with a kernel size of 5×5 is used to perform spatial domain denoising on the input grayscale image. Here, the standard deviation parameter of the Gaussian distribution is preferably set to a range of 1 to 1.5. For example, setting it to 1.2 can minimize the blurring effect on key edge features of the sealing line while suppressing noise interference.
[0048] After denoising, the Otsu method is applied to find the optimal threshold that maximizes the inter-class variance by traversing all possible gray levels from 0 to 255. Combined with a pre-defined background sampling area around the image, a Boolean mask for the conveyor belt background region with large-area uniformity is extracted. Based on the mask, the pixel distribution within this background region is statistically analyzed, generating a 256-level background gray-level histogram to represent the background illumination distribution. Based on the extracted gray-level histogram, a double-ended gray-level stretching and truncation algorithm is performed.
[0049] Two scanning pointers are set up, starting at gray levels 0 and 255 respectively. The total number of pixels is gradually increased towards the center gray level based on frequency. Scanning stops when the total number of pixels accumulated in one direction reaches exactly 5% of the total number of pixels in the conveyor belt background. The gray levels corresponding to the two stopping points are recorded as the lower limit gray level values. For example... and upper limit grayscale value, for example .
[0050] Internal redundant checks are implemented. If the lower and upper limits coincide, the upper limit is incremented by 1 to reduce the risk of the denominator being zero during normalization calculations. A linear contrast expansion operation is performed on the entire image: for center pixels whose grayscale falls within the [45, 190] range, a linear formula (original grayscale - 45) / (190 - 45) × 255 is used to map them to an 8-bit display space; pixels with a grayscale value less than 45 are all treated as 0, and extremely bright pixels with a grayscale value greater than 190 are all set to 255, thus generating a pre-processed image with a more stable grayscale distribution. Histogram comparison before and after grayscale stretching is shown below. Figure 1 As shown.
[0051] In an optional embodiment, the output edge mask and the main mask are weighted and fused into a final state mask according to the weight determined by the edge pixel ratio. This includes: converting the edge mask into a binary edge map using a preset pixel threshold, and counting the number of edge pixels with a value of 1 within the target region or bounding box; dividing the number of edge pixels by the total number of pixels within the target region or bounding box to obtain the edge pixel ratio; adding a reference constant to the calculated edge pixel ratio, and taking the minimum value of the sum and the constant 1 to obtain the fusion weight for the current judgment period; taking each pixel of the matrix as the origin, multiplying the edge mask by the fusion weight, multiplying the main mask by 1 and subtracting the fusion weight to obtain the main mask weight, and adding the two pixel by pixel to obtain the final state mask matrix.
[0052] After the mask branch output, a balancing strategy is used for fusion, with a threshold of 0.5 to predict the thermals of continuous edges. Figure 2The values are converted to a Boolean array. The space of the target bounding box is traversed, and the total number of positive feature pixels with a value of 1 is counted. This total is divided by the total pixel area of the bounding box to obtain the edge pixel ratio. The fusion weight is calculated: the baseline constant 0.1 is added to the calculated edge pixel ratio, and this sum is then divided by the constant 1 to obtain the fusion weight for the current cycle. The generated edge mask is multiplied by this fusion weight, and the main mask output from the backbone network is multiplied by 1 and subtracted from it to obtain the main mask weight. These two are added together to obtain the fused mask. The mapping relationship between the edge pixel ratio and the mask fusion weight is as follows: Figure 2 As shown.
[0053] In an optional embodiment, extracting the sealing contour and calculating the rate of curvature change and width uniformity, and making a judgment, includes: using the Canny operator to process the final state mask to extract the pixel arrangement sequence of the closed loop shape; at the center position of each adjacent connected three points, using the partial derivative of the quadratic spline interpolation function, calculating the instantaneous first-order bending deflection difference value of the curve angle measured by the second-order parameter direction change at the local position of the pixel, and obtaining the overall variance as the measured rate of curvature change; calculating the sequence of the shortest perpendicular distance between the inner and outer contours of the sealing contour, and taking the statistical variance of the deviation set as the width uniformity; setting a finite-length sequential replacement cache list with a historical qualified sample length of a preset number M; judging whether the number of qualified samples stored in the list has reached the preset number M; if not, using a preset initial fixed threshold as the set threshold; if it has reached, retrieving the qualified samples stored in the cache list. For all historical curvature change rates and width uniformity, the average value including all elements is calculated, and the standard deviation value is calculated for each. The corresponding item is used as the judgment threshold by adding twice the standard deviation to the mean. If the curvature change rate and width uniformity of the current test sample are both lower than the set threshold, it is confirmed as qualified and the release process is performed. If the cache list is not full, the two indicators corresponding to the current sample are written into the cache list. If the cache list is full, the earliest written data is removed according to the first-in-first-out rule, and then the two indicators corresponding to the current sample are written, and used as the reference sample for threshold calculation in the next detection cycle. Otherwise, the rejection or interception mechanism is triggered and an audible and visual alarm is triggered. The coordinates of the abnormal area are generated according to the final state mask, sealing contour or abnormal judgment result and reported to the central control terminal. The unqualified data is not included in the cache queue and can enter the manual re-inspection process according to the production line rules.
[0054] The Canny operator is used to extract closed contour sequences with a single pixel width for quantitative detection. Based on three adjacent pixels, a quadratic spline interpolation function is used to calculate the partial derivative and the instantaneous bending angle difference in the local second-order direction. The statistical variance of the angle differences of the entire contour is taken as the rate of curvature change. The sequence of shortest vertical distances between the inner and outer boundaries of the contour is searched, and the statistical variance of the thickness set is taken as the width uniformity.
[0055] It has a built-in first-in-first-out (FIFO) buffer queue with a preset capacity of M to store the indicators of historical qualified samples. The preset capacity M can be 30. If the buffer queue is not full of the preset capacity M, a manually preset fixed constant is used as the judgment threshold; if the buffer queue is full of the preset capacity M, it enters the learning state, calculates the mean and standard deviation of the curvature change rate and width uniformity of the preset capacity M samples, and sets the mean + 2 times the standard deviation as the threshold; where the preset capacity M can be 30.
[0056] If both indicators of the current sample are lower than the set threshold, the product is deemed qualified and released. The curvature change rate and width uniformity of the sample are written to the cache queue. When the cache queue is full, the earliest written data is removed according to the first-in-first-out rule to update the historical threshold baseline.
[0057] If any indicator exceeds the threshold, a rejection or interception mechanism is triggered, and an audible and visual alarm is issued. The coordinates can be determined by identifying local curvature anomalies, local width anomalies, or the circumscribed rectangle of an abnormally connected region, and then reported to the central control unit. This non-compliant data is not included in the cache queue to maintain the stability of the historical threshold baseline, and can proceed to the manual re-inspection process according to production line rules.
[0058] Ablation validation was conducted for food packaging surface defect detection. A 50-residual network structure was uniformly adopted as the backbone feature extraction network, and a stochastic gradient descent optimizer was configured. The initial learning rate of the model was set to 0.01, the batch size was set to 16, and 50 epochs of iterative training were completed on a single computing card. The experimental dataset contained 5000 food packaging images collected from real production lines as training samples, and the test set contained 1000 scene images with high-frequency reflections and minor crack interference. The evaluation metrics were mean precision, edge intersection-union ratio, and defect false negative rate.
[0059] like Figure 3 As shown, the experiment was divided into three groups for comparison and verification. The first group was the baseline model, which only used a conventional mask region convolutional neural network. The average accuracy was 82.4%, the edge crossover ratio was 75.6%, and the defect false negative rate was 6.8%. The second group added double-ended grayscale stretching preprocessing and a channel attention weighting module based on the standard deviation of feature maps to the baseline model. The average accuracy was improved to 86.5%, the edge crossover ratio reached 79.2%, and the defect false negative rate decreased to 4.5%. The third group was a complete implementation scheme that included edge differential filters and edge-sensitive weighted losses. The average accuracy was improved to 91.2%, the edge crossover ratio reached 88.5%, and the defect false negative rate decreased to 1.2%.
[0060] Experimental results show that the addition of grayscale stretching preprocessing and the channel attention module helps to reduce the impact of high-frequency reflective noise and enhance the effective semantic channel response, resulting in a 4.1 percentage point improvement in average accuracy compared to the baseline model. Further integration of the edge fusion mechanism and edge-sensitive weighted loss enhances the model's response to hidden minor damage and blurred sealing boundaries, further improving the edge crossover ratio and reducing the defect false negative rate. This indicates that the local sensitive response extraction component and the multi-dimensional quantitative evaluation mechanism contribute to improving the stability and reliability of online industrial vision inspection.
[0061] In the second embodiment, the present invention also proposes an online detection system for the airtightness of food packaging based on machine vision, comprising the following modules: The model training module is used to build an improved MaskR-CNN network. Some standard convolutions in the backbone feature extraction part are replaced with deformable convolutions. A dual-path attention module is added at the horizontal connection of the feature pyramid. The channel weights are obtained by weighting the global average pooling vector and the global max pooling vector with coefficients determined by the sum of the absolute values of the standard deviation of the feature map divided by the arithmetic mean and the preset small constant, and then passing the weights through the Sigmoid function. An edge-aware sub-branch is added to the mask branch. The gradient magnitude is extracted using the Sobel operator and multiplied by the original mask features pixel by pixel before concatenating to output the edge mask. The network is jointly trained using Dice loss and edge-sensitive weighted cross-entropy loss. The online detection module is used to acquire and preprocess images of conveyor belt packaging. The preprocessed images are input into the trained network, which outputs an edge mask and a main mask and fuses them into a final mask based on the weights determined by the proportion of edge pixels. The sealing contour is extracted and the rate of curvature change and width uniformity are calculated and judged. If the number of qualified samples does not reach the preset number, a preset initial threshold is used for judgment. After the preset number is reached, if both indicators are lower than the threshold formed by the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, it is judged as qualified. Otherwise, it is judged as unqualified and the coordinates are output and not included in the threshold update.
[0062] In the description of this specification, "multiple" or "several" means at least two, such as two, three or more, unless otherwise expressly and specifically defined.
Claims
1. A machine vision-based online detection method for the airtightness of food packaging, characterized in that, include: Model Training Phase: An improved MaskR-CNN network is constructed. Some standard convolutions in the backbone feature extraction section are replaced with deformable convolutions, specifically replacing the standard 2D convolutional layers in the third and fourth stages of the backbone network. A dual-path attention module is added to the lateral connections of the feature pyramid. Channel weights are obtained by weighting the global average pooling vector and the global max pooling vector with a coefficient determined by the sum of the absolute value of the difference between the standard deviation and the arithmetic mean of the feature map and a preset small constant, followed by the Sigmoid function. An edge-aware sub-branch is added to the mask branch. The gradient magnitude is extracted using the Sobel operator and multiplied pixel-wise with the original mask features before concatenating to output the edge mask. The network is jointly trained using Dice loss and edge-sensitive weighted cross-entropy loss. The process involves: calculating the Dice loss between the master mask prediction and the real region mask; generating real edges from the real region mask and dividing pixels within 3 pixels of the real edges into edge-sensitive regions using Chebyshev distance or morphological dilation; calculating the ratio of real edge pixels to the total number of pixels in the real mask, and using 1 plus this ratio as the weighting coefficient for the edge-sensitive regions; calculating the cross-entropy loss between the edge mask prediction and the real edges, where the loss of pixels within the edge-sensitive regions is multiplied by the weighting coefficient, and the loss of other pixels is weighted at 1, to obtain the edge-sensitive weighted cross-entropy loss; and weighting the Dice loss and the edge-sensitive weighted cross-entropy loss according to a preset ratio, using this as the total loss for backpropagation and network parameter updates. Online detection phase: Images of conveyor belt packaging are acquired and preprocessed. The preprocessed images are input into the trained network, and the edge mask and the main mask are output and fused into a final mask based on the weight determined by the proportion of edge pixels. The sealing contour is extracted and the rate of curvature change and width uniformity are calculated and judged. If the number of qualified samples does not reach the preset number, a preset initial threshold is used for judgment. After reaching the preset number, if both indicators are lower than the threshold formed by the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, it is judged as qualified. Otherwise, it is judged as unqualified and the coordinates are output and not included in the threshold update.
2. The method according to claim 1, characterized in that, The process of acquiring and preprocessing images of conveyor belt packaging includes: The acquired packaging images are subjected to smoothing and noise reduction processing; The background region of the conveyor belt is extracted by threshold segmentation, and the statistical characteristics of the gray-scale distribution of the background region are calculated. Based on the grayscale distribution statistical characteristics, a lower limit grayscale value and an upper limit grayscale value are determined, wherein the lower limit grayscale value and the upper limit grayscale value are determined based on a preset truncation ratio of the total number of pixels in the background area; By using the determined lower and upper grayscale values, the original image pixels are subjected to grayscale stretching and truncation to obtain a preprocessed image with enhanced contrast.
3. The method according to claim 1, characterized in that, The channel weights are obtained by: calculating the standard deviation and arithmetic mean of the intensity of all pixels in each channel of the feature map; determining the weight coefficient, which is the sum of the absolute value of the difference between the standard deviation and the arithmetic mean and a preset small constant. The weight coefficient is used as the weight of the global max pooling vector, and 1 minus the weight coefficient is used as the weight of the global average pooling vector. The corresponding positions of the two weighted vectors are added together and the channel absolute weight allocation sequence is obtained by passing the Sigmoid function. A preset upper limit and a suppression factor are set. During backpropagation, if the weight coefficient is greater than the preset upper limit, the learning rate or gradient of the spatial offset parameter of the corresponding deformable convolutional layer is multiplied by the suppression factor to shrink and limit it.
4. The method according to claim 2 or 3, characterized in that, The extraction of gradient magnitude using the Sobel operator includes: Determine the side length, size, and resolution of the feature map of the candidate target region derived from the RoIAlign layer; For an input feature map with a side length resolution of 14×14 pixels, a discrete differential Sobel filter with a specified kernel matrix side length of 3×3 is applied to the entire grid with a span of 1 and zero-pixel filling of the outer boundary. For an input feature map with a side length resolution of 28×28 pixels, a 5×5 smooth Sobel filter with fixed parameters is used to perform a convolution operation with the same phase length and corresponding boundary padding to obtain the horizontal gradient matrix representing the horizontal gray level change and the vertical gradient matrix representing the vertical gray level change.
5. The method according to claim 1, characterized in that, The process of multiplying the original mask features by pixels and then concatenating them to output the edge mask includes: The sum of the squares of the horizontal and vertical gradients obtained by the Sobel operator is calculated and the square root is taken to obtain the undirected absolute measure of the edge activation intensity scalar. The edge enhancement feature map is concatenated with the original mask feature along the channel dimension to form a hybrid feature tensor; The hybrid feature tensor is input into a series of convolutional layers for feature mapping. The first convolutional layer uses a 3×3 convolutional kernel and outputs 256 channels. The second convolutional layer outputs the same number of channels and connects them to an activation function. Finally, an edge probability map is generated through a single-channel output layer, and the edge probability map is used as an edge mask.
6. The method according to claim 1, characterized in that, The output edge mask and the main mask are weighted and fused into a final state mask according to the weight determined by the edge pixel ratio. This includes: converting the edge mask into a binary edge map using a preset pixel threshold, and counting the number of edge pixels with a value of 1 in the target region or bounding box; dividing the number of edge pixels by the total number of pixels in the target region or bounding box to obtain the edge pixel ratio; adding a reference constant to the calculated edge pixel ratio, and taking the minimum value of the sum and the constant 1 to obtain the fusion weight for the current judgment period; taking each pixel of the matrix as the origin, multiplying the edge mask by the fusion weight, multiplying the main mask by 1 and subtracting the fusion weight to obtain the main mask weight, and adding the two pixel by pixel to obtain the final state mask matrix.
7. The method according to claim 1, characterized in that, The extraction of the sealing profile and calculation of the rate of curvature change and width uniformity include: The final state mask is processed using the Canny operator to extract the closed-loop pixel sequence of the sealed contour; At the center of each adjacent three-point connection, the partial derivative of the quadratic spline interpolation function is used to calculate the instantaneous first-order bending deflection difference of the curve angle measured by the second-order parameter direction change at the local position of the pixel, and the total variance is used as the measured curvature change rate. Calculate the sequence of shortest perpendicular distances between the inner and outer contours of the sealing profile, and take the statistical variance of the deviation set as the width uniformity.
8. The method according to claim 7, characterized in that, The determination includes: Set a cache list of historical qualified samples with a length of M; If the number of qualified samples in the list does not reach M, then a preset initial threshold is used as the set threshold. If the number of qualified samples in the list has reached M, then calculate the mean and standard deviation of all historical curvature change rates and width uniformity in the list, and use the mean plus twice the standard deviation as the set threshold. If the curvature change rate and width uniformity of the current sample are both lower than the set threshold, it is deemed qualified and the two indicators of the current sample are written into the cache list; when the list is full, the earliest data is removed and written in according to the first-in-first-out rule.
9. A machine vision-based online inspection system for the airtightness of food packaging, characterized in that, Includes the following modules: Model Training Module: An improved MaskR-CNN network is constructed. Some standard convolutions in the backbone feature extraction section are replaced with deformable convolutions. A dual-path attention module is added to the lateral connections of the feature pyramid. Channel weights are obtained by weighting the global average pooling vector and the global max pooling vector with a coefficient determined by the sum of the absolute value of the difference between the standard deviation and the arithmetic mean of the feature map and a preset small constant, followed by the Sigmoid function. An edge-aware sub-branch is added to the mask branch. The gradient magnitude is extracted using the Sobel operator and multiplied pixel-wise with the original mask features before concatenation to output the edge mask. The network is jointly trained using Dice loss and edge-sensitive weighted cross-entropy loss, including: calculating the prediction results of the main mask and the ground truth region. The Dice loss between domain masks is calculated; real edges are generated from real region masks, and pixels within 3 pixels of the real edges are divided into edge-sensitive regions using Chebyshev distance or morphological dilation; the proportion of real edge pixels to the total number of pixels in the real mask is calculated, and 1 plus this proportion is used as the weighting coefficient for the edge-sensitive regions; the cross-entropy loss between the edge mask prediction result and the real edges is calculated, where the loss of pixels located in the edge-sensitive regions is multiplied by the weighting coefficient, and the loss weight of the remaining pixels is 1, to obtain the edge-sensitive weighted cross-entropy loss; the Dice loss and the edge-sensitive weighted cross-entropy loss are weighted and summed according to a preset ratio, and the sum is used as the total loss for backpropagation and network parameter updates; Online detection module: Acquires and preprocesses images of conveyor belt packaging, inputs the preprocessed images into a trained network, outputs an edge mask and a main mask, and fuses them into a final mask by weighting according to the weight determined by the proportion of edge pixels. Extracts the sealing contour and calculates the rate of curvature change and width uniformity for judgment. If the number of qualified samples does not reach the preset number, a preset initial threshold is used for judgment. After reaching the preset number, if both indicators are lower than the threshold formed by the mean of the corresponding indicators of historical qualified samples plus twice the standard deviation, it is judged as qualified; otherwise, it is judged as unqualified, and the coordinates are output and not included in the threshold update.
Citation Information
Patent Citations
PRP preparation quality evaluation method based on double-branch image fusion
CN120635059A
MaskRcnn-based tumor detection method and system
CN121304533A
