Visual inspection method and system for flaws of plastic packaging bag
By collecting continuous frame images of long plastic packaging bags in real time on the production line, dividing independent detection segments, analyzing the degree of shrinkage and reflective areas, and dynamically setting reference thresholds, the problems of limited detection range and missed detection in the existing technology are solved, and efficient and accurate defect detection and fault traceability are achieved.
Patent Information
- Application Number
- CN202510654852.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2045-05-21
AI Technical Summary
In the prior art, defect detection of plastic packaging bags is usually carried out after cutting and forming, making it difficult to capture defects in the dynamic process, and the detection range is limited, and there is a risk of missed inspection.
By erecting a high-frame rate camera on the production line, we collect continuous frame images of long plastic packaging bags in real time, divide them into several independent detection sections, analyze the degree of shrinkage and the proportion of reflective area, dynamically set the reference threshold, filter defective pixel points, and realize automatic detection of the entire process.
It realizes rapid and accurate positioning of defective areas, avoids misjudgment of wrinkle areas, improves the accuracy of detection results, and traces faults in production links, reducing manual intervention.
Smart Images

Figure CN120510344A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of visual defect detection, and in particular to a method and system for visually detecting defects in plastic packaging bags. Background Art
[0002] Plastic packaging is a crucial carrier for many industries, including food and pharmaceuticals. Its quality is directly linked to the safe storage and transportation of its contents. If cosmetic, structural, or functional defects that may arise during the production process go undetected, they can not only cause packaging problems during use, threatening consumer health and rights, but can also severely damage the manufacturer's brand reputation. Using efficient defect detection methods to monitor production processes in real time and promptly identify and eliminate substandard products not only improves production efficiency but also ensures product compliance with industry standards and regulations, laying a solid foundation for companies to build a quality trust system.
[0003] Currently, the inspection of defects in plastic packaging bags in factories is often carried out after cutting and forming. The inspection timing lags behind the production process, making it difficult to capture defects such as stretching breakage caused by dynamic processes such as stretching and uneven tension. At the same time, traditional sampling inspection has a limited coverage and there is a risk of missed detection. Summary of the Invention
[0004] In order to solve the above technical problems, the object of the present invention is to provide a method and system for visually detecting defects in plastic packaging bags.
[0005] According to a first aspect of an embodiment of the present invention, a method for visually inspecting defects in plastic packaging bags is provided, wherein the technical solution adopted is as follows:
[0006] Obtain the moving speed of the production line, set the camera's frame rate, and capture continuous frame images of long plastic packaging bags moving along the production line;
[0007] Based on the shooting frame rate and the moving speed, a segment length is set to divide the long plastic packaging bag into a plurality of independent detection segments;
[0008] Based on the continuous frame images, analyzing the shrinkage degree and the area ratio of the reflective region of the independent detection segment to obtain the wrinkle influence degree of the independent detection segment, and then determining a qualified frame image of the independent detection segment;
[0009] Dynamically setting a reference threshold to obtain a reference segment according to the degree of influence of the wrinkles;
[0010] Based on the qualified frame image of the independent detection segment, analyzing the grayscale value difference between the pixel points in the detection segment and the reference segment, screening the defective pixel points, and obtaining the defective area;
[0011] According to the location distribution and collective characteristics of the defective areas, production process fault tracing is carried out.
[0012] In some embodiments of the present invention, setting the shooting frame rate of a camera includes:
[0013] Get the vertical length of the camera's field of view and the camera's vertical pixel resolution;
[0014] The shooting frame rate of the camera is set according to the moving speed of the production line, the longitudinal length and the longitudinal pixel resolution.
[0015] In some embodiments of the present invention, analyzing the contraction degree of the independent detection segment based on the continuous frame images includes:
[0016] Get the standard width of long plastic packaging bags;
[0017] Extracting the main edge of the independent detection segment based on the continuous frame images, obtaining the coordinates of the main edge, and calculating the local width of the independent detection segment;
[0018] The shrinkage degree of the independent detection section is obtained according to the standard width and the local width.
[0019] In some embodiments of the present invention, extracting the main edge of the independent detection segment based on the continuous frame images includes:
[0020] Based on the continuous frame images, marking four vertices of the independent detection segment, obtaining a fitting rectangle of the independent detection segment, and calculating a theoretical perimeter of the fitting rectangle;
[0021] The outer contour of the independent detection segment is extracted through OpenCV.findContours, and an error range is set. The outer contour whose error between the perimeter of the outer contour and the theoretical perimeter is within the error range is retained and marked as the main edge of the independent detection segment. The remaining straight lines are regarded as interference lines, and the interference line area is covered and eliminated by masking, so that only the core area surrounded by the main edge is retained.
[0022] In some embodiments of the present invention, analyzing the reflective area ratio of the independent detection segment based on the continuous frame images includes:
[0023] Convert the continuous frame images into HSV space and extract the brightness channel;
[0024] For the brightness channel, the Otsu algorithm is used to obtain a segmentation threshold, and binarization is performed to obtain the reflective area of the independent detection segment;
[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, dynamically setting a reference threshold and obtaining a reference segment according to the degree of influence of the wrinkles includes:
[0027] Set the initial reference threshold;
[0028] determining whether the wrinkle influence degree of the independent detection segment is less than or equal to the initial reference threshold;
[0029] If yes, the independent detection segment is included in the reference segment library;
[0030] Calculating the average of the wrinkle influence degrees of all independent detection segments in the reference segment library to obtain a new reference threshold, and using the new reference threshold to determine whether to include the independent detection segment in the reference segment library;
[0031] When K independent detection segments are accumulated in the reference segment library, each new independent detection segment added to the reference segment library is compared with the independent detection segment with the highest wrinkle influence in the reference segment library, and the independent detection segment with the lowest wrinkle influence is retained in the reference segment library;
[0032] Continuously update the reference segment library until all independent test segments are tested;
[0033] The independent detection segment corresponding to the minimum value of the wrinkle influence degree in the reference segment library is selected in real time as the reference segment.
[0034] In some embodiments of the present invention, based on the qualified frame image of the independent detection segment, analyzing the grayscale value difference between pixels in the segment to be detected and the reference segment, screening defective pixels, and obtaining the defective area includes:
[0035] Based on the qualified frame image, establishing a coordinate system of the segment to be detected and the reference segment;
[0036] Based on the coordinate system, the segment to be detected is transformed into the coordinate system of the reference segment to complete image alignment;
[0037] Based on the aligned image, calculating the grayscale value differences of the corresponding pixel points in all the segments to be detected and the reference segments;
[0038] Setting a grayscale value difference threshold according to the mean and standard deviation of the grayscale values of all pixels in the reference segment;
[0039] Marking pixels in the segment to be detected whose grayscale value difference is greater than the grayscale value difference threshold as defective pixels;
[0040] Through connected domain analysis, continuous defective pixels are merged into suspected defective areas;
[0041] When the number of defective pixels in the suspected defect area is greater than or equal to N, the suspected defect area is determined to be a defect area.
[0042] In some embodiments of the present invention, obtaining the defect area further includes:
[0043] Connected domain analysis is performed on the defect areas of the independent detection segment and its adjacent independent detection segments before and after it, and continuous defect areas are merged into a continuous defect area.
[0044] According to a second aspect of an embodiment of the present invention, a plastic packaging bag defect visual inspection system 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 the program code stored in the memory and execute the method described in the first aspect of the embodiment 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 collect continuous frame images of the long plastic packaging bags moving along the production line;
[0049] A segmentation module, configured to set a segment length based on the shooting frame rate and the moving speed, and divide the long plastic packaging bag into a plurality of independent detection segments;
[0050] a wrinkle impact analysis module, configured to analyze the shrinkage degree and the reflective area ratio of the independent detection segment based on the continuous frame images, obtain the wrinkle impact degree of the independent detection segment, and further determine a qualified frame image of the independent detection segment;
[0051] A reference segment acquisition module is used to dynamically set a reference threshold and obtain a reference segment according to the degree of influence of the wrinkles;
[0052] a defective area acquisition module, configured to analyze the grayscale value difference between pixels in the segment to be inspected and the reference segment based on the qualified frame image of the independent inspection segment, screen defective pixels, and obtain the defective area;
[0053] The production link fault tracing module is used to trace the production link faults according to the location distribution and collective characteristics of the defective areas.
[0054] Compared with the existing technology, the present invention provides a method and system for visually inspecting defects in plastic packaging bags, which has the following beneficial effects:
[0055] The present invention divides the long plastic packaging bag into several independent detection segments, and the range of each independent detection segment is relatively clear, which can greatly reduce the search range for defect positioning and facilitate the rapid and accurate locking of the defect area; by analyzing the shrinkage degree and the area ratio of the reflective area of the independent detection segment, the wrinkle influence degree of the independent detection segment is obtained, and then the qualified frame image of the independent detection segment is determined, which can effectively avoid the misjudgment of the quality defect area caused by the wrinkle area and improve the accuracy of the detection result; by dynamically setting the reference threshold, the reference segment is obtained according to the wrinkle influence degree, which solves the problem of not being able to obtain the reference segment in advance, and improves the effectiveness of the reference segment, further improving the accuracy of the detection result; by analyzing the grayscale value difference of the pixel points in the segment to be detected and the reference segment, the defective pixel points are screened to obtain the defect area; according to the position distribution and collective characteristics of the defect area, the production link fault tracing is carried out. The present invention sets up a high frame rate camera in the production stage of the uncut long plastic packaging bag to achieve real-time detection and full process automation without manual intervention; and each independent detection segment is checked one by one to achieve rapid and accurate positioning of the defect area. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0057] Figure 1 A schematic diagram of the basic process of a method for visually inspecting defects in plastic packaging bags provided by one embodiment of the present invention;
[0058] Figure 2 A schematic diagram of camera image acquisition provided by one embodiment of the present invention;
[0059] Figure 3 A schematic diagram of dividing independent detection segments provided by one embodiment of the present invention;
[0060] Figure 4 A schematic diagram of independent detection segment coordinates provided by one embodiment of the present invention;
[0061] Figure 5 A schematic diagram of a defect area and a continuous defect area provided by an embodiment of the present invention;
[0062] Figure 6 A schematic diagram of the basic components of a plastic packaging bag defect visual inspection system provided by one embodiment of the present invention. DETAILED DESCRIPTION
[0063] To further illustrate the technical means and effectiveness of the present invention in achieving its intended objectives, the following, in conjunction with the accompanying drawings and preferred embodiments, provides a detailed description of the specific implementation, structure, features, and effectiveness of a method and system for visually inspecting defects in plastic packaging bags. In the following description, references to "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.
[0064] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this invention pertains. Terms such as "comprises," "comprising," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a circuit structure, article, or device comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such article or device. In the absence of further limitations, the phrase "comprising a ..." to define an element does not preclude the presence of other identical elements in the article or device comprising the element.
[0065] The following describes in detail a method for visually detecting defects in plastic packaging bags provided by the present invention with reference to the accompanying drawings.
[0066] See also Figure 1 , which shows the basic process of a plastic packaging bag defect visual detection method provided by an embodiment of the present invention.
[0067] like Figure 1 As shown, an embodiment of the present invention provides a method for visually detecting defects in plastic packaging bags, specifically comprising:
[0068] S100: Acquire the moving speed of the production line, set the shooting frame rate of the camera, and collect continuous frame images of the long plastic packaging bag moving along the production line.
[0069] Before the segmentation stage of the plastic packaging bag production process, a high-frame camera is set up directly above the unsegmented long packaging bag. The camera's shooting range covers the entire width of the long packaging bag, forming a rectangular shooting area with the length range, such as Figure 2 As shown, continuous frame images of the long packaging bag are taken as it moves along the production line.
[0070] To ensure continuous image acquisition and avoid blurred images or missed defects due to excessively fast production line speeds, the camera frame rate must be set to a lower limit based on the production line speed. Therefore, the camera frame rate should be set high enough to ensure that the distance the bag moves between two consecutive frames is less than the size of the smallest detectable defect. This ensures that the smallest detectable defect can be fully captured within a single frame, preventing small defects from being split across two or even multiple frames due to the bag's rapid movement, affecting the identification of the defective area.
[0071] Therefore, in the embodiment of the present invention, the moving speed of the production line, the vertical length of the camera's field of view, and the vertical pixel resolution of the camera are first obtained; then, the camera's shooting frame rate is set according to the moving speed of the production line, the vertical length, and the vertical pixel resolution. The camera's shooting frame rate should meet the following requirements:
[0072]
[0073] Where f is the camera frame rate; v is the moving speed of the production line; FOV H It represents the vertical length of the camera's field of view; H represents the vertical pixel resolution of the camera; and n represents the minimum number of pixels that a defect should occupy in the image.
[0074] The larger the production line's moving speed v value is, the higher the corresponding camera's shooting frame rate is required; Indicates the minimum size requirement for detectable defects. The smaller the value, the higher the frame rate requirement for the camera. The vertical length of the camera's field of view FOV H The larger the value, the larger the camera's shooting range, the smaller the size of the defect in the image, and the larger the minimum detectable defect size required; the smaller the camera's vertical pixel resolution H value, the blurrier the camera's shooting, and the larger the minimum detectable defect size required to ensure the clarity of the defect; usually n ≥ 2 to avoid noise and interference caused by a single pixel.
[0075] S200: 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.
[0076] When performing defect detection on long plastic packaging bags, undivided long plastic packaging bags have certain limitations in the actual scenario of locating defects due to their long length; due to the large range, if a defect occurs, it is quite difficult to determine the location of the defect. Therefore, in order to improve the efficiency of defect location, the present invention divides the complete long plastic packaging bag into several relatively independent individuals. The range of each individual is relatively clear, which can greatly reduce the search range for defect location and facilitate fast and accurate locking of the defect area. Specifically, on the continuously produced long plastic packaging bags, the width of the long plastic packaging bag is used as the horizontal boundary, and several independent detection segments are divided according to fixed segment lengths along the movement direction of the production line, such as Figure 3 As shown in the figure, 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. Furthermore, based on the camera's shooting frame rate f, the acquisition time interval for each frame image can be obtained as t = 1 / f. Combined 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 obtained as:
[0077]
[0078] Where L is the segment length; k is the segmentation coefficient (usually 2 to 4); d is the distance the long plastic packaging bag moves on the production line during the acquisition time interval; v is the moving speed of the production line; and f is the camera frame rate.
[0079] S300: Based on the continuous frame images, analyze the shrinkage degree and the area ratio of the reflective area of the independent detection segment to obtain the wrinkle influence degree of the independent detection segment, and then determine the qualified frame image of the independent detection segment.
[0080] During the production process of long plastic packaging bags, conveyors at both ends continuously apply force to the bags, propelling them along the production line. However, this force can easily cause wrinkles on the bags, which can be misidentified as quality defects, affecting the accuracy of inspection results. To avoid such misidentification, the image frame with the least longitudinal stretch and wrinkles is selected from multiple frames to minimize interference caused by bag deformation. Starting from the first frame, the position and morphological changes of each independent inspection segment from the time it enters the camera's field of view to the time it leaves the camera's field of view are recorded, and the wrinkle condition is analyzed. Wrinkles cause localized material stretching during movement along the production line, which manifests as lateral contraction (e.g., wrinkles at the edges squeeze the width of the middle section, narrowing it). Furthermore, the tension at both ends of the production line causes wrinkles to form strip-like protrusions along the surface of the long plastic packaging bags, enhancing localized reflectivity. Therefore, in wrinkle detection, the degree of shrinkage along the width of the long plastic packaging bags and the proportion of reflective areas are used as quantitative indicators of wrinkle severity.
[0081] Based on the above analysis, in an embodiment of the present invention, based on continuous frame images, the shrinkage degree and the area ratio of the reflective area of the independent detection segment are analyzed to obtain the wrinkle influence degree of the independent detection segment, and then determine the qualified frame image of the independent detection segment.
[0082] Based on the continuous frame images, the contraction degree of the independent detection segment is analyzed, further including:
[0083] First, obtain the standard width of the long plastic packaging bag, that is, the width of the long plastic packaging bag in a flawless state, which can be measured before the long plastic packaging bag enters the production line.
[0084] Then, 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. Specifically:
[0085] In the continuous frame images, the four vertices of the independent detection segment are marked. Each independent detection segment is regarded as a rectangular area composed of these four vertices. Therefore, the fitting rectangle of the independent detection segment is obtained, and the theoretical perimeter of the fitting rectangle is calculated as: (segment length + long plastic packaging bag width) × 2.
[0086] Since plastic packaging bags will reserve cutting lines or segmentation reserved areas before formal cutting, each independent detection segment should contain 4 main edges (upper and lower edges, left and right edges), and the independent detection segment containing cutting lines or segmentation reserved areas will additionally detect 1 to 2 straight lines (or simple broken lines) perpendicular to or parallel to the main edges, and the position is fixed; these segmentation reserved areas may interfere with the judgment of wrinkles, so before formally analyzing the wrinkle situation, the independent detection segment containing cutting lines or segmentation reserved areas must be processed and the corresponding areas must be eliminated; therefore, the main edge of the independent detection segment is extracted. The specific implementation method is as follows: the outer contour of the independent detection segment is extracted through OpenCV.findContours, and an error range is set (the value can be 5%). The outer contour whose error between the perimeter of the outer contour and the theoretical perimeter is within the error range is retained and marked as the main edge of the independent detection segment. The remaining straight lines are regarded as interference lines, and the interference line area is covered and eliminated by masking, leaving only the core area surrounded by the main edge.
[0087] Through edge detection, the top edge pixel coordinates (x top ,y top ) and the bottom edge pixel coordinates (x bottom ,y bottom ), calculate the local width of the independent detection segment as W current =|y top ―y bottom |.
[0088] Finally, the shrinkage degree of the independent detection segment is obtained based on the standard width and the local width. The shrinkage degree calculation formula of the independent detection segment is:
[0089]
[0090] Where C represents the shrinkage degree of the independent detection segment; W std Indicates the standard width of a long plastic packaging bag in a flawless state; minW current Represents the minimum value among all local widths of independent detection segments.
[0091] Based on continuous frame images, the reflective area ratio of the independent detection segment is analyzed. The specific implementation method is as follows:
[0092] The continuous frame images are converted to HSV space and the brightness channel V is extracted; for the brightness channel, the segmentation threshold is obtained using the Otsu algorithm, and the reflective area of the independent detection segment is obtained by binarization. In addition, after obtaining the reflective area of the independent detection segment, it is also included: since the production line moves in the horizontal direction, the reflective area is required to be a horizontal strip, so it is necessary to remove the interfering reflective area from all the obtained reflective areas. Specifically, the standard deviation σ of the x-axis (production line movement direction) coordinates of all pixels in the reflective area is calculated.x and the standard deviation of the y-axis (vertical to the direction of movement of the production line) σ y , requiring σ x >2σ y (The lateral discreteness is significantly greater than the longitudinal discreteness, ensuring that the area extends along the x-axis). At the same time, the minimum circumscribed rectangle angle θ of the reflective area (the angle between the side of the minimum circumscribed rectangle along the moving direction of the production line and the x-axis) is retained within the range of ±15° (ensuring that the reflective area is basically parallel to the moving direction of the production line).
[0093] Then, obtain the reflective area (all reflective areas after removing the interfering reflective areas in the independent detection segment) and the area of the independent detection segment, and calculate the area ratio of the reflective area in the independent detection segment. The area ratio of the reflective area in the independent detection segment is obtained as follows:
[0094]
[0095] Where B represents the reflective area ratio of the independent detection segment; S 反光区域 It represents the sum of the areas of all reflective areas in the independent detection segment after removing the interfering reflective areas; S 独立检测段 Represents the area of an independent detection segment.
[0096] According to the shrinkage degree of the independent detection segment and the proportion of the reflective area, the wrinkle influence degree of the independent detection segment is obtained as follows:
[0097] Score=α·C+β·B
[0098] Where Score represents the influence of wrinkles in the independent detection segment; α represents the weight of the shrinkage degree of the independent detection segment (value range [0.3, 0.4]); β represents the weight of the reflective area ratio of the independent detection segment (value range [0.6, 0.7]), and α + B = 1.
[0099] The larger the Score value, the more affected the current independent detection segment is by the fold.
[0100] According to 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 of the independent detection segment from entering the shooting area to leaving the shooting area are recorded, the degree of wrinkle influence of the independent detection segment in each frame image 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 set a reference threshold and obtain a reference segment according to the degree of influence of the wrinkles.
[0102] A flawless control plastic packaging segment represents an ideal state, meeting quality requirements. By comparing the individual test segment to the reference segment, it is possible to clearly determine whether the individual test segment is defective. However, in a real production environment, it may not be possible to obtain reference segments in advance. Therefore, the present invention adopts a dynamic initialization strategy. Starting from the first frame of 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 an embodiment of the present invention, a reference threshold is dynamically set, and a reference segment is obtained according to the degree of wrinkle influence. Specific implementation methods are as follows:
[0104] After the production line is started, in order to quickly establish a reliable reference standard, the width shrinkage caused by tension at both ends of the plastic packaging bag's independent inspection section is tested. Considering that the thickness on both sides of the cut line reserved before splitting is usually greater than the main area of the plastic packaging bag, this thickness difference will lead to different shrinkage levels in the area near the cut line (thick area, usually located on both sides of the cut line, with a width determined by the product design) and the main area (thin area). That is, the thick area has low ductility and shrinks less, while the thin area has thinner material and high ductility and shrinks relatively more. Therefore, initial reference thresholds are set separately 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, if there is a cut line or a split reserved area, the area on both sides of the cut line (the width range is determined by the actual reserved width of the plastic packaging bag's cut line) or the split reserved area is the thick area, and the rest of the area is the thin area. The wrinkle influence degree of the first independent detection segment that meets the threshold screening is taken 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 thin area initial reference threshold and the thick area initial reference threshold.
[0105] Subsequently, the subsequent independent detection segments are tested to determine whether the wrinkle influence degree of the independent detection segment is less than or equal to the initial reference threshold; if so, the independent detection segment is included in the reference segment library; and the mean wrinkle influence degree of all independent detection segments in the reference segment library + k times the standard deviation (the value of 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] After the reference segment library has accumulated K (K can be 5 to 10) independent detection segments, all independent detection segments in the reference segment library are sorted from largest to smallest by score value. Each new independent detection segment in the reference segment library is then compared with the independent detection segment with the highest wrinkle impact (score value) in the reference segment library. The independent detection segments with the lowest wrinkle impact (score value) are retained in the reference segment library. This mechanism continuously updates the reference segment library until all independent detection segments are tested.
[0107] The independent detection segment corresponding to the minimum value of the wrinkle influence degree (Score value) in the reference segment library is selected in real time as the reference segment.
[0108] S500: Based on the qualified frame image of the independent detection segment, the grayscale value difference between the pixel points in the detection segment and the reference segment is analyzed, the defective pixel points are screened, and the defective area is obtained.
[0109] Based on the qualified frame image of the independent detection segment, the gray value difference between the pixel points in the detection segment and the reference segment is analyzed to filter the defective pixels and obtain the defective area.
[0110] In order to locate the defective area more accurately, a coordinate system is established in each segment to be inspected and the reference segment to perform image registration. Specifically: based on the qualified frame images of the segment to be inspected and the reference segment, the upper left corner of each segment to be inspected or the reference segment is taken as the origin, the x-axis is along the length direction of the plastic packaging bag, and the y-axis is along the width direction of the plastic packaging bag, such as Figure 4 As shown, ensure that the coordinate system directions and scales of all segments to be detected and reference segments are consistent.
[0111] Based on the coordinate system, the segment to be detected is transformed into the coordinate system of the reference segment to complete the image alignment. Specifically, the edge corner points (such as Harris corner points) of the reference segment and the segment to be detected are extracted, the translation amount (Δx, Δy) is calculated by matching the feature points, and the segment to be detected is transformed into the coordinate system of the reference segment.
[0112] Based on the aligned image, the grayscale value difference between the corresponding pixel points in all the segments to be detected and the reference segment is calculated as:
[0113] D i (x,y)=|I i检测 (x,y)―I i参照 (x,y)|
[0114] Where D i (x, y) represents the grayscale value difference between the i-th pixel in the segment to be detected and the reference segment; (x, y) represents the coordinates of the i-th pixel in the coordinate system; I 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] According to the mean and standard deviation of the grayscale values of all pixels in the reference segment, the grayscale value difference threshold is set as:
[0116] T=μ+kσ
[0117] Where T is the grayscale value difference threshold; μ and σ are the mean and standard deviation of the grayscale values of all pixels in the reference segment, respectively; k is the fluctuation coefficient. The larger k is, the greater the grayscale difference fluctuation in the normal area is allowed (the higher the error tolerance), and the less likely it is to be misjudged (usually 2 to 3).
[0118] Pixels whose grayscale value difference in the segment to be detected is greater than the grayscale value difference threshold are marked as defective pixels.
[0119] Through connected domain analysis, such as 8-neighborhood connection, continuous defective pixels are merged into suspected defective areas; when the number of defective pixels in the suspected defective area is greater than or equal to N, the value of N can be 5 to 15, which is determined according to the resolution of the camera, the suspected defective area is determined to be a defective area, such as Figure 5 As shown in the figure; if the number of defective pixels in the suspected defect area is less than N, it is considered as a noise defect area.
[0120] Obtaining the defect area, and then also including: performing connected domain analysis on the defect area of the independent detection segment and the defect areas of the adjacent independent detection segments before and after, such as 8-neighborhood connection, merging continuous defect areas into continuous defect areas, such as Figure 5 The defect area of a single independent detection segment or the continuous defect area merged from multiple adjacent (greater than or equal to 2) independent detection segments is located.
[0121] S600: Trace production process faults based on the location distribution and collective characteristics of defective areas.
[0122] Simple production process fault tracing can be performed based on the location distribution and collective 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 cutting and slitting. It is necessary to check the alignment accuracy of the slitting knife and the usage time of the blade.
[0125] Functional area defects (such as the sealing line, heat-sealing area, and other fixed coordinate ranges) directly affect the sealing of the package. It is important to check whether the heat-sealing temperature is within the standard range and whether there is any foreign matter 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 processes. 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 plastic packaging bag defect visual inspection system.
[0128] See also Figure 6 , which shows the basic composition of a plastic packaging bag defect visual inspection system provided by one embodiment of the present invention.
[0129] like Figure 6 As shown, a plastic packaging bag defect visual inspection system includes: a memory 10 and a processor 20, wherein:
[0130] Memory 10, for storing program code;
[0131] The processor 20 is used to read the program code stored in the memory 10, and execute the following steps: obtaining the moving speed of the production line, setting the shooting frame rate of the camera, and collecting continuous frame images of the long plastic packaging bag moving along the production line; setting the segment length based on the shooting frame rate and the moving speed, and dividing the long plastic packaging bag into a number of independent detection segments; analyzing the shrinkage degree and the proportion of the reflective area of the independent detection segment based on the continuous frame images, obtaining the degree of wrinkle influence of the independent detection segment, and then determining the qualified frame image of the independent detection segment; dynamically setting the reference threshold, and obtaining the reference segment according to the degree of wrinkle influence; analyzing the grayscale value difference of the pixel points in the to-be-detected segment and the reference segment based on the qualified frame image of the independent detection segment, screening the defective pixel points, and obtaining the defective area; tracing the production link fault according to the position distribution and collective characteristics of the defective area.
[0132] Furthermore, the processor 20 includes an image acquisition module 21, a segmentation module 22, a wrinkle impact analysis module 23, a reference segment acquisition module 24, a defect area acquisition module 25, and a production process fault tracing module 26.
[0133] The image acquisition module 21 is used to obtain the moving speed of the production line, set the shooting frame rate of the camera, and collect continuous frame images of the long plastic packaging bag moving along the production line;
[0134] The segmentation module 22 is used to set the segment length based on the shooting frame rate and the moving speed, and divide the long plastic packaging bag into a number of independent detection segments;
[0135] The wrinkle impact analysis module 23 is used to analyze the shrinkage degree and the reflective area ratio of the independent detection segment based on the continuous frame images, obtain the wrinkle impact degree of the independent detection segment, and then determine the qualified frame image of the independent detection segment;
[0136] The reference segment acquisition module 24 is used to dynamically set a reference threshold and obtain a reference segment according to the degree of wrinkle influence;
[0137] The defect area acquisition module 25 is used to analyze the grayscale value difference between the pixels in the to-be-detected segment and the reference segment based on the qualified frame image of the independent detection segment, filter the defective pixels, and obtain the defect area;
[0138] The production link fault tracing module 26 is used to trace the production link faults based on the location distribution and collection characteristics of the defective areas.
[0139] It should be noted that the order in which the embodiments of the present invention are described above is for illustrative purposes only and does not necessarily represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain 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, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
Claims
1. A method for visually detecting defects in plastic packaging bags, characterized in that: The method comprises: Obtain the moving speed of the production line, set the camera's frame rate, and capture continuous frame images of long plastic packaging bags moving along the production line; Based on the shooting frame rate and the moving speed, a segment length is set to divide the long plastic packaging bag into a plurality of independent detection segments; Based on the continuous frame images, analyzing the shrinkage degree and the area ratio of the reflective region of the independent detection segment to obtain the wrinkle influence degree of the independent detection segment, and then determining a qualified frame image of the independent detection segment; Dynamically setting a reference threshold to obtain a reference segment according to the degree of influence of the wrinkles; Based on the qualified frame image of the independent detection segment, analyzing the grayscale value difference between the pixel points in the segment to be detected and the reference segment, screening the defective pixel points, and obtaining the defective area; According to the location distribution and collective characteristics of the defective areas, production process fault tracing is carried out.
2. The method for visually inspecting defects in plastic packaging bags according to claim 1, wherein: Set the camera's shooting frame rate, including: Get the vertical length of the camera's field of view and the camera's vertical pixel resolution; The shooting frame rate of the camera is set according to the moving speed of the production line, the longitudinal length and the longitudinal pixel resolution.
3. The method for visually inspecting defects in plastic packaging bags according to claim 1, wherein: Analyzing the contraction degree of the independent detection segment based on the continuous frame images includes: Get the standard width of long plastic packaging bags; Extracting the main edge of the independent detection segment based on the continuous frame images, obtaining the coordinates of the main edge, and calculating the local width of the independent detection segment; The shrinkage degree of the independent detection segment is obtained according to the standard width and the local width.
4. The method for visually inspecting defects in plastic packaging bags according to claim 3, wherein: Extracting the main edge of the independent detection segment based on the continuous frame images includes: Based on the continuous frame images, marking four vertices of the independent detection segment, obtaining a fitting rectangle of the independent detection segment, and calculating a theoretical perimeter of the fitting rectangle; The outer contour of the independent detection segment is extracted through OpenCV.findContours, and an error range is set. The outer contour whose error between the perimeter of the outer contour and the theoretical perimeter is within the error range is retained and marked as the main edge of the independent detection segment. The remaining straight lines are regarded as interference lines, and the interference line area is covered and eliminated by masking, so that only the core area surrounded by the main edge is retained.
5. The method for visually inspecting defects in plastic packaging bags according to claim 1, wherein: Analyzing the reflective area ratio of the independent detection segment based on the continuous frame images includes: Convert the continuous frame images into HSV space and extract the brightness channel; For the brightness channel, the Otsu algorithm is used to obtain a segmentation threshold, and binarization is performed to obtain the reflective area of the independent detection segment; 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 visually inspecting defects in plastic packaging bags according to claim 1, wherein: Dynamically set the reference threshold and obtain the reference segment according to the degree of influence of the wrinkles, including: Set the initial reference threshold; determining whether the wrinkle influence degree of the independent detection segment is less than or equal to the initial reference threshold; If yes, the independent detection segment is included in the reference segment library; Calculating the average of the wrinkle influence degrees of all independent detection segments in the reference segment library to obtain a new reference threshold, and using the new reference threshold to determine whether to include the independent detection segment in the reference segment library; When K independent detection segments are accumulated in the reference segment library, each new independent detection segment added to the reference segment library is compared with the independent detection segment with the highest wrinkle influence in the reference segment library, and the independent detection segment with the lowest wrinkle influence is retained in the reference segment library; Continuously update the reference segment library until all independent test segments are tested; The independent detection segment corresponding to the minimum value of the wrinkle influence degree in the reference segment library is selected in real time as the reference segment.
7. The method for visually inspecting defects in plastic packaging bags according to claim 1, wherein: Based on the qualified frame image of the independent detection segment, analyzing the grayscale value difference between the pixel points in the detection segment and the reference segment, screening the defective pixel points, and obtaining the defective area, including: Based on the qualified frame image, establishing a coordinate system of the segment to be detected and the reference segment; Based on the coordinate system, the segment to be detected is transformed into the coordinate system of the reference segment to complete image alignment; Based on the aligned image, calculating the grayscale value differences of the corresponding pixel points in all the segments to be detected and the reference segments; Setting a grayscale value difference threshold according to the mean and standard deviation of the grayscale values of all pixels in the reference segment; Marking pixels in the segment to be detected whose grayscale value difference is greater than the grayscale value difference threshold as defective pixels; Through connected domain analysis, continuous defective pixels are merged into suspected defective areas; When the number of defective pixels in the suspected defect area is greater than or equal to N, the suspected defect area is determined to be a defect area.
8. The method for visually inspecting defects in plastic packaging bags according to claim 1, wherein: Get the blemish area, and then also include: Connected domain analysis is performed on the defect areas of the independent detection segment and its adjacent independent detection segments before and after it, and continuous defect areas are merged into a continuous defect area.
9. A plastic packaging bag defect visual inspection system, characterized in that: The system comprises: a memory and a processor, wherein: The memory is used to store program code; The processor is configured to read the program code stored in the memory and execute the method according to any one of claims 1 to 8.
10. The plastic packaging bag defect visual inspection system 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 collect continuous frame images of the long plastic packaging bags moving along the production line; A segmentation module, configured to set a segment length based on the shooting frame rate and the moving speed, and divide the long plastic packaging bag into a plurality of independent detection segments; a wrinkle impact analysis module, configured to analyze the shrinkage degree and the reflective area ratio of the independent detection segment based on the continuous frame images, to obtain the wrinkle impact degree of the independent detection segment, and further determine a qualified frame image of the independent detection segment; A reference segment acquisition module is used to dynamically set a reference threshold and obtain a reference segment according to the degree of influence of the wrinkles; a defective area acquisition module, configured to analyze the grayscale value difference between pixels in the segment to be inspected and the reference segment based on the qualified frame image of the independent inspection segment, screen defective pixels, and obtain the defective area; The production link fault tracing module is used to trace the production link faults according to the location distribution and collective 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
Film adjusting method based on machine vision
CN115009905A
Packaging bag defect detection method and device based on machine vision, terminal and medium
CN117764963A
Thermal shrinkage film defect detection method, device and system and electronic equipment
CN118162380A