Printing defect detection method and detection device for cylindrical bottle body
Through the detection method of combining linear array cameras and combined light sources, combined with normalized cross correlation and perceived hash similarity comparison, the versatility and accuracy of defect detection of cylindrical bottle printing patterns in the prior art is solved, and efficient automated detection and defect removal are achieved.
Patent Information
- Application Number
- CN202510658679.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-08-29
AI Technical Summary
The existing detection systems are difficult to compatible with complex printing pattern defects in cylindrical bottle bodies of different specifications, and there are problems of image distortion and insufficient detection accuracy.
A linear array camera is used to conduct continuous mapping under combined light source illumination, and aligned points are determined by combining normalized cross-correlation search and linear regression model, affine transformation correction is performed, and printing defects are identified by perceived hash similarity comparison and morphological analysis, and high-precision detection is achieved with an automated feeding device.
It realizes high-precision printing defect detection of cylindrical bottle bodies of different specifications, reduces equipment development costs, improves detection accuracy and production efficiency, and can identify multiple printing defects.
Smart Images

Figure CN120563442A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image matching, and in particular to a method and device for detecting printing defects of cylindrical bottles. Background Art
[0002] Cylindrical beverage bottles are commonly transported and printed using high-speed automated processes in modern beverage production lines. The integrity and clarity of the printed pattern are directly related to the product's appearance, quality, and brand image. Existing inspection systems primarily focus on rough inspections of the bottle's contour integrity or the presence of foreign matter. A universal, high-precision solution for inspecting printed pattern defects has yet to be established.
[0003] Existing techniques use two cameras, front and back, and a combined light source and backlight to inspect empty beer bottles for surface stains and foreign matter. However, this method cannot detect defects in complex printed patterns on bottles and is prone to image edge distortion and detection blind spots when processing curved bottles. Another method uses a rotating platform and multifunctional inspection components to inspect the shape, integrity, and foreign matter of vials. However, due to the small size and simple patterns of vials, this solution lacks the ability to detect complex textures and high-resolution printed patterns, making it less versatile.
[0004] In summary, existing inspection solutions suffer from the following shortcomings: Most systems focus solely on bottle shape or stains and foreign matter, making them inadequate for the diverse and complex nature of printed pattern defects. Existing algorithms fail to account for image distortion caused by cylindrical bottle rotation, light sources, and acquisition systems, resulting in reduced inspection accuracy. Each solution is highly customized for specific bottle shapes or single defect types, resulting in limited versatility and long development cycles. These shortcomings urgently require a universal solution that can accommodate cylindrical bottles of varying sizes and provide high-precision, real-time inspection of printed patterns. Summary of the Invention
[0005] The purpose of the present invention is to provide a universal detection device and method that is compatible with cylindrical bottles of different specifications, can perform high-precision automatic detection of printed patterns thereon, and can realize online rejection of defective products.
[0006] The technical solution of the present invention is to provide a method for detecting printing defects on cylindrical bottles, the method comprising:
[0007] S1. Use a line array camera to continuously capture images of the rotating cylindrical bottle under the illumination of a combined light source, acquiring images of the bottle body and bottleneck area respectively. The captured images cover more than a complete inspection cycle.
[0008] S2. Select areas with clear outlines and no duplication within the same cycle from the collected image as positioning points, perform a normalized cross-correlation search on the collected image to determine the positions of the positioning points, use the original image width as the cropping width, and determine the cropping height based on the distance between any two positioning points. Use the middle positioning point as the cropping center, and crop one of the complete cycle images as the detection template image;
[0009] S3. Fit all the positioning points to a linear function using a linear regression model, and finally calculate the affine transformation matrix of all the positioning points to the detection template image, perform affine transformation on all images, and crop the transformed images according to the template image area to obtain all cropped images within one cycle;
[0010] S4, using the perceptual hash similarity comparison algorithm to select the best image collection period for all cropped images;
[0011] S5, correcting the vertical stretching distortion of all cropped images;
[0012] S6. Performing image difference between the processed inspection image and the template image to obtain a difference image. Grayscale region segmentation is performed on the difference image based on pre-set defect detection areas, contrast, and area thresholds. Connected region features are extracted and analyzed using morphological methods for the segmented areas. The area and aspect ratio parameters of the defective areas are calculated to determine the presence and severity of printing defects.
[0013] S7. The image processing system outputs judgment information based on the defect detection results. When the detection results show the existence of printing defects, the control signal drives the waste ejection device to start and automatically remove the defective products from the production line; otherwise, qualified products are transported to the next process in sequence.
[0014] In any of the above technical solutions, further, the calculation formula of the normalized cross-correlation algorithm in step S2 is as follows:
[0015]
[0016] Among them, NCC is the dot product similarity of the overlapping area of the two images in space, f(x,y) is the pixel value of the image to be detected at (x,y), r(x,y) is the pixel value of the template image at (x,y), m and n represent the calculation window size, μ f 、μ r Represent the window means of the image to be detected and the reference template image respectively.
[0017] In any of the above technical solutions, further, step S3 specifically includes:
[0018] S31. Fit all the positioning points using a linear regression model, and the calculation formula is as follows:
[0019] y=kx+b;
[0020] Where k is the slope and b is the intercept;
[0021] S32, after initially generating the initial values of the linear function coefficients, the objective function E(k * ,b * ), as shown below:
[0022]
[0023] Solve for the parameter k that minimizes the function * ,b * as follows:
[0024]
[0025] in, is the input variable x i The mean of , n is the number of positioning points;
[0026] S33. Calculate the residual for each positioning point:
[0027] e i =y i -(kx i +b);
[0028] Among them, e i is the residual of the i-th point, define a residual threshold ∈, and filter out the residuals that satisfy |e i |>∈, retain the rest of the points, iterate the above steps 20 times until the residual screening result no longer changes, obtain the linear fitting function of the coordinate points, and filter out the erroneous coordinates with large deviations;
[0029] S34. Sort the positioning points vertically from small to large, calculate the interval between each two positioning points, and the Y-axis coordinates after sorting are expressed as follows:
[0030] Y={y1,y2,y3,...,y n};
[0031] Calculate the translation affine transformation matrix using the sorted i-th location and the i-th location on the template. Calculate the stretching affine transformation matrix using the ratio of the interval between the sorted i+1-th location and the i-th location to the interval between the i+1-th location and the i-th location on the template. Set the reference point of the stretching affine transformation to the coordinates of the i-th location.
[0032] S35. Repeat the above operation to calculate the affine transformation matrix of all points, perform affine transformation on the image, and crop the transformed image according to the template image area to obtain all cropped images within a cycle.
[0033] In any of the above technical solutions, further, in step S34, the translation affine transformation matrix is calculated from any two corresponding positioning points;
[0034] The stretching affine transformation matrix is calculated by the ratio of the distance between adjacent positioning points and the interval between corresponding positioning points in the template, and is based on the first positioning point.
[0035] In any of the above technical solutions, further, the process of selecting the optimal image acquisition period using the perceptual hash similarity comparison algorithm in step S4 includes:
[0036] S41, uniformly scaling the template image and all cropped images to 32×32 pixels, and converting the multi-channel image into a single-channel grayscale image;
[0037] S42. Perform a two-dimensional discrete cosine transform on the grayscale image. The formula is as follows:
[0038]
[0039] Where f(x,y) is an M×N digital image matrix; F(u,v) is the result of a two-dimensional discrete transformation; C(u) is a piecewise function, and C(v) is similar. The expressions are as follows:
[0040]
[0041] S43, selecting the 8×8 matrix in the upper left corner from the two-dimensional transformation result, and calculating the pixel mean of the selected area;
[0042] S44. Compare each coefficient in the 8×8 matrix with the mean. If the coefficient is greater than or equal to the mean, the coefficient is recorded as 1; if it is less than the mean, the coefficient is recorded as 0, thereby obtaining a binary hash table.
[0043] S45. Calculate the Hamming distance between each cropped image and the hash table corresponding to the template image. The calculation method is to compare the bits in the vector in turn to see if they are the same. If they are different, the Hamming distance is increased by 1. The Hamming distance calculation formula is as follows:
[0044]
[0045] Where Dis is the Hamming distance, N is the length of the hash table, and X 1i is the value of the first hash table at position i; the smaller the Hamming distance Dis, the higher the similarity between the two images;
[0046] S46. Select the cropped image with the smallest Hamming distance as the optimal image collection period image.
[0047] In any of the above technical solutions, further, step S5 only performs correction in the vertical direction, that is, the Y direction, and the specific correction process includes:
[0048] S51, extracting the edge contour of the template image using an edge extraction algorithm;
[0049] S52, selecting positions with rich contour information in the template image at regular intervals as positioning points;
[0050] S53. Search for the positioning points corresponding to the template image in the image to be detected, use the two sets of positioning points as input, and construct a thin plate spline transformation model only for the vertical direction. The formula is as follows:
[0051]
[0052] Among them, f y (0,y i ) is the thin plate spline function in the Y direction, y i and y′ i are the y coordinates of the i-th point in the template image and the detection image, ω i is the transformation coefficient to be solved, It is a radial basis function kernel based on the distance between the anchor points;
[0053] In any of the above technical solutions, further, S54, minimizing the sum of squares of the Y coordinate errors of all positioning points before and after the transformation is used as the objective function E:
[0054]
[0055] S55. Use the least squares method to solve the optimal transformation coefficient, and substitute the coefficient into the improved thin plate spline transformation formula to perform local stretching correction on the detection image in the Y direction while keeping the X coordinate unchanged to achieve high-precision alignment with the template image.
[0056] Also provided is a detection device for detecting printing defects on cylindrical bottles using the method described in any of the above technical solutions, the device comprising: a feed belt 1, an input plum blossom plate 2, an input curved baffle track 3, a bottle placement tray 4, a feed turntable 5, a combined light source 6, a camera 7, an output plum blossom plate 8, a feed belt 9, a waste ejection device 10, an output curved baffle track 11, and an image processing system 12;
[0057] The automated inspection process is achieved through mechanical transmission and signal linkage between various components. The feed belt 1 first continuously transports the cylindrical bottles to be inspected from the production line to the input plum blossom tray 2. The input plum blossom tray 2, assisted by the input curved baffle track 3, sequentially feeds the cylindrical bottles into different bottle placement trays 4 at predetermined fixed intervals.
[0058] The bottle placing tray 4 includes a tray base 43, a nylon pressing head 41, and a tray gear 44. During the bottle feeding process, the air pressure device drives the nylon pressing head 41 to firmly press the bottle mouth against the tray base 43. The tray gear 44 is fixed to the bottom of the tray base 43 and meshes with the drive belt of the feed turntable 5. The bottle placing tray 4 rotates under the drive belt of the feed turntable 5 through the tray gear 44 and revolves together with the feed turntable 5.
[0059] When the bottle tray 4 passes in front of the camera 7, the feeding turntable 5 triggers the image acquisition signal, prompting the camera 7 to continuously capture images of the bottle body and neck in the detection area;
[0060] The combined light source 6 evenly illuminates the cylindrical bottle, and the combined light source 6 includes a planar array light source 61 and a tunnel light source 62;
[0061] The camera 7 includes a first line array camera 71 and a second line array camera 72. The first line array camera 71 is tilted 15 degrees relative to the horizontal direction to shoot. The camera 7 uses line array technology to capture images of the bottle body and bottleneck area. The captured images should cover more than a complete image cycle.
[0062] The cylindrical bottle body is taken out by the output plum blossom disk 8 and finally enters the conveyor belt 9 with the assistance of the output arc baffle track 11; the image obtained by image acquisition is sent to the image processing system 12 through the high-speed data transmission interface; the image processing system 12 outputs the detection result to the ejection device 10. When the detection system determines that a bottle is defective, the ejection device 10 automatically starts after receiving the signal, uses air pressure to open the valve and blows air, and the defective bottle is removed from the assembly line.
[0063] The beneficial effects of the present invention are:
[0064] The present invention utilizes a linked structure consisting of a feed belt, plum blossom plate, bottle placement tray, and feed turntable to achieve fully automated transfer of cylindrical bottles, from feeding, positioning, rotational imaging, to discharging. This system is suitable for cylindrical bottles of varying sizes, offering high versatility and reducing equipment development and replacement costs. The bottle placement tray structure, with its nylon pressure head and elastic tray base, ensures stability and coaxiality during rotation, improving image consistency and quality. A combined light source (tunnel light and surface light) is combined with a linear array camera to capture images of the bottle body and bottleneck. This complete cycle capture provides high precision and robust interference resistance, providing a high-quality data foundation for subsequent image processing.
[0065] In terms of image processing, this invention uses a normalized cross-correlation algorithm to detect positioning points, combined with a linear regression model for screening, ensuring the accuracy and robustness of the positioning results. Using an affine transformation matrix to periodize and initially correct the image effectively corrects vertical stretching distortion caused by uneven bottle rotation and avoids false detections caused by image alignment errors.
[0066] The present invention further proposes an improved thin plate spline transformation model, which only performs local stretching correction on the vertical direction of the image, effectively simplifying the amount of calculation, improving the operation efficiency, and ensuring that the corrected image is highly aligned with the template image, thereby improving the detection accuracy.
[0067] The present invention adopts a perceptual hash similarity comparison algorithm to screen each periodic image to ensure that the most representative and least distorted periodic image is selected for subsequent detection. The detection process locates and extracts features of printing defects through image difference combined with morphological analysis methods. The detection has high accuracy and fast speed, and can identify various defects including text breakage, pattern missing, color cast and blur. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] The advantages of the above and additional aspects of the present invention will become apparent and readily understood from the following description of the embodiments with reference to the accompanying drawings, in which:
[0069] Figure 1 is a flow chart of a method for detecting printing defects on a cylindrical bottle according to one embodiment of the present invention;
[0070] Figure 2 is a simplified structural diagram of a printing defect detection device for cylindrical bottles according to one embodiment of the present invention;
[0071] Figure 3 is a structural diagram of a printing defect detection device for cylindrical bottles according to one embodiment of the present invention;
[0072] Figure 4 2 is a schematic structural diagram of a bottle placing tray of a device for detecting printing defects on cylindrical bottles according to an embodiment of the present invention;
[0073] Figure 5 2 is a schematic diagram of a combined light source and camera structure of a printing defect detection device for cylindrical bottles according to an embodiment of the present invention;
[0074] Figure 6 1 is a flow chart of a positioning and stretching algorithm for a method for detecting printing defects on cylindrical bottles according to an embodiment of the present invention;
[0075] Figure 7is a similarity comparison flow chart of a perceptual hash algorithm for a method for detecting printing defects on cylindrical bottles according to an embodiment of the present invention;
[0076] Figure 8 The present invention is a flowchart of a method for detecting printing defects of cylindrical bottles according to an embodiment of the present invention, wherein an improved thin plate spline transformation model is used to correct local tensile deformation.
[0077] Among them, 1-feeding belt, 2-input plum blossom disk, 3-input curved baffle track, 4-bottle tray, 5-feeding turntable, 6-combined light source, 7-camera, 8-output plum blossom disk, 9-feeding belt, 10-waste kicking device, 11-output curved baffle track, 12-image processing system, 41-nylon pressure head, 42-cylindrical bottle body, 43-tray base, 44-tray gear, 61-area array light source, 62-tunnel light source, 71-first line array camera, 72-second line array camera. DETAILED DESCRIPTION
[0078] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present invention and the features therein can be combined with each other without conflict.
[0079] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the scope of protection of the present invention is not limited to the specific embodiments disclosed below.
[0080] like Figure 2 and Figure 3 As shown, this embodiment provides a printing defect detection device for cylindrical bottles, which includes: a feeding belt 1, an input plum blossom plate 2, an input arc baffle track 3, a bottle placement tray 4, a feeding turntable 5, a combined light source 6, a camera 7, an output plum blossom plate 8, a feeding belt 9, a waste kicking device 10, an output arc baffle track 11 and an image processing system 12.
[0081] The above components achieve an automated inspection process through mechanical transmission and signal linkage. The feed belt 1 first continuously transports the cylindrical bottles to be inspected from the production line to the input plum blossom tray 2. The input plum blossom tray 2, assisted by the input curved baffle track 3, sequentially delivers the cylindrical bottles to different bottle trays 4 at predetermined fixed intervals.
[0082] The structure of the bottle tray 4 is as follows Figure 4As shown, a tray base 43, a nylon pressing head 41 and a tray gear 44 are provided therein; during the bottle feeding process, the air pressure device drives the nylon pressing head 41 to firmly press the bottle mouth of the cylindrical bottle body 42 against the tray base 43. A spring is installed in the tray base 43. Under the action of the spring, the tray base 43 can be fine-tuned up and down within a certain range to ensure the accurate position of the bottle; the tray gear 44 is fixed to the bottom of the tray base 43 and engages with the driving belt of the feeding turntable 5. The bottle placing tray 4 rotates on its own under the drive of the feeding turntable 5 through the tray gear 44, and revolves together with the feeding turntable 5. When the bottle placing tray 4 passes directly in front of the camera 7, the feeding turntable 5 triggers the image acquisition signal, prompting the camera 7 to continuously acquire images of the bottle body and bottleneck located in the detection area.
[0083] like Figure 5 As shown, to ensure the quality and accuracy of image acquisition, a combined light source 6 is used to uniformly illuminate the cylindrical bottle body during the image acquisition process. The combined light source 6 includes two light sources: an area array light source 61 and a tunnel light source 62. The addition of the combined light source 6 ensures that the image captured by the camera 7 has high contrast and low noise, meeting the requirements of subsequent image processing for detecting subtle printing defects. The camera 7 includes a first line array camera 71 and a second line array camera 72. The first line array camera 71 is tilted 15° relative to the horizontal direction to capture images. The camera 7 uses line array technology to capture images of the bottle body and bottleneck area. The captured images should cover more than a complete image cycle, thereby ensuring that the image information is complete and the imaging error is as small as possible.
[0084] The captured image is sent to the image processing system 12 via a high-speed data transmission interface. A specialized processing module within the image processing system 12 first locates and segments the captured image. The specific method involves selecting clear, non-repeated areas within the image as positioning points and searching for these points using a normalized cross-correlation algorithm. The distance between the two positioning points and a fixed constant are combined to determine the crop height, using the entire original width as the crop width and the center of the crop point. This creates a single periodic image as a test template. The template pre-defines the test area, defect contrast, and area thresholds, providing a standard for subsequent testing.
[0085] Subsequently, the detection process includes searching for positioning points, linear regression fitting to eliminate abnormal positioning points, and using a positioning stretching algorithm to correct and crop periodic images. To overcome vertical image stretching distortion caused by bottle rotation and coaxial deviation between the bottle tray and the feed turntable, this embodiment further adopts an improved thin plate spline transformation model to perform local stretching correction only in the vertical direction of the image. During the correction process, the system first uses an edge extraction algorithm to obtain the template image outline and selects positioning points with rich edge information at predetermined intervals. Then, based on the information of the corresponding positioning points in the detection image, the system uses the least squares method to calculate the optimal stretching transformation coefficient to complete the image distortion correction in the Y direction, while keeping the image coordinates in the X direction unchanged to achieve higher-precision alignment with the template image.
[0086] After image correction is complete, the image processing system 12 uses a perceptual hashing similarity comparison algorithm to evaluate the similarity of the cropped periodic images. This involves first scaling each periodic image to 32×32 pixels and converting it to a single-channel grayscale image. Low-frequency features are then extracted using a two-dimensional discrete cosine transform. The 8×8 matrix in the upper left corner is then selected to generate a binary hash table. Finally, the Hamming distance between each periodic image and the template image is compared, and the image with the smallest Hamming distance is selected as the optimal periodic image. This optimal image is then subjected to image difference processing with the template image to obtain a differential image of the printing defect. Subsequently, morphological methods (such as erosion and dilation) are used to extract features from the connected regions in the differential image, combining the set defect grayscale and area thresholds. The specific parameters of the defective region are calculated, ultimately determining whether the cylindrical bottle has a printing defect.
[0087] The cylindrical bottle body is taken out by the output plum blossom plate 8 and finally enters the conveyor belt 9 with the assistance of the output arc baffle track 11; the detection result is output by the image processing system 12 and transmitted to the ejection device 10. When the detection system determines that a bottle is defective, the ejection device 10 automatically starts after receiving the signal, uses air pressure to open the valve, and removes the defective bottle from the assembly line by blowing air, realizing automated sorting and discharging of the entire assembly line.
[0088] like Figure 1 As shown, the following embodiment provides a detection method based on the above detection device, the method comprising:
[0089] S1. Capture images. Utilize a line array camera 7 under the illumination of a combined light source 6 (including tunnel light and surface light) to continuously capture images of cylindrical bottles rotating on a bottle placement tray 4 and orbiting on a feed turntable 5. Images of the bottle body and bottleneck area are acquired separately. The captured images cover more than one complete inspection cycle.
[0090] S2. Construct a template image and select areas with clear contours and no repetition in the same cycle from the collected image as positioning points. Perform a normalized cross correlation (NCC) search on the collected image to determine the position of the positioning points. The cropping height is determined based on the distance between any two positioning points plus a fixed constant. The original image width is used as the cropping width, and the positioning point in the middle is used as the cropping center. One of the complete cycle images is cropped as the template image for detection.
[0091] The calculation formula of the normalized cross-correlation algorithm (NCC) is as follows:
[0092]
[0093] Among them, NCC is the dot product similarity of the overlapping area of the two images in space, f(x,y) is the pixel value of the image to be detected at (x,y), r(x,y) is the pixel value of the template image at (x,y), m and n represent the calculation window size, μ f 、μ r Represent the window means of the image to be detected and the reference template image respectively.
[0094] S3, such as Figure 6 As shown in the figure, the image to be detected is searched for positioning points, and the linear regression function is used to fit the positioning points. The specific steps are as follows:
[0095] S31. Fit all the positioning points using a linear regression model to a linear function, the formula of which is as follows:
[0096] y=kx+b;
[0097] Where k is the slope and b is the intercept.
[0098] S32, after initially generating the initial values of the linear function coefficients, the objective function E(k * ,b * ), as shown below:
[0099]
[0100] Solve for the parameter k that minimizes the function * ,b * as follows:
[0101]
[0102] in, is the input variable x i The mean of , n is the number of positioning points.
[0103] S33. Calculate the residual for each positioning point:
[0104] e i =y i -(kx i +b);
[0105] Among them, e i is the residual of the i-th point, define a residual threshold ∈, and filter out the residuals that satisfy |e i |>∈, retain the rest of the points, iterate the above steps 20 times until the residual screening result no longer changes, obtain the linear fitting function of the coordinate points, and filter out the erroneous coordinates with large deviations.
[0106] S34. Sort the positioning points vertically from small to large, calculate the interval between each two positioning points, and the Y-axis coordinates after sorting are expressed as follows:
[0107] Y={y1,y2,y3,...,y n};
[0108] The translation affine transformation matrix is calculated using the sorted i-th positioning and the i-th positioning on the template (the translation affine transformation matrix is calculated from any two corresponding positioning points), and the stretching affine transformation matrix is calculated using the ratio of the interval between the sorted i+1-th positioning and the i-th positioning to the interval between the i+1-th positioning and the i-th positioning on the template, and the reference point of the stretching affine transformation is set to the coordinate of the i-th positioning point (the stretching affine transformation matrix is calculated from the ratio of the distance between adjacent positioning points and the interval between corresponding positioning points in the template, and takes the first positioning point as the reference).
[0109] S35. Repeat the above operation to calculate the affine transformation matrix of all points, perform affine transformation on the image, and crop the transformed image according to the template image area to obtain all cropped images within a cycle.
[0110] S4, such as Figure 7 As shown, the cropped image is periodically selected and corrected:
[0111] For each image cropped in step S3, the perceptual hashing similarity comparison algorithm is used to select the optimal image collection period. The specific process is as follows:
[0112] S41. Scale the template image and all cropped images uniformly to 32×32 pixels, and convert the multi-channel image into a single-channel grayscale image.
[0113] S42. Perform a two-dimensional discrete cosine transform on the grayscale image. The formula is as follows:
[0114]
[0115] Where f(x,y) is an M×N digital image matrix; F(u,v) is the result of a two-dimensional discrete transformation; C(u) is a piecewise function, and C(v) is similar. The expressions are as follows:
[0116]
[0117] S43. Select the 8×8 matrix in the upper left corner from the two-dimensional transformation result, and calculate the pixel mean of the selected area.
[0118] S44. Compare each coefficient in the 8×8 matrix with the mean. If the coefficient is greater than or equal to the mean, record the coefficient as 1; if it is less than the mean, record it as 0, thereby obtaining a binary hash table.
[0119] S45. Calculate the Hamming distance between each cropped image and the hash table corresponding to the template image. The calculation method is to compare the bits in the vector in turn to see if they are the same. If they are different, the Hamming distance is increased by 1. The Hamming distance calculation formula is as follows:
[0120]
[0121] Where Dis is the Hamming distance, N is the length of the hash table, and X 1i is the value of the first hash table at position i; the smaller the Hamming distance Dis, the higher the similarity between the two images.
[0122] S46. Select the cropped image with the smallest Hamming distance as the optimal image acquisition cycle image for subsequent defect detection.
[0123] S5, such as Figure 8 As shown, the local stretching distortion correction of the image in the vertical direction is:
[0124] Considering that the cylindrical bottle image mainly experiences stretching distortion in the vertical direction during the image acquisition process, this step only corrects the Y direction (vertical direction).
[0125] S51, using an edge extraction algorithm (such as the Canny algorithm) to extract the edge contour of the template image;
[0126] S52, selecting positions with rich contour information in the template image at regular intervals as positioning points (the contour area or the number of corner points may be referenced);
[0127] S53, searching for the positioning points corresponding to the template image in the image to be detected, taking the two sets of positioning points as input, and constructing a thin plate spline transformation model for the vertical direction only. For a two-dimensional thin plate spline transformation, the commonly used formula is:
[0128]
[0129] Among them, T(x,y) is the target coordinate value of the position point after image transformation, ωi is the transformation coefficient to be solved, y i and y′ i are the y coordinates of the i-th point in the template image and the detection image respectively, It is a radial basis function kernel based on the distance between the positioning points, usually chosen as a thin plate spline function.
[0130] The present invention only corrects the image in the Y direction and improves the thin plate spline transformation formula as follows:
[0131]
[0132] f y (0,y i ) is the thin plate spline function in the Y direction.
[0133] S54, taking the objective function E as the sum of squares of the Y coordinate errors of all positioning points before and after the transformation:
[0134]
[0135] S55. Use the least squares method to solve the optimal transformation coefficient, and substitute the coefficient into the improved thin plate spline transformation formula to perform local stretching correction on the detection image in the Y direction while keeping the X coordinate unchanged to achieve high-precision alignment with the template image.
[0136] S6, Defect Information Detection: Perform image difference between the detection image processed in step S4 or S5 and the template image to obtain a difference image. Based on the pre-set defect detection area, contrast, and area threshold, the difference image is segmented into grayscale regions. Morphological methods (such as erosion and dilation) are used to extract and analyze connected region features in the segmented regions. Parameters such as the area or aspect ratio of the defect area are calculated to determine the presence and severity of printing defects.
[0137] S7, Result Output and Control: Based on the defect detection results obtained in step S6, the image processing system 12 outputs judgment information. If the detection results indicate a printing defect, a control signal activates the reject device 10, automatically removing the defective product from the production line. Otherwise, qualified products are transported to the next process via the output plum blossom tray 8, the output curved baffle track 11, and the conveyor belt 9.
[0138] The printing defect detection method for cylindrical bottles described in this embodiment achieves high-precision and rapid detection of printing defects in complex printed patterns through steps such as image acquisition, template construction, positioning and cropping, perceptual hash similarity comparison, local vertical correction using an improved thin plate spline transformation model, and image difference and morphological processing. At the same time, it is linked with an automatic feeding and defect rejection device to form a complete automated detection process, effectively improving production efficiency and product quality.
[0139] In summary, the present invention proposes a method for detecting printing defects on cylindrical bottles, comprising:
[0140] S1. Use a line array camera to continuously capture images of the rotating cylindrical bottle under the illumination of a combined light source, acquiring images of the bottle body and bottleneck area respectively. The captured images cover more than a complete inspection cycle.
[0141] S2. Select areas with clear outlines and no repetition in the same cycle from the collected images as positioning points, perform normalized cross-correlation search on the collected images, determine the positions of the positioning points, use the original image width as the cropping width, and determine the cropping height based on the distance between any two positioning points. Use the positioning point in the middle as the cropping center, and crop one of the complete cycle images as the template image for detection.
[0142] S3. Fit all positioning points to a linear function using a linear regression model, and finally calculate the affine transformation matrix of all positioning points to the detection template image, perform affine transformation on all images, and crop the transformed images according to the template image area to obtain all cropped images within one cycle.
[0143] S4. Use the perceptual hashing similarity comparison algorithm to select the best image collection period for all cropped images.
[0144] S5. Correct the vertical stretching distortion of all cropped images.
[0145] S6. Perform image difference between the processed detection image and the template image to obtain a difference image. Perform grayscale region segmentation on the difference image based on the pre-set defect detection area, contrast, and area threshold. Use morphological methods to extract and analyze connected region features of the segmented area, calculate the area and aspect ratio parameters of the defect area, and determine the presence and degree of printing defects.
[0146] S7. The image processing system outputs judgment information based on the defect detection results. When the detection results show the existence of printing defects, the control signal drives the waste ejection device to start and automatically remove the defective products from the production line; otherwise, qualified products are transported to the next process in sequence.
[0147] The present invention also proposes a detection device using the above detection method, comprising:
[0148] Feeding belt 1, input plum blossom plate 2, input arc baffle track 3, bottle placement tray 4, feeding turntable 5, combined light source 6, camera 7, output plum blossom plate 8, feeding belt 9, waste kicking device 10, output arc baffle track 11 and image processing system 12.
[0149] The automated inspection process is achieved through mechanical transmission and signal linkage between various components. The feed belt 1 first continuously transports the cylindrical bottles to be inspected from the production line to the input plum blossom tray 2. The input plum blossom tray 2, assisted by the input curved baffle track 3, sequentially delivers the cylindrical bottles to different bottle placement trays 4 at predetermined fixed intervals.
[0150] The bottle placing tray 4 includes a tray base 43, a nylon pressing head 41 and a tray gear 44. During the bottle feeding process, the air pressure device drives the nylon pressing head 41 to firmly press the bottle mouth against the tray base 43. The tray gear 44 is fixed to the bottom of the tray base 43 and engages with the drive belt of the feeding turntable 5. The bottle placing tray 4 rotates on its own under the drive belt of the feeding turntable 5 through the tray gear 44, and revolves together with the feeding turntable 5. When the bottle placing tray 4 passes directly in front of the camera 7, the feeding turntable 5 triggers the image acquisition signal, prompting the camera 7 to continuously capture images of the bottle body and bottleneck located in the detection area.
[0151] The combined light source 6 evenly illuminates the cylindrical bottle, and the combined light source 6 includes a planar array light source 61 and a tunnel light source 62 .
[0152] The camera 7 includes a first line array camera 71 and a second line array camera 72. The first line array camera 71 is tilted 15° relative to the horizontal direction to shoot. The camera 7 relies on line array technology to capture images of the bottle body and bottleneck area. The captured images should cover more than a complete image cycle.
[0153] The cylindrical bottle body is brought out by the output plum blossom disk 8 and finally enters the conveyor belt 9 with the assistance of the output arc baffle track 11; the image obtained by image acquisition is sent to the image processing system 12 through the high-speed data transmission interface; the image processing system 12 outputs the detection result to the ejection device 10. When the detection system determines that a bottle is a defective product, the ejection device 10 automatically starts after receiving the signal, uses air pressure to open the valve and blow air, and removes the defective bottles from the subsequent assembly line, realizing automatic sorting and discharging of the entire assembly line.
[0154] The steps in the present invention can be adjusted in sequence, combined, or deleted according to actual needs.
[0155] The units in the device of the present invention can be combined, divided and deleted according to actual needs.
[0156] Although the present invention has been disclosed in detail with reference to the accompanying drawings, it should be understood that these descriptions are merely illustrative and are not intended to limit the application of the present invention. The scope of the present invention is defined by the appended claims and includes various modifications, variations, and equivalents made to the invention without departing from the scope and spirit of the present invention.
Claims
1. A method for detecting printing defects on cylindrical bottles, characterized in that: The method comprises: S1. Use a line array camera to continuously capture images of the rotating cylindrical bottle under the illumination of a combined light source, acquiring images of the bottle body and bottleneck area respectively. The captured images cover more than a complete inspection cycle. S2. Select areas with clear outlines and no duplication within the same cycle from the collected image as positioning points, perform a normalized cross-correlation search on the collected image to determine the positions of the positioning points, use the original image width as the cropping width, and determine the cropping height based on the distance between any two positioning points. Use the middle positioning point as the cropping center, and crop one of the complete cycle images as the detection template image; S3. Fit all the positioning points to a linear function using a linear regression model, and finally calculate the affine transformation matrix of all the positioning points to the detection template image, perform affine transformation on all images, and crop the transformed images according to the template image area to obtain all cropped images within one cycle; S4, using the perceptual hash similarity comparison algorithm to select the best image collection period for all cropped images; S5, correcting the vertical stretching distortion of all cropped images; S6. Performing image difference between the processed inspection image and the template image to obtain a difference image. Grayscale region segmentation is performed on the difference image based on pre-set defect detection areas, contrast, and area thresholds. Connected region features are extracted and analyzed using morphological methods for the segmented areas. The area and aspect ratio parameters of the defective areas are calculated to determine the presence and severity of printing defects. S7. The image processing system outputs judgment information based on the defect detection results. When the detection results show the existence of printing defects, the control signal drives the waste ejection device to start and automatically remove the defective products from the production line; otherwise, qualified products are transported to the next process in sequence.
2. The method for detecting printing defects of cylindrical bottles according to claim 1, characterized in that: The calculation formula of the normalized cross-correlation algorithm in step S2 is as follows: Among them, NCC is the dot product similarity of the overlapping area of the two images in space, f(x,y) is the pixel value of the image to be detected at (x,y), r(x,y) is the pixel value of the template image at (x,y), m and n represent the calculation window size, μ f 、μ r Represent the window means of the image to be detected and the reference template image respectively.
3. The method for detecting printing defects of cylindrical bottles according to claim 1, wherein: The step S3 specifically includes: S31. Fit all the positioning points using a linear regression model, and the calculation formula is as follows: y=kx+b; Where k is the slope and b is the intercept; S32, after initially generating the initial values of the linear function coefficients, the objective function E(k * ,b * ), as shown below: Solve for the parameter k that minimizes the function * ,b * as follows: in, is the input variable x i The mean of , n is the number of positioning points; S33. Calculate the residual for each positioning point: e i =y i -(kx i +b); Among them, e i is the residual of the i-th point, define a residual threshold ∈, and filter out the residuals that satisfy |e i |>∈, retain the rest of the points, iterate the above steps 20 times until the residual screening result no longer changes, obtain the linear fitting function of the coordinate points, and filter out the erroneous coordinates with large deviations; S34. Sort the positioning points vertically from small to large, calculate the interval between each two positioning points, and the Y-axis coordinates after sorting are expressed as follows: <h2 style=";text-align:left;direction:ltr">Y = {y1,y2,y3,...,y<h2 style=";text-align:left;direction:ltr"> n <h2 style=";text-align:left;direction:ltr">}; Calculate the translation affine transformation matrix using the sorted i-th location and the i-th location on the template. Calculate the stretching affine transformation matrix using the ratio of the interval between the sorted i+1-th location and the i-th location to the interval between the i+1-th location and the i-th location on the template. Set the reference point of the stretching affine transformation to the coordinates of the i-th location. S35. Repeat the above operation to calculate the affine transformation matrix of all points, perform affine transformation on the image, and crop the transformed image according to the template image area to obtain all cropped images within a cycle.
4. The method for detecting printing defects of cylindrical bottles according to claim 3, wherein: In step S34, the translation affine transformation matrix is calculated from any two corresponding positioning points; The stretching affine transformation matrix is calculated by the ratio of the distance between adjacent positioning points and the interval between corresponding positioning points in the template, and is based on the first positioning point.
5. The method for detecting printing defects of cylindrical bottles according to claim 1, wherein: The process of selecting the optimal image acquisition period using the perceptual hash similarity comparison algorithm in step S4 includes: S41, uniformly scaling the template image and all cropped images to 32×32 pixels, and converting the multi-channel image into a single-channel grayscale image; S42. Perform a two-dimensional discrete cosine transform on the grayscale image. The formula is as follows: Where f(x,y) is an M×N digital image matrix; F(u,v) is the result of a two-dimensional discrete transformation; C(u) is a piecewise function, and C(v) is similar. The expressions are as follows: S43, selecting the 8×8 matrix in the upper left corner from the two-dimensional transformation result, and calculating the pixel mean of the selected area; S44. Compare each coefficient in the 8×8 matrix with the mean. If the coefficient is greater than or equal to the mean, the coefficient is recorded as 1; if it is less than the mean, the coefficient is recorded as 0, thereby obtaining a binary hash table. S45. Calculate the Hamming distance between each cropped image and the hash table corresponding to the template image. The calculation method is to compare the bits in the vector in turn to see if they are the same. If they are different, the Hamming distance is increased by 1. The Hamming distance calculation formula is as follows: Where Dis is the Hamming distance, N is the length of the hash table, and X 1i is the value of the first hash table at position i; the smaller the Hamming distance Dis, the higher the similarity between the two images; S46. Select the cropped image with the smallest Hamming distance as the optimal image collection period image.
6. The method for detecting printing defects of cylindrical bottles according to claim 1, wherein: Step S5 is performed only for the vertical direction, i.e., the Y direction, and the specific correction process includes: S51, extracting the edge contour of the template image using an edge extraction algorithm; S52, selecting positions with rich contour information in the template image at regular intervals as positioning points; S53. Search for the positioning points corresponding to the template image in the image to be detected, use the two sets of positioning points as input, and construct a thin plate spline transformation model only for the vertical direction. The formula is as follows: Among them, f y (0,y i ) is the thin plate spline function in the Y direction, y i and y i ′ are the y coordinates of the i-th point in the template image and the detection image, ω i is the transformation coefficient to be solved, It is a radial basis function kernel based on the distance between the anchor points; S54, taking the objective function E as the sum of squares of the Y coordinate errors of all positioning points before and after the transformation: S55. Use the least squares method to solve the optimal transformation coefficient, and substitute the coefficient into the improved thin plate spline transformation formula to perform local stretching correction on the detection image in the Y direction while keeping the X coordinate unchanged to achieve high-precision alignment with the template image.
7. A detection device using the method for detecting printing defects on cylindrical bottles according to claims 1-6, characterized in that: The device comprises: a feeding belt (1), an input plum blossom disk (2), an input arc-shaped baffle track (3), a bottle placement tray (4), a feeding turntable (5), a combined light source (6), a camera (7), an output plum blossom disk (8), a feeding belt (9), a waste kicking device (10), an output arc-shaped baffle track (11) and an image processing system (12); The various components realize an automated inspection process through mechanical transmission and signal linkage. The feeding belt (1) first continuously transports the cylindrical bottles to be inspected from the production line to the input plum blossom tray (2); the input plum blossom tray (2) is assisted by the input arc baffle track (3), and sequentially delivers the cylindrical bottles to different bottle trays (4) according to predetermined fixed intervals. The bottle placing tray (4) comprises a tray base (43), a nylon pressing head (41) and a tray gear (44); during the bottle feeding process, the air pressure device drives the nylon pressing head (41) to firmly press the bottle mouth onto the tray base (43); the tray gear (44) is fixed to the bottom of the tray base (43) and meshes with the driving belt of the feeding turntable (5); the bottle placing tray (4) is driven by the driving belt of the feeding turntable (5) through the tray gear (44) to realize self-rotation and orbital revolution together with the feeding turntable (5); When the bottle placement tray (4) passes in front of the camera (7), the feeding turntable (5) triggers a picture acquisition signal, prompting the camera (7) to continuously acquire pictures of the bottle body and the bottleneck located in the detection area; The combined light source (6) evenly illuminates the cylindrical bottle, and the combined light source (6) includes a planar array light source (61) and a tunnel light source (62); The camera (7) includes a first linear array camera (71) and a second linear array camera (72). The first linear array camera (71) is tilted 15 degrees relative to the horizontal direction for shooting. The camera (7) relies on linear array technology to collect images of the bottle body and bottleneck area. The collected images should cover more than a complete image cycle. The cylindrical bottle body is taken out by the output plum blossom disk (8) and finally enters the conveyor belt (9) with the assistance of the output arc baffle track (11); the image obtained by the acquisition is sent to the image processing system (12) through the high-speed data transmission interface; the image processing system (12) outputs the detection result to the ejection device (10). When the detection system determines that a bottle is a defective product, the ejection device (10) automatically starts after receiving the signal, uses air pressure to open the valve and blows air, and removes the defective bottle from the production line.