A plastic packaging bag flaw visual inspection method and system
By installing high frame rate cameras on the production line, dividing the inspection section, analyzing the degree of shrinkage and reflective areas, dynamically setting reference thresholds, and filtering defective pixels, the real-time and accuracy problems of defect detection in plastic packaging bags were solved, and defect location was achieved through full-process automation.
Patent Information
- Application Number
- CN202510654852.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-05-21
AI Technical Summary
In existing technologies, it is difficult to monitor defects in plastic packaging bags in real time during the production process, especially defects such as stretching and uneven tension during dynamic processes. The detection timing is delayed and the coverage is limited, which poses a risk of missed detection.
By setting up high frame rate cameras on the production line to acquire continuous frame images of long plastic packaging bags, dividing them into independent detection segments, analyzing the degree of shrinkage and the proportion of reflective area, dynamically setting reference thresholds, and filtering out defective pixels, the defective areas can be quickly and accurately located.
It enables real-time detection of defects in plastic packaging bags, improving the accuracy and efficiency of detection results. It requires no manual intervention and can quickly and accurately locate defective areas before cutting.
Smart Images

Figure CN120510344B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of visual defect inspection technology, specifically to a method and system for visual inspection of defects in plastic packaging bags. Background Technology
[0002] Plastic packaging serves as a crucial medium for numerous industries, including food and pharmaceuticals, and its quality directly impacts the safety of its contents during storage and transportation. Undetected defects in appearance, structure, or functionality that may arise during production can lead to problems during use, threatening consumer health and rights, and causing serious consequences such as damage to the manufacturer's brand reputation. Real-time monitoring of the production process using efficient defect detection methods allows for the timely identification and removal of substandard products. This not only improves production efficiency but also ensures that products meet industry standards and regulations, laying a solid foundation for building a quality trust system for the company.
[0003] Currently, the detection of defects in plastic packaging bags in factories is often carried out after cutting and forming. The timing of the detection lags behind the production process, making it difficult to capture defects such as tensile damage caused by stretching and uneven tension during dynamic processes. At the same time, traditional sampling inspection has a limited coverage and there is a risk of missed detection. Summary of the Invention
[0004] To address the above-mentioned technical problems, the present invention aims to provide a method and system for visual inspection of defects in plastic packaging bags.
[0005] According to a first aspect of the present invention, a visual inspection method for defects in plastic packaging bags is provided, and the specific technical solution adopted is as follows:
[0006] The system acquires the moving speed of the production line, sets the camera's frame rate, and captures continuous frame images of the long plastic packaging bags moving along the production line.
[0007] Based on the shooting frame rate and the moving speed, the segment length is set to divide the long plastic packaging bag into several independent detection segments;
[0008] Based on the continuous frame images, the degree of contraction and the area ratio of reflective regions of the independent detection segments are analyzed to obtain the degree of wrinkle influence of the independent detection segments, and then the qualified frame images of the independent detection segments are determined.
[0009] A reference threshold is dynamically set to obtain a reference segment based on the degree of influence of the wrinkles;
[0010] Based on the qualified frame image of the independent detection segment, the gray value difference of the pixels in the segment to be detected and the reference segment is analyzed to filter out defective pixels and obtain the defective area.
[0011] Based on the location distribution and aggregation characteristics of the defective areas, production process fault tracing is performed.
[0012] In some embodiments of the present invention, setting the camera's shooting frame rate includes:
[0013] Obtain the vertical length of the camera's field of view and the camera's vertical pixel resolution;
[0014] The camera's frame rate is set based on the production line's moving speed, as well as the longitudinal length and the longitudinal pixel resolution.
[0015] In some embodiments of the present invention, analyzing the degree of contraction of the independent detection segments based on the consecutive frame images includes:
[0016] Obtain the standard width for long plastic packaging bags;
[0017] Based on the continuous frame images, the main edge of the independent detection segment is extracted, the coordinates of the main edge are obtained, and the local width of the independent detection segment is calculated;
[0018] The degree of contraction of the independent detection segment is obtained based on the standard width and the local width.
[0019] In some embodiments of the present invention, based on the continuous frame images, the main edge of the independent detection segment is extracted, including:
[0020] Based on the continuous frame images, the four vertices of the independent detection segment are marked to obtain the fitted rectangle of the independent detection segment, and the theoretical perimeter of the fitted rectangle is calculated.
[0021] The outer contour of the independent detection segment is extracted using OpenCV.findContours. An error range is set, and the outer contour whose perimeter is within the error range is retained. This outer contour is marked as the main edge of the independent detection segment, and the remaining straight lines are regarded as interference lines. The interference line area is covered and removed by masking, and only the core area surrounded by the main edge is retained.
[0022] In some embodiments of the present invention, based on the continuous frame images, the area ratio of the reflective region of the independent detection segment is analyzed, including:
[0023] The consecutive frame images are converted to HSV space and the luminance channel is extracted;
[0024] For the brightness channel, the Otsu algorithm is used to obtain the segmentation threshold, and the reflective area of the independent detection segment is obtained by binarization;
[0025] The areas of the reflective region and the independent detection segment are obtained, and the area ratio of the reflective region in the independent detection segment is calculated to obtain the area ratio of the reflective region in the independent detection segment.
[0026] In some embodiments of the present invention, a reference threshold is dynamically set, and a reference segment is obtained based on the degree of influence of the wrinkles, including:
[0027] Set the initial reference threshold;
[0028] Determine whether the degree of wrinkle influence of the independent detection segment is less than or equal to the initial reference threshold;
[0029] If so, the independent detection segment will be included in the reference segment library;
[0030] Calculate the average wrinkle influence of all independent detection segments in the reference segment library to obtain a new reference threshold, and use the new reference threshold to determine whether to include the independent detection segment in the reference segment library.
[0031] After K independent detection segments have been accumulated in the reference segment library, each time a new independent detection segment is added to the reference segment library, it is compared with the independent detection segment with the highest degree of wrinkle influence in the reference segment library, and the independent detection segment with the lower degree of wrinkle influence is retained in the reference segment library.
[0032] Continuously update the reference segment library until all independent detection segments have been detected;
[0033] The independent detection segment corresponding to the minimum value of the wrinkle influence in the reference segment library is selected as the reference segment in real time.
[0034] In some embodiments of the present invention, based on the qualified frame image of the independent detection segment, the gray value difference of pixels in the segment to be detected and the reference segment is analyzed to filter out defective pixels and obtain defective regions, including:
[0035] Based on the qualified frame image, establish a coordinate system between the segment to be detected and the reference segment;
[0036] Based on the coordinate system, the segment to be detected is transformed to the coordinate system of the reference segment to complete image alignment;
[0037] Based on the aligned image, calculate the gray value difference of the corresponding pixel points in all the segments to be detected and the reference segments;
[0038] Based on the mean and standard deviation of the gray values of all pixels in the reference segment, a gray value difference threshold is set;
[0039] Pixels within the segment to be detected whose grayscale value difference is greater than the grayscale value difference threshold are marked as defective pixels.
[0040] By analyzing connected components, consecutive defective pixels are merged into suspected defective regions.
[0041] When the number of defective pixels in the suspected defective area is greater than or equal to N, the suspected defective area is determined to be a defective area.
[0042] In some embodiments of the present invention, after obtaining the defective region, the process further includes:
[0043] Connectivity analysis is performed on the defect regions of the independent detection segment and its adjacent independent detection segments to merge continuous defect regions into continuous defect regions.
[0044] According to a second aspect of the present invention, a visual inspection system for defects in plastic packaging bags is provided, comprising: a memory and a processor, wherein:
[0045] The memory is used to store program code;
[0046] The processor is configured to read program code stored in the memory and execute the method described in the first aspect of the present invention.
[0047] In some embodiments of the present invention, the processor includes:
[0048] The image acquisition module is used to obtain the moving speed of the production line, set the shooting frame rate of the camera, and acquire continuous frame images of the long plastic packaging bags moving along the production line.
[0049] The segmentation module is used to set the segment length based on the shooting frame rate and the moving speed, and to divide the long plastic packaging bag into several independent detection segments;
[0050] The wrinkle influence analysis module is used to analyze the degree of contraction and the area ratio of reflective regions of the independent detection segment based on the continuous frame images, to obtain the degree of wrinkle influence of the independent detection segment, and then determine the qualified frame images of the independent detection segment.
[0051] The reference segment acquisition module is used to dynamically set a reference threshold and obtain a reference segment based on the degree of influence of the wrinkles.
[0052] The defect area acquisition module is used to analyze the gray value difference of pixels in the segment to be detected and the reference segment based on the qualified frame image of the independent detection segment, filter defective pixels, and obtain the defect area;
[0053] The production process fault tracing module is used to trace production process faults based on the location distribution and aggregation characteristics of the defective areas.
[0054] Compared with existing technologies, the visual inspection method and system for defects in plastic packaging bags provided by this invention have the following advantages:
[0055] This invention divides long plastic packaging bags into several independent inspection segments, each with a relatively clear range, significantly narrowing the search area for defect location and facilitating rapid and accurate identification of defective areas. By analyzing the degree of contraction and the proportion of reflective areas in each independent inspection segment, the degree of wrinkle influence is determined, thereby identifying the qualified frame image for that segment. This effectively avoids misjudging quality defects caused by wrinkled areas, improving the accuracy of inspection results. By dynamically setting a reference threshold, a reference segment is obtained based on the degree of wrinkle influence, solving the problem of not being able to obtain a reference segment in advance and improving its effectiveness, further enhancing the accuracy of inspection results. By analyzing the grayscale difference between pixels in the segment to be inspected and the reference segment, defective pixels are filtered to obtain defective areas. Based on the location distribution and aggregation characteristics of defective areas, production process fault tracing is performed. This invention achieves real-time inspection and fully automated processing by setting up high-frame-rate cameras during the production stage of uncut long plastic packaging bags, eliminating the need for manual intervention. Furthermore, by inspecting each independent inspection segment individually, rapid and accurate location of defective areas is achieved. Attached Figure Description
[0056] To more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0057] Figure 1 A schematic diagram of the basic process of a visual inspection method for defects in plastic packaging bags provided in one embodiment of the present invention;
[0058] Figure 2 This is a schematic diagram of a camera image acquisition method provided in one embodiment of the present invention;
[0059] Figure 3 This is a schematic diagram of an independent detection segment division provided in one embodiment of the present invention;
[0060] Figure 4 This is a schematic diagram of the coordinates of an independent detection segment provided in one embodiment of the present invention;
[0061] Figure 5 A schematic diagram of a defective region and a continuous defective region provided in an embodiment of the present invention;
[0062] Figure 6 This is a schematic diagram of the basic components of a visual inspection system for defects in plastic packaging bags provided in one embodiment of the present invention. Detailed Implementation
[0063] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of a visual inspection method and system for defects in plastic packaging bags proposed according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0064] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. Terms such as “comprising,” “including,” or any other variations thereof are intended to cover a non-exclusive inclusion, such that a circuit structure, article, or device comprising a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such article or device. Without further limitation, an element defined by the phrase “comprising one…” does not exclude the presence of additional identical elements in the article or device that includes the element.
[0065] The specific scheme of the visual inspection method for defects in plastic packaging bags provided by the present invention will be described in detail below with reference to the accompanying drawings.
[0066] Please see Figure 1 This illustrates the basic process of a visual inspection method for defects in plastic packaging bags provided by an embodiment of the present invention.
[0067] like Figure 1 As shown, an embodiment of the present invention provides a visual inspection method for defects in plastic packaging bags, specifically including:
[0068] S100: Acquires the moving speed of the production line, sets the camera's shooting frame rate, and captures continuous frame images of long plastic packaging bags moving along the production line.
[0069] Before the cutting stage in the plastic packaging bag production process, a high-frame camera is mounted directly above the uncut strip of packaging bag. The camera's field of view covers the entire width of the strip of packaging bag, forming a rectangular shooting area with its length. Figure 2 As shown, this is how continuous frame images of long packaging bags moving along the production line are captured.
[0070] To ensure continuous image acquisition and prevent blurry images or missed defects due to excessively fast production line speeds, the lower limit of the camera's frame rate needs to be determined based on the production line speed. Therefore, the camera frame rate should be set high enough to ensure that the distance the packaging bag moves between adjacent frames is less than the size of the smallest detectable defect. This guarantees that the smallest detectable defect is fully represented in a single frame, preventing small defects from being segmented across two or more frames due to excessive bag movement, thus affecting the identification of defective areas.
[0071] Therefore, in embodiments of the present invention, the moving speed of the production line is first obtained, as well as the longitudinal length of the camera's field of view and the camera's longitudinal pixel resolution; then, based on the moving speed of the production line, the longitudinal length, and the longitudinal pixel resolution, the camera's shooting frame rate is set. The camera's shooting frame rate should satisfy:
[0072]
[0073] In the formula, f represents the camera's frame rate; v represents the production line's moving speed; FOV H H represents the vertical length of the camera's field of view; H represents the camera's vertical pixel resolution; n represents the minimum number of pixels that defects should occupy in the image.
[0074] The higher the production line's moving speed (v), the higher the required camera frame rate. This indicates the minimum detectable defect size requirement; the smaller the value, the higher the required camera frame rate. The field of view (FOV) is the vertical length of the camera's field of view. H The larger the value, the larger the camera's shooting range, and the smaller the size of the flaw in the image. Therefore, the minimum detectable flaw size needs to be larger. The smaller the vertical pixel resolution H value of the camera, the blurrier the camera image, and the larger the minimum detectable flaw size needs to be to ensure that the flaw is clear. Usually, n≥2 to avoid noise and interference from a single pixel causing misjudgment.
[0075] S200: Based on the shooting frame rate and movement speed, the segment length is set to divide the long plastic packaging bag into several independent detection segments.
[0076] When performing defect detection on long plastic packaging bags, the undivided bags present limitations in locating defects due to their length; the large area affected makes pinpointing the defect location quite difficult. Therefore, to improve defect location efficiency, this invention divides the complete long plastic packaging bag into several relatively independent segments, each with a clearly defined range. This significantly narrows the search area for defect location, facilitating quick and accurate identification of the defect region. Specifically, on continuously produced long plastic packaging bags, the width of the bag serves as the lateral boundary, and several independent detection segments are defined along the production line direction at fixed lengths, such as... Figure 3 As shown. Based on the shooting frame rate and movement speed, the segment length is set, dividing the long plastic packaging bag into several independent detection segments. Furthermore, according to the camera's shooting frame rate f, the acquisition time interval for each frame can be obtained as t = 1 / f. Combining this with the production line's movement speed v, the distance the long plastic packaging bag moves on the production line during the acquisition time interval is d = v·t = v / f. Based on this movement distance, the segment length is derived as:
[0077]
[0078] In the formula, L represents the segment length; k represents the segmentation empirical coefficient (usually taken as 2 to 4); d represents the distance the long plastic packaging bag moves on the production line during the acquisition time interval; v represents the speed of the production line; and f represents the camera's shooting frame rate.
[0079] S300: Based on continuous frame images, analyze the degree of contraction and the area ratio of reflective regions of independent detection segments to obtain the degree of wrinkle influence of independent detection segments, and then determine the qualified frame images of independent detection segments.
[0080] During the production of long plastic packaging bags, the conveyor devices at both ends continuously apply force to the bags to drive them along the production line. However, this force easily causes wrinkles on the bags, and these wrinkled areas may be misjudged as quality defects, affecting the accuracy of the inspection results. To avoid such misjudgments, it is necessary to select the frame with the least longitudinal stretching and the fewest wrinkles from multiple frames to minimize interference caused by the deformation of the plastic packaging bag. Starting from the first frame, the position and shape changes of each independent inspection segment area from entering the camera's field of view to leaving the shooting area are recorded, and the wrinkling situation is analyzed: When moving on the production line, wrinkles cause local material stretching, which is directly manifested as a contraction in lateral width (e.g., the compression of wrinkles in the edge area causes the width of the middle section to narrow). At the same time, the tension at both ends of the production line causes wrinkles to form strip-shaped protrusions along the production line direction on the surface of the long plastic packaging bag, enhancing local reflection. Therefore, in the wrinkle detection of plastic packaging, the degree of contraction in the width direction of the long plastic packaging bag and the proportion of the reflective area are used as quantitative indicators of the degree of wrinkling.
[0081] Based on the above analysis, in the embodiments of the present invention, based on continuous frame images, the degree of contraction and the proportion of reflective area of independent detection segments are analyzed to obtain the degree of wrinkle influence of independent detection segments, thereby determining the qualified frame images of independent detection segments. Wherein:
[0082] Based on consecutive frame images, the degree of contraction of independent detection segments is analyzed, further including:
[0083] First, the standard width of the long plastic packaging bag is obtained, that is, the width of the long plastic packaging bag in a flawless state. This can be measured before the long plastic packaging bag enters the production line.
[0084] Then, based on consecutive frame images, the main edges of independent detection segments are extracted, their coordinates are obtained, and the local width of each independent detection segment is calculated. Specifically:
[0085] In a series of frames, the four vertices of an independent detection segment are marked. Each independent detection segment is considered as a rectangular region composed of these four vertices. Therefore, the fitted rectangle of the independent detection segment is obtained, and the theoretical perimeter of the fitted rectangle is calculated as: (segment length + width of the long plastic bag) × 2.
[0086] Because plastic packaging bags are pre-cut with cutting lines or pre-defined areas before formal slitting, each independent detection segment should contain four main edges (top and bottom edges, left and right edges). Independent detection segments containing cutting lines or pre-defined areas will additionally detect one or two straight lines (or simple broken lines) perpendicular or parallel to the main edges, and their positions are fixed. These pre-defined areas may interfere with the judgment of wrinkles. Therefore, before formally analyzing wrinkles, independent detection segments containing cutting lines or pre-defined areas need to be processed to remove the corresponding areas. Therefore, the main edges of independent detection segments are extracted. Specifically, the outer contour of the independent detection segment is extracted using OpenCV.findContours. An error range is set (the value can be 5%), and the outer contour whose perimeter is within the error range of the theoretical perimeter is retained. This outer contour is marked as the main edge of the independent detection segment, and the remaining straight lines are considered interference lines. The interference line areas are covered and removed using a mask, leaving only the core area surrounded by the main edges.
[0087] The coordinates (x, y) of the top edge pixel point corresponding to the main edge of the independent detection segment are obtained through edge detection. top ,y top ) and the coordinates of the bottom edge pixel (x bottom ,y bottom ), calculate the local width of the independent detection segment as W. current =|y top ―y bottom |
[0088] Finally, based on the standard width and local width, the degree of shrinkage of the independent detection segment is obtained. The formula for calculating the degree of shrinkage of the independent detection segment is:
[0089]
[0090] In the formula, C represents the degree of contraction of the independently detected segment; W std This indicates the standard width of a long plastic bag in its unblemished state; minW current This represents the minimum value among all local widths of the independent detection segment.
[0091] Based on consecutive frame images, the area ratio of reflective regions in independent detection segments is analyzed. The specific implementation method is as follows:
[0092] The continuous frame images are converted to HSV space and the luminance channel V is extracted. For the luminance channel, the Otsu algorithm is used to obtain the segmentation threshold, and binarization is performed to obtain the reflective areas of independent detection segments. Furthermore, after obtaining the reflective areas of independent detection segments, the following steps are taken: since the production line moves laterally, the reflective areas must be horizontally elongated. Therefore, interfering reflective areas need to be removed from all obtained reflective areas. Specifically, this is done by calculating the standard deviation σ of the x-axis (production line movement direction) coordinates of all pixels within the reflective area.x The standard deviation σ of the y-axis (the direction perpendicular to the production line movement direction) coordinate. y σ is required x >2σ y (The lateral dispersion is significantly greater than the longitudinal dispersion, ensuring that the area extends along the x-axis). At the same time, the area with the minimum bounding rectangle angle θ (the angle between the side of the minimum bounding rectangle along the production line movement direction and the x-axis) of the reflective area is retained within ±15° (ensuring that the reflective area is basically parallel to the production line movement direction).
[0093] Then, the areas of the reflective regions (all reflective regions after removing interfering reflective regions in the independent detection segment) and the independent detection segment are obtained, and the area ratio of the reflective regions in the independent detection segment is calculated. The area ratio of the reflective regions in the independent detection segment is then obtained as follows:
[0094]
[0095] In the formula, B represents the percentage of the reflective area in the independent detection segment; S 反光区域 S represents the sum of the areas of all reflective regions in the independent detection segment after removing interfering reflective regions; 独立检测段 This represents the area of the independent detection segment.
[0096] Based on the degree of shrinkage and the proportion of reflective area in the independent detection segment, the degree of wrinkle influence in the independent detection segment is obtained as follows:
[0097] Score = α·C + β·B
[0098] In the formula, Score represents the degree of influence of wrinkles in the independent detection segment; α represents the weight of the degree of contraction in the independent detection segment (value range [0.3, 0.4]); β represents the weight of the area ratio of the reflective region in the independent detection segment (value range [0.6, 0.7]), and α + β = 1.
[0099] The higher the score, the more the current independent detection segment is affected by wrinkles.
[0100] Based on the degree of wrinkle influence of the independent detection segment, the qualified frame image of the independent detection segment is determined. Specifically, multiple frames of images are recorded throughout the entire process of the independent detection segment from entering the shooting area to leaving the shooting area. The degree of wrinkle influence of the independent detection segment in each frame is calculated, and the single frame image with the smallest wrinkle influence value is selected as the qualified frame image of the independent detection segment.
[0101] S400: Dynamically sets the reference threshold and obtains the reference segment based on the degree of influence of wrinkles.
[0102] The flawless control plastic packaging segment represents an ideal state that meets quality requirements. By comparing the independent inspection segment to be inspected with the reference segment, it is possible to clearly determine whether the independent inspection segment to be inspected has defects. However, in a real production environment, considering that reference segments may not be available in advance, this invention adopts a dynamic initialization strategy, that is, starting from the first frame image after the production line starts, a reliable reference segment library is gradually built through real-time screening.
[0103] Based on the above analysis, in the embodiments of the present invention, a reference threshold is dynamically set, and a reference segment is obtained according to the degree of influence of wrinkles. The specific implementation method is as follows:
[0104] After the production line starts up, in order to quickly establish a reliable reference standard, the width shrinkage caused by the tension at both ends of the independent inspection section of the plastic packaging bag is detected. Considering that the thickness on both sides of the pre-cut line reserved before the plastic packaging bag is divided is usually greater than that of the main body area, this thickness difference will cause a difference in the degree of shrinkage between the area near the cut line (the thick area, usually located on both sides of the cut line, the width of which is determined by the product design) and the main body area (the thin area). That is, the thick area has low ductility and a smaller shrinkage range, while the thin area has thinner material, higher ductility, and a relatively larger shrinkage range. Therefore, initial reference thresholds are set for the thick area of the cut line and the thin area of the main body. The allowable shrinkage rate threshold for the thick area is lower, such as ≤1%, while the allowable shrinkage rate threshold for the thin area is higher, such as ≤5%. It should be noted that within the independent inspection section area, if there is a cut line or a pre-reserved area for division, the area on both sides of the cut line (the width range is determined according to the actual reserved width of the cut line of the plastic packaging bag) or the pre-reserved area for division is considered the thick area, and other areas are considered the thin area. The degree of wrinkle influence of the first independent detection segment that meets the threshold screening is used as the initial reference threshold, that is, the thin area meets Score≤5% and the thick area meets Score≤1%. The initial reference threshold includes the initial reference threshold for the thin area and the initial reference threshold for the thick area.
[0105] Subsequently, the subsequent independent inspection segments are inspected to determine whether the wrinkle influence of the independent inspection segment is less than or equal to the initial reference threshold. If so, the independent inspection segment is included in the reference segment library. The mean of the wrinkle influence of all independent inspection segments in the reference segment library plus k times the standard deviation (k can be 1 to 3) is calculated as the new reference threshold. If not, it is marked as a defective segment and skipped.
[0106] Once K (K can be 5-10) independent detection segments have accumulated in the reference segment library, all independent detection segments in the reference segment library are sorted from highest to lowest Score value. Subsequently, each new independent detection segment in the reference segment library is compared with the independent detection segment in the reference segment library with the highest wrinkle influence (Score value), and the independent detection segment with the lower wrinkle influence (Score value) is retained in the reference segment library. This mechanism continuously updates the reference segment library until all independent detection segments have been detected.
[0107] The independent detection segment corresponding to the minimum value of the wrinkle influence degree (Score value) in the reference segment library is selected as the reference segment in real time.
[0108] S500: Based on the qualified frame image of the independent detection segment, analyze the gray value difference of the pixels in the segment to be detected and the reference segment, filter out defective pixels, and obtain the defective area.
[0109] Based on the qualified frame images of the independent detection segment, the grayscale value difference of pixels in the segment to be detected and the reference segment is analyzed to filter out defective pixels and obtain the defective region. Further steps include:
[0110] To more accurately locate defective areas, image registration is performed by establishing a coordinate system in each segment to be inspected and a reference segment. Specifically: based on the qualified frame images of the segment to be inspected and the reference segment, with the upper left corner of each segment as the origin, the x-axis is along the length of the plastic packaging bag, and the y-axis is along the width of the plastic packaging bag, as shown below. Figure 4 As shown, ensure that the coordinate system orientation and scale of all segments to be detected and reference segments are consistent.
[0111] Based on the coordinate system, the segment to be detected is transformed to the coordinate system of the reference segment to complete image alignment. Specifically, the edge corner points (such as Harris corner points) of the reference segment and the segment to be detected are extracted, and the translation amount (Δx, Δy) is calculated by matching feature points to transform the segment to be detected to the coordinate system of the reference segment.
[0112] Based on the aligned image, the grayscale difference between corresponding pixels in all segments to be detected and the reference segment is calculated as follows:
[0113] D i (x,y)=|I i检测 (x,y)―I i参照 (x,y)|
[0114] In the formula, D i (x,y) represents the grayscale difference between the i-th pixel in the segment to be detected and the corresponding pixel in the reference segment; (x,y) represents the coordinates of the i-th pixel in the coordinate system; i检测 (x,y) represents the grayscale value of the i-th pixel in the segment to be detected; I i参照(x,y) represents the grayscale value of the i-th pixel in the reference segment.
[0115] Based on the mean and standard deviation of the grayscale values of all pixels within the reference segment, the grayscale value difference threshold is set as follows:
[0116] T=μ+kσ
[0117] In the formula, T represents the gray value difference threshold; μ and σ represent the mean and standard deviation of the gray values of all pixels in the reference segment, respectively; k represents the fluctuation coefficient. The larger k is, the greater the gray value difference fluctuation in the normal area is allowed (the higher the fault tolerance rate) and the less likely it is to be misjudged (usually a value of 2 to 3).
[0118] Pixels within the detection segment whose grayscale value difference exceeds the grayscale value difference threshold are marked as defective pixels.
[0119] By analyzing connected components, such as 8-neighborhood connections, consecutive defective pixels are merged into suspected defective regions. When the number of defective pixels in a suspected defective region is greater than or equal to N, where N can be 5 to 15, determined based on the camera's resolution, the suspected defective region is identified as a defective region. Figure 5 As shown; if the number of defective pixels in a suspected defective area is less than N, it is considered a noise defective area.
[0120] After obtaining the defective regions, the process includes: performing connected component analysis on the defective regions of independent detection segments and their adjacent independent detection segments, such as 8-neighborhood connectivity, to merge consecutive defective regions into consecutive defective regions, such as... Figure 5 As shown, the defect area of a single independent detection segment or a continuous defect area formed by merging multiple adjacent (greater than or equal to 2) independent detection segments is located.
[0121] S600: Based on the location distribution and aggregation characteristics of defective areas, traceability of production process faults is performed.
[0122] Simple production process fault tracing can be performed based on the location distribution and aggregation characteristics of defective areas (or continuous defective areas).
[0123] in:
[0124] Edge defects (located on both sides of the independent inspection section) are mostly caused by the cutting and slitting process. It is necessary to check the alignment accuracy of the slitting blade and the usage time of the blade.
[0125] Defects in functional areas (such as the sealing line, heat-sealing area, etc.) directly affect the sealing performance of the packaging. It is necessary to focus on checking whether the heat-sealing temperature is within the standard range and whether there are foreign objects adhering to the surface of the sealing mold.
[0126] Surface defects (located in the middle area outside the edge area and functional area), such as bubbles, are usually related to raw materials or molding process. It is necessary to check whether there are dents, wear or impurities on the surface of the printing roller.
[0127] Based on the same inventive concept as the above method, this embodiment also provides a visual inspection system for defects in plastic packaging bags.
[0128] Please see Figure 6 This illustrates the basic components of a visual inspection system for defects in plastic packaging bags provided in one embodiment of the present invention.
[0129] like Figure 6 As shown, a visual inspection system for defects in plastic packaging bags includes: a memory 10 and a processor 20, wherein:
[0130] Memory 10 is used to store program code;
[0131] The processor 20 is used to read the program code stored in the memory 10 and execute it to acquire the moving speed of the production line, set the shooting frame rate of the camera, and acquire continuous frame images of the long plastic packaging bag moving along the production line; based on the shooting frame rate and moving speed, it sets the segment length and divides the long plastic packaging bag into several independent inspection segments; based on the continuous frame images, it analyzes the degree of contraction and the area ratio of reflective areas of the independent inspection segments to obtain the degree of wrinkle influence of the independent inspection segments, and then determines the qualified frame images of the independent inspection segments; it dynamically sets a reference threshold and obtains a reference segment according to the degree of wrinkle influence; based on the qualified frame images of the independent inspection segments, it analyzes the gray value difference of pixels in the segment to be inspected and the reference segment, filters out defective pixels, and obtains defective areas; based on the location distribution and set characteristics of the defective areas, it performs production process fault tracing.
[0132] Furthermore, the processor 20 includes an image acquisition module 21, a segmentation module 22, a wrinkle influence analysis module 23, a reference segment acquisition module 24, a defect area acquisition module 25, and a production process fault tracing module 26. Wherein:
[0133] Image acquisition module 21 is used to obtain the moving speed of the production line, set the shooting frame rate of the camera, and acquire continuous frame images of the long plastic packaging bag moving along the production line.
[0134] Segmentation module 22 is used to set the segment length based on the shooting frame rate and movement speed, and divide the long plastic packaging bag into several independent detection segments;
[0135] The wrinkle influence analysis module 23 is used to analyze the degree of contraction and the area ratio of reflective regions of independent detection segments based on continuous frame images, to obtain the degree of wrinkle influence of independent detection segments, and then determine the qualified frame images of independent detection segments.
[0136] The reference segment acquisition module 24 is used to dynamically set the reference threshold and obtain the reference segment according to the degree of influence of the wrinkles;
[0137] The defect area acquisition module 25 is used to analyze the gray value difference of pixels in the segment to be detected and the reference segment based on the qualified frame image of the independent detection segment, filter defective pixels, and obtain the defect area.
[0138] The production process fault tracing module 26 is used to trace production process faults based on the location distribution and aggregation characteristics of defective areas.
[0139] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0140] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
Claims
1. A method for visual inspection of defects in plastic packaging bags, characterized in that, The method includes: The system acquires the moving speed of the production line, sets the camera's frame rate, and captures continuous frame images of the long plastic packaging bags moving along the production line. Based on the shooting frame rate and the moving speed, the segment length is set to divide the long plastic packaging bag into several independent detection segments; Based on the continuous frame images, the degree of contraction and the area ratio of reflective regions of the independent detection segments are analyzed to obtain the degree of wrinkle influence of the independent detection segments, and then the qualified frame images of the independent detection segments are determined. A reference threshold is dynamically set to obtain a reference segment based on the degree of influence of the wrinkles; Based on the qualified frame image of the independent detection segment, the gray value difference of the pixels in the segment to be detected and the reference segment is analyzed to filter out defective pixels and obtain the defective area. Based on the location distribution and aggregation characteristics of the defective areas, production process fault tracing is performed.
2. The method for visual inspection of defects in plastic packaging bags according to claim 1, characterized in that, Set the camera's shooting frame rate, including: Obtain the vertical length of the camera's field of view and the camera's vertical pixel resolution; The camera's frame rate is set based on the production line's moving speed, as well as the longitudinal length and the longitudinal pixel resolution.
3. The visual inspection method for defects in plastic packaging bags according to claim 1, characterized in that, Based on the continuous frame images, the degree of contraction of the independent detection segments is analyzed, including: Obtain the standard width for long plastic packaging bags; Based on the continuous frame images, the main edge of the independent detection segment is extracted, the coordinates of the main edge are obtained, and the local width of the independent detection segment is calculated; The degree of contraction of the independent detection segment is obtained based on the standard width and the local width.
4. The method for visual inspection of defects in plastic packaging bags according to claim 3, characterized in that, Based on the consecutive frame images, the main edge of the independent detection segment is extracted, including: Based on the continuous frame images, the four vertices of the independent detection segment are marked to obtain the fitted rectangle of the independent detection segment, and the theoretical perimeter of the fitted rectangle is calculated. The outer contour of the independent detection segment is extracted using OpenCV.findContours. An error range is set, and the outer contour whose perimeter is within the error range is retained. This outer contour is marked as the main edge of the independent detection segment, and the remaining straight lines are regarded as interference lines. The interference line area is covered and removed by masking, and only the core area surrounded by the main edge is retained.
5. The method for visual inspection of defects in plastic packaging bags according to claim 1, characterized in that, Based on the continuous frame images, the area ratio of reflective regions in the independent detection segments is analyzed, including: The consecutive frame images are converted to HSV space and the luminance channel is extracted; For the brightness channel, the Otsu algorithm is used to obtain the segmentation threshold, and the reflective area of the independent detection segment is obtained by binarization; The areas of the reflective region and the independent detection segment are obtained, and the area ratio of the reflective region in the independent detection segment is calculated to obtain the area ratio of the reflective region in the independent detection segment.
6. The method for visual inspection of defects in plastic packaging bags according to claim 1, characterized in that, A reference threshold is dynamically set, and a reference segment is obtained based on the degree of influence of the wrinkles, including: Set the initial reference threshold; Determine whether the degree of wrinkle influence of the independent detection segment is less than or equal to the initial reference threshold; If so, the independent detection segment will be included in the reference segment library; Calculate the average wrinkle influence of all independent detection segments in the reference segment library to obtain a new reference threshold, and use the new reference threshold to determine whether to include the independent detection segment in the reference segment library; After K independent detection segments have been accumulated in the reference segment library, each time a new independent detection segment is added to the reference segment library, it is compared with the independent detection segment with the highest degree of wrinkle influence in the reference segment library, and the independent detection segment with the lower degree of wrinkle influence is retained in the reference segment library. Continuously update the reference segment library until all independent detection segments have been detected; The independent detection segment corresponding to the minimum value of the wrinkle influence in the reference segment library is selected as the reference segment in real time.
7. The method for visual inspection of defects in plastic packaging bags according to claim 1, characterized in that, Based on the qualified frame images of the independent detection segment, the grayscale value difference of pixels in the segment to be detected and the reference segment is analyzed to filter out defective pixels and obtain defective regions, including: Based on the qualified frame image, establish a coordinate system between the segment to be detected and the reference segment; Based on the coordinate system, the segment to be detected is transformed to the coordinate system of the reference segment to complete image alignment; Based on the aligned image, calculate the gray value difference of the corresponding pixel points in all the segments to be detected and the reference segments; Based on the mean and standard deviation of the gray values of all pixels in the reference segment, a gray value difference threshold is set; Pixels within the segment to be detected whose grayscale value difference is greater than the grayscale value difference threshold are marked as defective pixels. By analyzing connected components, consecutive defective pixels are merged into suspected defective regions. When the number of defective pixels in the suspected defective area is greater than or equal to N, the suspected defective area is determined to be a defective area.
8. The method for visual inspection of defects in plastic packaging bags according to claim 1, characterized in that, After identifying the defective area, the following steps are also included: Connectivity analysis is performed on the defect regions of the independent detection segment and its adjacent independent detection segments to merge continuous defect regions into continuous defect regions.
9. A visual inspection system for defects in plastic packaging bags, characterized in that, The system includes: a memory and a processor, wherein: The memory is used to store program code; The processor is configured to read program code stored in the memory and execute the method as described in any one of claims 1 to 8.
10. The visual inspection system for defects in plastic packaging bags according to claim 9, characterized in that, The processor includes: The image acquisition module is used to obtain the moving speed of the production line, set the shooting frame rate of the camera, and acquire continuous frame images of the long plastic packaging bags moving along the production line. The segmentation module is used to set the segment length based on the shooting frame rate and the moving speed, and to divide the long plastic packaging bag into several independent detection segments; The wrinkle influence analysis module is used to analyze the degree of contraction and the area ratio of reflective regions of the independent detection segment based on the continuous frame images, to obtain the degree of wrinkle influence of the independent detection segment, and then determine the qualified frame images of the independent detection segment. The reference segment acquisition module is used to dynamically set a reference threshold and obtain a reference segment based on the degree of influence of the wrinkles. The defect area acquisition module is used to analyze the gray value difference of pixels in the segment to be detected and the reference segment based on the qualified frame image of the independent detection segment, filter defective pixels, and obtain the defect area; The production process fault tracing module is used to trace production process faults based on the location distribution and aggregation characteristics of the defective areas.
Citation Information
Patent Citations
Packaging flatness detection method and system, electronic equipment and storage medium
CN111161263A
Industrial product image target extraction and defect judgment method
CN112200805A