Visual detection method and device for surface character and pattern defects of cups and kettles

By combining multiple image processing technologies, the problems of complex surface distortion, material reflection interference, and high-speed dynamic detection in the detection of characters and patterns on the surface of cups and kettles have been solved, achieving high-precision defect detection and adapting to complex industrial environments.

CN120976158AInactive Publication Date: 2025-11-18ZHEJIANG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511100057.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-06
Publication Date
2025-11-18
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing machine vision technology faces challenges in detecting defects in characters and patterns on the surface of cups and kettles, such as complex surface distortion, material reflection interference, small and complex defect types, and high-speed dynamic detection, resulting in low detection accuracy.

Method used

By employing background-aware Otsu modulation thresholding, gray-scale feature adaptive extraction, robust fitting method of sub-pixel contour segmentation and M-estimation, and connected component morphological reconstruction and dynamic aspect ratio filtering, combined with image preprocessing techniques, high-precision detection of characters and patterns on the surface of cups and kettles can be achieved.

Benefits of technology

It achieves high-precision detection of characters and patterns on the surface of cups and kettles, improving the comprehensiveness, accuracy and stability of the detection, adapting to different lighting conditions and pattern features, effectively distinguishing defective areas from normal areas, and identifying character shape distortion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120976158A_ABST
    Figure CN120976158A_ABST
Patent Text Reader

Abstract

The invention discloses a cup and kettle surface character and pattern defect visual detection method and device, and relates to the technical field of visual detection, and the method comprises the steps: obtaining the image data of cup and kettle surface characters and patterns of a to-be-detected cup and kettle sample; carrying out image preprocessing on the image data of the to-be-detected cup and kettle sample; positioning internal defects based on a background perception Otsu modulation threshold method and a gray feature adaptive extraction method, and performing pattern internal defect detection on the processed image data to obtain internal defects of characters and patterns on the surfaces of the cups and kettles; performing pattern edge defect detection on the processed image data based on a robust fitting method of sub-pixel contour segmentation and M estimation to obtain edge defects of characters and patterns on the surface of the cup; and on the basis of a connected domain morphological reconstruction and dynamic aspect ratio screening method, pattern skew distortion detection is performed on the processed image data to obtain a morphological distortion result of the characters on the surfaces of the cups and the pots and the characters in the patterns.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of visual inspection, in particular to a cup surface character and pattern defect visual inspection method and device. BACKGROUND

[0002] In the actual application of machine vision technology in cup surface character and pattern defect detection, a series of technical bottlenecks still need to be broken through:

[0003] 1) Complex curved surface and perspective distortion challenge: cylindrical, special-shaped curved surface cup causes serious stretching and distortion of characters and patterns, standard plane imaging algorithm fails, it is difficult to accurately locate and segment ROI (region of interest), resulting in low detection accuracy.

[0004] 2) High light reflection and material diversity interference: glass, smooth plastic, metal and other materials are easy to produce strong mirror reflection or glare, which can easily cover the real defects, resulting in low detection accuracy; at the same time, different materials, colors and textures have great differences in response to light, and a single light source scheme is difficult to be universal.

[0005] 3) Small and complex defect types: character break, adhesion, blur, misprint, missing print, pattern scratch, color difference, stain and inaccurate overprint defects are small in size (often <0.1mm) and varied in shape, which are difficult to distinguish from normal process fluctuations or background noise, resulting in low detection accuracy.

[0006] 4) Stability requirements of high-speed dynamic detection: under the high-speed operation of production line (such as >1000 pieces / minute), the position jitter and motion blur of cup bring serious challenges to the clarity and positioning accuracy of image acquisition, resulting in low detection accuracy. SUMMARY

[0007] The purpose of the present application is to provide a cup surface character and pattern defect visual inspection method and device, which can effectively overcome the above technical bottlenecks and realize high-precision detection of cup surface character and pattern defects.

[0008] To achieve the above purpose, the present application provides the following solutions:

[0009] In a first aspect, the present application provides a cup surface character and pattern defect visual inspection method

[0010] Obtain image data of cup surface characters and patterns of the cup to be inspected; the image data includes cup cylindrical side surface image and cup top surface image of the cup to be inspected;

[0011] Image preprocessing is performed on the image data of the cup to be inspected;

[0012] Based on the background-aware Otsu modulation thresholding method and gray-scale feature adaptive extraction method, internal defects are located, and the internal defects of the characters and patterns on the surface of the cup and kettle are detected.

[0013] Based on a robust fitting method using subpixel contour segmentation and M-estimation, pattern edge defect detection is performed on the processed image data to obtain edge defects of characters and patterns on the surface of cups and kettles.

[0014] Based on the connected component morphological reconstruction and dynamic aspect ratio filtering method, pattern skew and distortion detection is performed on the processed image data to obtain the morphological distortion results of characters and patterns on the surface of cups and kettles.

[0015] Optionally, image preprocessing is performed on the image data of the cup and pot sample to be inspected, specifically including:

[0016] The image data is converted to grayscale to obtain a grayscale image;

[0017] Based on the character colors in the grayscale image, the grayscale image is either inverted or not inverted. When the grayscale value of the character area is greater than that of the background area, it is determined to be a dark color and no inversion is performed, resulting in the processed grayscale image. When the grayscale value of the character area is not greater than that of the background area, it is determined to be a light color and inverted, resulting in the processed grayscale image.

[0018] The processed grayscale image is subjected to small-size filtering to remove noise, resulting in the processed image data.

[0019] Optionally, based on the background-aware Otsu modulation thresholding method and the gray-scale feature adaptive extraction method, internal defects are located, and the processed image data is used to detect internal defects in the patterns on the surface of the cup or kettle, specifically including:

[0020] The background-aware Otsu modulation thresholding method is used to extract the character backbone region from the processed image data; the segmentation threshold in the background-aware Otsu modulation thresholding method is based on the formula... Calculated; where T otsu μ is the basic segmentation threshold obtained from the image using the Otsu method. bg To use T otsu The gray level obtained after binarization segmentation is greater than T. otsu The mean gray value of the region, where α is a strictly adjustable parameter;

[0021] The number of connected components extracted from the character backbone region is determined. When the number of connected components extracted from the character backbone region does not match the number of character region features in the standard cup and kettle product, a multi-channel fault tolerance mechanism is activated. When the number of connected components extracted from the character backbone region matches the number of character region features in the standard cup and kettle product, the next step is executed. The multi-channel fault tolerance mechanism is used to select the channel image or grayscale image that is closest to the expected value and re-acquire the character backbone region.

[0022] The character backbone area is morphologically modified to obtain the modified character backbone area;

[0023] Based on the modified character backbone area, the defect area in the processed image data is extracted using the grayscale feature adaptive threshold extraction method.

[0024] The threshold increment stability constraint optimization is performed on the defect region to locate the gray-level boundary of the real defect in the defect region, and the optimized defect region is obtained.

[0025] Edge interference suppression and variance dynamic hierarchical filtering are performed on the optimized defect area to obtain the internal defects of characters and patterns on the surface of the cup and kettle.

[0026] Alternatively, the method for selecting the channel image or grayscale image that best matches the desired value is as follows:

[0027] Objective function selected based on channel Select the channel image or grayscale image that best matches the desired value; where O represents using a grayscale image as the channel image, and N represents the grayscale image. C N represents the number of connected components extracted from channel C. expected This is the preset expected number of characters.

[0028] Optionally, based on a robust fitting method of subpixel contour segmentation and M-estimation, pattern edge defect detection is performed on the processed image data to obtain edge defects of characters and patterns on the surface of the cup or kettle, specifically including:

[0029] Based on the background-aware Otsu modulation thresholding method, the segmentation threshold is used to binarize the processed image data and extract the character pattern region.

[0030] Extract the boundary lines of the character pattern area; the boundary lines are high-precision contours at the sub-pixel level.

[0031] Based on the sub-pixel contour segmentation method, the boundary lines are segmented to obtain several polygonal contours composed of line segments.

[0032] A robust fitting method based on M-estimation is used to fit a straight line to several polygonal contours composed of line segments, and the fitted straight line is obtained.

[0033] Based on the distance from each point on the polygonal outline to the fitted line, it is determined whether the polygonal outline has edge defects; when there are points on the polygonal outline whose distance from the fitted line exceeds a preset threshold, it is determined that there are edge defects.

[0034] Edge defect detection is performed on all polygonal contours to obtain the edge defects of characters and patterns on the surface of cups and kettles.

[0035] Optionally, the formula for calculating the distance from each point on the polygonal contour to the fitted line is:

[0036] D i =|Nr·r i +Nc·c i +d|;

[0037] Wherein, the unit normal vector of the fitted line is r i denoted as , where c is the residual from a point on the polygonal contour to the fitted line, d is the hyperparameter, and d is the distance from the fitted line to the origin of the image.

[0038] Optionally, the formula for the fitted straight line is:

[0039] Nr·x+Nc·y+d=0.

[0040] Optionally, based on connected component morphological reconstruction and dynamic aspect ratio filtering methods, pattern skew and distortion detection is performed on the processed image data to obtain the morphological distortion results of characters and patterns on the surface of cups and kettles, specifically including:

[0041] Initial connected component labeling is performed on the character pattern region to obtain a set of several non-overlapping connected components;

[0042] Based on the circular structuring element, each non-intersecting connected region is expanded and the connected components are marked again to obtain a new set of regions.

[0043] The areas in the new set of regions are filtered by area to obtain a filtered set of regions; the filtered set of regions consists of connected and complete character pattern regions.

[0044] Calculate the height feature of each character pattern region in the filtered region set and perform threshold filtering to obtain character pattern regions whose height features meet the requirements.

[0045] The width feature of the character pattern areas that meet the height feature requirements after screening is calculated, and dynamic aspect ratio screening is performed to obtain character pattern areas with normal character shape and character pattern areas with distorted character shape; the character pattern areas with distorted character shape are the results of character shape distortion in the characters and patterns on the surface of the cup or pot.

[0046] Secondly, this application provides an apparatus for implementing the aforementioned visual inspection method for character and pattern defects on the surface of a cup or kettle, comprising: a mechanical structure module, a clear imaging and data acquisition module for the cylindrical side of the cup or kettle, and a clear imaging and data acquisition module for the top surface of the cup or kettle;

[0047] The mechanical structure module includes a sample support device for the cup or kettle to be tested, a tunnel light source and its bracket, a line scan camera and its bracket, a ring light source and its bracket, and an area scan camera and its bracket. The sample support device is used to support and fix the cup or kettle to be tested. The tunnel light source, fixed on the tunnel light source bracket, is used to illuminate the cylindrical side surface of the cup or kettle to be tested. The line scan camera is fixed on the line scan camera bracket and is used to acquire image data of the cylindrical side surface of the cup or kettle to be tested. The ring light source is fixed by the ring light source bracket and is used to illuminate the top surface of the cup or kettle to be tested. The area scan camera is fixed by the area scan camera bracket and is used to acquire image data of the top surface of the cup or kettle to be tested.

[0048] The clear imaging and data acquisition module for the cylindrical side of the cup / pot includes a tunnel light source, a line scan camera, and a sample synchronous self-rotation drive platform. The tunnel light source provides narrow, uniform, and stable high-brightness illumination for the cylindrical side of the cup / pot sample to be inspected. The line scan camera scans the continuously rotating cylindrical side of the cup / pot sample column by column and stitches the vector images to generate a high-resolution two-dimensional image of the cylindrical side of the cup / pot. The sample synchronous self-rotation drive platform drives the self-rotation of the cup / pot sample to be inspected.

[0049] The clear imaging and data acquisition module for the top surface of the cup / pot includes a ring light source, an area array camera, and a sample braking platform. The ring light source provides a circular, uniform, and stable high-brightness illumination for the cylindrical top surface of the cup / pot sample to be inspected. The area array camera is used to capture the top surface of the cup / pot sample to be inspected, generating a high-resolution two-dimensional image of the top surface of the cup / pot. The sample braking platform is used to brake the cup / pot sample to be inspected.

[0050] Optionally, the rotational angular velocity, cylindrical cross-sectional area radius, and data acquisition frequency of the sample cup / pot to be tested are matched.

[0051] The specific embodiments provided in this application disclose the following technical effects:

[0052] This application provides a visual detection method and apparatus for characters and patterns on the surface of cups and kettles. First, image data of characters and patterns on the surface of the cup or kettle sample to be inspected is acquired, covering the cylindrical side and top surfaces of the cup or kettle to ensure comprehensive detection. Next, the image data is preprocessed to improve image quality and reduce noise interference. Then, a background-aware Otsu modulation thresholding method and a grayscale feature adaptive extraction method are used to accurately locate internal defects. The combination of these two methods can automatically adapt to different lighting conditions and pattern features, effectively distinguishing defective areas from normal areas. Furthermore, a robust fitting method based on subpixel contour segmentation and M-estimation is used for fine detection of pattern edges. Subpixel technology provides more accurate edge location information, while the robust fitting method based on M-estimation effectively resists outlier interference, ensuring the accuracy of edge detection. Finally, based on connected component morphological reconstruction and dynamic aspect ratio filtering, skew and distortion detection of characters in the pattern is performed. This method analyzes the morphological features of the characters and dynamically adjusts the filtering conditions to accurately identify character morphological distortion. This application, by comprehensively utilizing these advanced image processing and pattern recognition technologies, can achieve high-precision detection of character and pattern defects on the surface of cups and kettles. Attached Figure Description

[0053] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0054] Figure 1 A flowchart of a visual inspection method for character and pattern defects on the surface of a cup or kettle, provided in an embodiment of this application;

[0055] Figure 2 This is a mechanical structure diagram of a device for clearly imaging and acquiring data on defects in characters and patterns on the surface of cups and kettles, provided in an embodiment of this application.

[0056] Figure 3 This is a flowchart of a visual inspection method for defects within character and pattern areas in one embodiment of this application;

[0057] Figure 4 This is a flowchart of a visual detection method for defects at the edges of character and pattern areas in one embodiment of this application;

[0058] Figure 5 This is a flowchart of a visual detection method for character and pattern skew or distortion defects in one embodiment of this application. Detailed Implementation

[0059] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0060] In modern industrial production, the characters (such as production date, batch number, shelf life, ingredient information, and barcodes) and brand patterns and decorative designs on the surfaces of cups and containers (including glass bottles, plastic bottles, ceramic cups, and metal cans) serve as core carriers for product quality control, brand image maintenance, and safety information traceability. The printing or engraving quality directly impacts consumer trust, corporate compliance, and market circulation efficiency. Against this backdrop, machine vision technology, with its advantages of non-contact operation, high speed, high precision, and objective consistency, demonstrates significant scientific and engineering value in the field of surface defect detection for cups and containers. Its scientific significance lies in its ability to simulate and surpass human visual perception, establishing quantitative identification models for minute defects on complex curved surfaces, under highly reflective conditions, and against multi-material backgrounds. This promotes the deep integration of optical imaging, image processing, and artificial intelligence in industrial inspection. The engineering value is even more direct: it replaces the traditional, inefficient, tiring, and subjective manual visual inspection, realizing fully automated, 100% online real-time detection on the production line, significantly improving quality inspection efficiency (up to dozens of times that of manual inspection), reducing the rate of missed / false inspections, ensuring the completeness and accuracy of product information, and avoiding economic losses, brand reputation damage, and even safety hazards (such as unclear information on expired medicines) caused by defective products entering the market. It strongly supports the high-quality and intelligent production upgrade of industries such as food, beverage, pharmaceuticals, and cosmetics.

[0061] However, current machine vision technology still faces a series of technical bottlenecks that urgently need to be overcome in the practical application of detecting defects in characters and patterns on the surface of cups and kettles.

[0062] The purpose of this application is to provide a visual inspection method and device for character and pattern defects on the surface of cups and kettles, which can effectively overcome the above-mentioned technical bottlenecks and achieve high-precision inspection of character and pattern defects on the surface of cups and kettles.

[0063] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0064] Example 1

[0065] like Figure 1 As shown, this embodiment provides a visual inspection method for character and pattern defects on the surface of cups and kettles.

[0066] Step 101: Obtain image data of characters and patterns on the surface of the cup and pot sample to be inspected; the image data includes the cylindrical side image and the top image of the cup and pot sample to be inspected;

[0067] Step 102: Perform image preprocessing on the image data of the cup and pot samples to be inspected;

[0068] Step 103: Based on the background-aware Otsu modulation thresholding method and gray-scale feature adaptive extraction method, locate internal defects, and perform pattern internal defect detection on the processed image data to obtain the internal defects of characters and patterns on the surface of the cup and pot.

[0069] Step 104: Based on the robust fitting method of subpixel contour segmentation and M estimation, the processed image data is subjected to pattern edge defect detection to obtain the edge defects of characters and patterns on the surface of the cup and kettle.

[0070] Step 105: Based on the connected component morphological reconstruction and dynamic aspect ratio filtering method, the processed image data is subjected to pattern skew and distortion detection to obtain the morphological distortion results of characters on the surface of the cup and pot and the characters in the pattern.

[0071] In some embodiments, when performing steps 101-105, the specific steps may be as follows:

[0072] Specifically, image preprocessing of the image data of the cup and pot samples to be inspected includes:

[0073] The image data is converted to grayscale to obtain a grayscale image;

[0074] Based on the character colors in the grayscale image, the grayscale image is either inverted or not inverted. When the grayscale value of the character area is greater than that of the background area, it is determined to be a dark color and no inversion is performed, resulting in the processed grayscale image. When the grayscale value of the character area is not greater than that of the background area, it is determined to be a light color and inverted, resulting in the processed grayscale image.

[0075] The processed grayscale image is subjected to small-size filtering to remove noise, resulting in processed image data. This processed image data will serve as the input image for subsequent character backbone region extraction and adaptive defect extraction steps.

[0076] Among them, the Otsu modulation thresholding method based on background awareness and the adaptive extraction method of grayscale features are used to locate internal defects. The processed image data is then used to detect internal defects in the characters and patterns on the surface of the cups and kettles, specifically including:

[0077] The background-aware Otsu modulation thresholding method is used to extract the character backbone region from the processed image data;

[0078] The number of connected components extracted from the character backbone region is determined. When the number of connected components extracted from the character backbone region does not match the number of character region features in the standard cup and kettle product, a multi-channel fault tolerance mechanism is activated. When the number of connected components extracted from the character backbone region matches the number of character region features in the standard cup and kettle product, the next step is executed. The multi-channel fault tolerance mechanism is used to select the channel image or grayscale image that is closest to the expected value and re-acquire the character backbone region.

[0079] The character backbone area is morphologically modified to obtain the modified character backbone area;

[0080] Based on the modified character backbone area, the defect area in the processed image data is extracted using the grayscale feature adaptive threshold extraction method.

[0081] The threshold increment stability constraint optimization is performed on the defect region to locate the gray-level boundary of the real defect in the defect region, and the optimized defect region is obtained.

[0082] Edge interference suppression and variance dynamic hierarchical filtering are performed on the optimized defect area to obtain the internal defects of characters and patterns on the surface of the cup and kettle.

[0083] Specifically, the background-aware Otsu modulation thresholding method is used to extract the character backbone region, providing an accurate ROI for subsequent defect adaptive extraction steps, thereby improving the overall algorithm accuracy and speed. Specifically, a segmentation threshold T is accurately calculated using a linear interpolation model, followed by binarization segmentation. Connected components with a mean grayscale value greater than T in the segmentation result are then used as the ROI for defect adaptive extraction. The expression for calculating the segmentation threshold T is as follows:

[0084]

[0085] In the formula, T otsu The base segmentation threshold, μ, is obtained for the image using the Otsu method (maximum inter-class variance method). bg To use T otsu The gray level obtained after binarization segmentation is greater than T. otsu The grayscale mean of the region is α, which is a strictly adjustable parameter, and α∈[0,2]. The larger the value of α, the more complete the extracted character backbone region. However, the more background interference is also included. By continuously adjusting the value of α, the algorithm can achieve a smooth transition between strict character backbone extraction and loose edge feature preservation. This method effectively solves the oversegmentation problem caused by edge blurring and uneven lighting in complex industrial scenes using traditional binarization, significantly improving the accuracy and robustness of character backbone region extraction, and laying a reliable foundation for subsequent defect detection.

[0086] For the consistency check of the number of connected components in the character backbone, this step judges the number of connected components extracted from the character backbone region. If it does not meet the requirements, a multi-channel fault tolerance mechanism is activated. Specifically, if the number of connected components extracted from the character backbone region does not match the number of character region features in the actual product, the multi-channel fault tolerance mechanism will be activated. The multi-channel fault tolerance mechanism will select the channel image or grayscale image that is closest to the expected value and re-acquire the character backbone region. The optimality of the channel selection is strictly defined by the objective function:

[0087]

[0088] In the formula, O indicates that a grayscale image is used as the channel map, and N C N represents the number of connected components extracted from channel C. expected Given a preset expected number of characters, the algorithm prioritizes selecting characters that satisfy N. C =N expected The function describes how, after the multi-channel fault tolerance mechanism is activated, it sequentially traverses the RGB color channels, independently executing a complete dynamic threshold extraction process for each channel until a channel meeting the quantity requirement is found or all channels have been traversed. By leveraging the complementarity of multi-channel information, it effectively overcomes the segmentation failure or poor performance issues of single-channel processing in complex industrial environments such as low contrast, reflection, and shadows, ensuring the reliability of character integrity detection.

[0089] Morphological modifications are applied to the main character region. Specifically, depending on the actual needs, options include filling in holes of a certain size in the main character region, expanding or shrinking areas, and performing small-scale morphological processing, such as using 3x3 microstructural elements for erosion or expansion. If morphological modification is chosen, the modified result is used as the ROI for subsequent adaptive defect extraction.

[0090] Defect Adaptive Extraction: A gray-scale feature adaptive threshold extraction method is used to extract defect regions, and threshold increment stability constraints are applied to ensure accurate detection of different types of defects. Specifically, this step designs symmetrical but independent processing flows for bright and dark defects. Taking bright defects as an example, the image is first located on the main body region of a single character. Then, gray-scale feature adaptive threshold extraction and threshold increment stability constraints are applied to optimize the extracted region. This method gradually merges pixels with grayscale values ​​in the range [Max-i, i] based on the iteration step size δ, using these as the initial defect regions. Max is the maximum grayscale value in the main body region of a single character, and i is the iteration number. The area of ​​the defect region obtained after each iteration is A. i The iteration step size δ for the defect and the termination condition for the iteration are as follows:

[0091]

[0092] In the formula, μ is the average gray value of the backbone region of a single character, and θ area This is a configurable area threshold parameter. For dark defects, pixels with gray levels in the range [Min, Min+i] are gradually merged as the initial defect regions, where Min is the minimum gray level in the main body region of a single character. The iteration step size δ for dark defects and the termination condition for the iteration are as follows:

[0093]

[0094] This step, through iterative search and termination mechanisms, accurately locates the grayscale boundaries of real defects. The area abrupt change criterion effectively identifies the boundary transition points of defect regions, fundamentally solving the over-segmentation and under-segmentation problems commonly found in traditional fixed-step threshold searches, and significantly improving detection accuracy.

[0095] Next, defect region screening is performed. In this step, edge interference suppression and variance dynamic hierarchical filtering are used to screen the defect regions obtained in the previous steps. Specifically, edge interference suppression calculates the edge proximity index ρ and determines whether it is an edge artifact rather than a valid defect by judging whether the index ρ is greater than a certain value. The expression for the index ρ is as follows:

[0096]

[0097] In the formula, D represents the defective area to be screened, and B... edge This is the inverted core region of a single character. After the above filtering is completed, dynamic variance-based layered filtering is performed. The details involve slightly dilating the filtered region, obtaining the grayscale variance within the region, and retaining regions with variances greater than a set threshold. If the region area is greater than a certain value, regions with variances greater than a certain percentage of the set threshold are retained. After completing all the above operations, the resulting region is considered the defect region. This method solves the edge artifact problem, quantifies the spatial relationship between defects and boundaries, retains small-area high-contrast defects and large-area low-contrast defects, and improves the adaptability and accuracy of the detection system. A detailed flowchart of the visual detection method for defects within character and pattern regions is shown below. Figure 3 As shown.

[0098] Among them, a robust fitting method based on sub-pixel contour segmentation and M-estimation is used to detect pattern edge defects in the processed image data, obtaining the edge defects of characters and patterns on the surface of the cups and kettles, specifically including:

[0099] Based on the background-aware Otsu modulation thresholding method, the segmentation threshold is used to binarize the processed image data and extract the character pattern region.

[0100] Extract the boundary lines of the character pattern area; the boundary lines are high-precision contours at the sub-pixel level.

[0101] Based on the sub-pixel contour segmentation method, the boundary lines are segmented to obtain several polygonal contours composed of line segments.

[0102] A robust fitting method based on M-estimation is used to fit a straight line to several polygonal contours composed of line segments, and the fitted straight line is obtained.

[0103] Based on the distance from each point on the polygonal outline to the fitted line, it is determined whether the polygonal outline has edge defects; when there are points on the polygonal outline whose distance from the fitted line exceeds a preset threshold, it is determined that there are edge defects.

[0104] Edge defect detection is performed on all polygonal contours to obtain the edge defects of characters and patterns on the surface of cups and kettles.

[0105] Specifically, the character pattern area can be extracted as follows:

[0106] A threshold determination method is employed for the obtained image using the maximum inter-class variance (MOV) method. This method automatically selects an optimal threshold t by analyzing the image's gray-level histogram to maximize the inter-class variance between the foreground and background, thereby achieving optimal segmentation. Based on the determined threshold t, the input image is binarized. Specifically, regions with gray values ​​higher than the threshold are designated as foreground (region value 1), while regions with gray values ​​lower than the threshold are classified as background (region value 0). In this method, the foreground portion represents the character region to be detected in the image. This approach ensures the accuracy and stability of the extraction results.

[0107] The boundary lines of the character pattern area can be extracted as follows:

[0108] For each input region, boundary tracking is performed to extract its boundary pixel paths. Smoother boundary points are then calculated using linear interpolation between contour points, thus accurately converting pixel-level regions into sub-pixel-level high-precision contours. These contours will be used in subsequent character boundary defect detection tasks.

[0109] The boundary lines can be defined as follows:

[0110] First, a threshold, MaxLineDist1, is set as the error tolerance for line fitting. The algorithm constructs a straight line from the start and end points of the current contour, and then finds the point on the contour that is farthest from this straight line, denoted as the maximum deviation d_max. If this deviation d_max exceeds the preset threshold MaxLineDist1, it means that the current straight line is insufficient to accurately represent the shape of the contour. Therefore, the algorithm will split the contour at the farthest point, dividing it into two segments, and recursively perform the same judgment and processing on these two segments. Conversely, if d_max is less than or equal to the threshold, it means that the contour segment can be well approximated by a straight line within the error range, and the algorithm retains it as a line segment. Through this step-by-step segmentation and recursive processing, the algorithm finally restores the entire complex contour into a polygonal contour composed of several straight line segments with precisely controlled error.

[0111] Fitting each polygon contour can be done as follows:

[0112] After obtaining the polygonal contour curve, a straight line fitting was performed using a robust fitting method based on M-estimation. During the iteration process, this method replaced the traditional ordinary residual sum of squares with a weighted residual sum of squares, effectively suppressing the interference of outliers and noise on the fitting results.

[0113] The specific steps are as follows: First, define points on a curve: (x1, y1), (x2, y2), ..., (x...). n ,y n Then, the weighted sum of squared residuals is defined as follows:

[0114]

[0115] To minimize the objective function S(a,b), the solution formula is shown below:

[0116]

[0117] In the formula: The weight w of each point i The weights are calculated using the robust weight function, and the formula for weight calculation is shown below:

[0118]

[0119] In the formula, c is the hyperparameter, and ri is the residual from a point on the curve to the straight line.

[0120] Points in the contour that are closer to the fitted line are given higher weights, while points that are farther away (i.e., potential outliers) are given lower weights or even weights close to zero. In this way, the fitting process can better reflect the main trend of the contour and is not affected by individual outliers.

[0121] The fitting algorithm controls the convergence process of robust estimation by setting the number of iterations. Each iteration repeats the above steps: first, calculate the residual ri from each point to the current line; then update the corresponding weights Wi according to the magnitude of the residuals; then refit with the updated weighted point set; this process is repeated until the weights converge or the set maximum number of iterations is reached, thus obtaining a stable and highly accurate line fitting result.

[0122] Calculate the distance from each point on the curve to its fitted straight line, and find the points with the greatest distance as follows:

[0123] First, obtain the unit normal vector of the fitted line from the previous step. And the distance d from the line to the origin of the image. The equation of the line can then be expressed in point-normal form as:

[0124] Nr·x+Nc·y+d=0.

[0125] After establishing the fitted line, the calculation is further performed on each point p on the contour. i =(r i ,c i The perpendicular geometric distance D from the line i Therefore, the following distance calculation formula is adopted:

[0126] D i =|Nr·r i +Nc·c i +d|

[0127] Next, the distance from all points on the contour to their fitted line is calculated and compared with a preset threshold D. thr Compare them. If the distance D from a certain point is... i Greater than the threshold D thr If the point deviates significantly from the fitted straight line, it indicates that the point is significantly off-center. When defects such as jagged edges and waves appear in the outline of a character or pattern, these points usually appear at the jagged edges and waves of the outline. Therefore, these points can be identified as defect boundaries and marked.

[0128] This step is essentially an anomaly detection mechanism based on geometric deviation. By precisely controlling the straight-line fitting error, local perturbation regions are separated from the global profile, thereby achieving robust detection of structural anomalies or surface defects. A detailed flowchart of this method is shown below. Figure 4 As shown.

[0129] Among them, based on the connected component morphological reconstruction and dynamic aspect ratio filtering method, pattern skew and distortion detection is performed on the processed image data to obtain the character morphological distortion results of the characters and patterns on the surface of the cup and kettle, specifically including:

[0130] Initial connected component labeling is performed on the character pattern region to obtain a set of several non-overlapping connected components;

[0131] Based on the circular structuring element, each non-intersecting connected region is expanded and the connected components are marked again to obtain a new set of regions.

[0132] The areas in the new set of regions are filtered by area to obtain a filtered set of regions; the filtered set of regions consists of connected and complete character pattern regions.

[0133] Calculate the height feature of each character pattern region in the filtered region set and perform threshold filtering to obtain character pattern regions whose height features meet the requirements.

[0134] The width feature of the character pattern areas that meet the height feature requirements after screening is calculated, and dynamic aspect ratio screening is performed to obtain character pattern areas with normal character shape and character pattern areas with distorted character shape; the character pattern areas with distorted character shape are the results of character shape distortion in the characters and patterns on the surface of the cup or pot.

[0135] Specifically, the character pattern area can be extracted as follows:

[0136] Based on existing dynamic threshold segmentation, the grayscale distributions of characters and backgrounds have been initially separated, but issues such as stroke breakage, adhesion, and interference from small noises need to be addressed. This algorithm employs a three-step fusion strategy: "connected component analysis + morphological dilation + area constraint".

[0137] The first step is initial connected component labeling. For the binary image I(x,y), perform 8-neighborhood connected component labeling to obtain a set of several disjoint connected regions: R = {R1, R2, R3, ..., R}. i ={(x,y)|I(x,y)=1, belonging to the i-th connected region}

[0138] The second step, morphological expansion connection, introduces a circular structural element with radius R to connect broken strokes and fill internal voids: B. R ={(u,v)|u 2 +v 2 =R 2 Then, each initial region Ri is expanded:

[0139] After expansion, connected components are labeled again to obtain a new set of regions R' = {R'1, R'2, R'3, ..., R'}. m}

[0140] The third step is area-constrained filtering. Since the real character area usually has a relatively fixed area range, while the noise or small interference area is smaller, precise filtering can be achieved by setting an appropriate area threshold. The area of ​​the real character area is usually within [A...]. min A max The range, noise, or non-character small patch area is extremely small. For each R′ j Calculate the area: A j =|R′ j |, |*| represents the number of pixels, and retains: R * ={R′ j |A min ≤A≤A max The final output region set R * That is, a connected and complete character region.

[0141] This step involves multi-step processing, allowing for flexible parameter adjustments based on different image characteristics. It effectively eliminates interference factors, ensuring the integrity and accuracy of character region extraction, and is suitable for various image scenarios with complex character backgrounds.

[0142] Specifically, areas with unacceptable heights can be screened as follows:

[0143] For the initially extracted character pattern regions, the height features of each region are calculated and thresholded. The principle is that real characters in an image typically have a specific height range, while the height of abnormal regions often deviates from this normal range. The height range is set to [H...]. min H max The algorithm compares the height of each region one by one, retaining only those regions whose height falls within the specified range and eliminating abnormal regions that are too tall or too short. This process, based on precise size constraints, effectively eliminates abnormal regions caused by image distortion or noise by dynamically adjusting the height threshold, thus improving the reliability of subsequent processing. Compared to traditional single-size filtering, this method allows for flexible threshold setting based on factors such as character type and image resolution, making it suitable for filtering character images of different sizes.

[0144] Specifically, areas with unacceptable aspect ratios can be screened as follows:

[0145] For the highly filtered region set R h Further, residual areas with abnormal shapes are removed. This algorithm uses a combination of dynamic threshold judgment and iterative filtering to accurately remove areas with abnormal shapes.

[0146] The first step is dynamic threshold modeling, which calculates the aspect ratio distribution of each character region in a batch of labeled samples: Estimate its mean μ r and standard deviation σ r : Then fix the interval [R] min ,R max Replace with an adjustable interval based on statistical prior: R min =μ r -kσ r R max =μ r +kσ r , where k can be dynamically fine-tuned at runtime based on the image noise level.

[0147] The second step involves iterating through the filtering process. For each extracted character region, geometric extraction, aspect ratio calculation, and threshold judgment are performed sequentially. First, the geometric dimensions of the characters are extracted: w = x max -x min +1,h=y max -y min +1, after extracting the geometric dimensions of the characters, through Calculate the aspect ratio of the extracted character region, then compare the calculated r with a set threshold. If R... min ≤r≤R max If the character is distorted, it is considered a good, undistorted character; otherwise, it is considered an unqualified character. This method innovatively combines dynamic threshold judgment with cyclic screening, which can not only accurately remove character regions with abnormal shapes, but also adapt to character images with different fonts and layouts by adjusting the aspect ratio threshold. Compared with traditional fixed threshold screening, this method has stronger robustness and adaptability in complex character scenarios, ensuring that the screening results meet the preset shape standards.

[0148] This step is essentially a hierarchical region selection algorithm based on prior geometric features. It achieves accurate extraction of character regions through a combined strategy of "morphological operation-based region aggregation + multi-dimensional geometric feature constraint selection." Its core value lies in transforming the spatial morphology and geometric attributes of characters into computable quantitative standards, balancing extraction accuracy and noise resistance through a multi-level selection mechanism. A detailed flowchart of this method is shown below. Figure 5 As shown.

[0149] Example 2

[0150] like Figure 2 As shown, this embodiment provides an apparatus for implementing the visual detection method for character and pattern defects on the surface of a cup or kettle, comprising: a mechanical structure module, a clear imaging and data acquisition module for the cylindrical side of the cup or kettle, and a clear imaging and data acquisition module for the top surface of the cup or kettle;

[0151] The mechanical structure module mainly includes a sample support device for the cups and jugs to be inspected, a tunneling light source and its bracket, a line scan camera and its bracket, a ring light source and its bracket, and an area scan camera and its bracket. Detailed structures are as follows: Figure 1 As shown. The sample support device for the cup / pot under test is used to support and fix the sample under test, ensuring that the sample moves as required; the tunnel light source is fixed by a specially designed bracket and is used to illuminate the side of the sample cylinder; the line scan camera is fixed by a specially designed bracket and is used to acquire image data of the side of the sample cylinder; the ring light source is fixed by a specially designed bracket and is used to illuminate the top surface of the sample; the area scan camera is fixed by a specially designed bracket and is used to acquire image data of the top surface of the sample.

[0152] The clear imaging and data acquisition module for the cylindrical side of the cup / pot includes a tunneling light source, a line scan camera, and a sample-frequency self-rotation drive platform. The tunneling light source provides narrow, uniform, and stable high-brightness illumination, ensuring that the cylindrical side of the sample receives sufficient light and suppressing light interference from other locations. The line scan camera is used to scan the continuously rotating cylindrical side of the cup / pot sample column by column, and then stitches the vector images to generate a high-resolution two-dimensional image of the cylindrical side of the cup / pot. The sample-frequency self-rotation drive platform is used to drive the sample's self-rotation, requiring that the sample's self-rotation angular velocity, the radius of the cylinder's cross-sectional area, and the data acquisition frequency of the line scan camera be matched.

[0153] The clear imaging and data acquisition module for the top surface of the cup / pot includes a ring light source, an area array camera, and a sample braking platform. The ring light source provides uniform and stable high-brightness illumination, ensuring that the top surface of the sample receives sufficient light and suppressing light interference from other locations. The area array camera captures the top surface of the cup / pot, generating a high-resolution two-dimensional image of the top surface. The sample braking platform rapidly brakes the self-rotating sample, keeping it stationary throughout the acquisition process from triggering to image completion, ensuring no image blurring in the top area of ​​the sample.

[0154] In summary, this application has the following technical effects:

[0155] 1) This application not only significantly improves the level of intelligent quality inspection in the cup and kettle manufacturing industry, reducing labor costs and quality risks, but also has profound industrial application prospects and technological innovation value. It integrates line scanning and area array imaging schemes, and develops dedicated detection algorithms for character and pattern defects.

[0156] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0157] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A visual inspection method for characters and patterns defects on the surface of cups and kettles, characterized in that, include: Acquire image data of characters and patterns on the surface of the cup and pot sample to be inspected; the image data includes the cylindrical side image and the top image of the cup and pot sample to be inspected; Image preprocessing is performed on the image data of the cup and pot samples to be inspected; Based on the background-aware Otsu modulation thresholding method and gray-scale feature adaptive extraction method, internal defects are located, and the internal defects of the characters and patterns on the surface of the cup and kettle are detected. Based on a robust fitting method using subpixel contour segmentation and M-estimation, pattern edge defect detection is performed on the processed image data to obtain edge defects of characters and patterns on the surface of cups and kettles. Based on the connected component morphological reconstruction and dynamic aspect ratio filtering method, pattern skew and distortion detection is performed on the processed image data to obtain the morphological distortion results of characters and patterns on the surface of cups and kettles.

2. The visual inspection method for characters and patterns on the surface of cups and kettles according to claim 1, characterized in that, Image preprocessing is performed on the image data of the cup and pot samples to be inspected, specifically including: The image data is converted to grayscale to obtain a grayscale image; Based on the character colors in the grayscale image, the grayscale image is either inverted or not inverted. When the grayscale value of the character area is greater than that of the background area, it is determined to be a dark color and no inversion is performed, resulting in the processed grayscale image. When the grayscale value of the character area is not greater than that of the background area, it is determined to be a light color and inverted, resulting in the processed grayscale image. The processed grayscale image is subjected to small-size filtering to remove noise, resulting in the processed image data.

3. The visual inspection method for characters and patterns on the surface of cups and kettles according to claim 2, characterized in that, Based on the background-aware Otsu modulation thresholding method and grayscale feature adaptive extraction method, internal defects are located. The processed image data is then used for pattern internal defect detection to obtain internal defects in characters and patterns on the surface of cups and kettles, specifically including: The background-aware Otsu modulation thresholding method is used to extract the character backbone region from the processed image data; the segmentation threshold in the background-aware Otsu modulation thresholding method is based on the formula... Calculated; where T otsu μ is the basic segmentation threshold obtained from the image using the Otsu method. bg To use T otsu The gray level obtained after binarization segmentation is greater than T. otsu The mean gray value of the region, where α is a strictly adjustable parameter; The number of connected components extracted from the character backbone region is determined. When the number of connected components extracted from the character backbone region does not match the number of character region features in the standard cup and kettle product, a multi-channel fault tolerance mechanism is activated. When the number of connected components extracted from the character backbone region matches the number of character region features in the standard cup and kettle product, the next step is executed. The multi-channel fault tolerance mechanism is used to select the channel image or grayscale image that is closest to the expected value and re-acquire the character backbone region. The character backbone area is morphologically modified to obtain the modified character backbone area; Based on the modified character backbone area, the defect area in the processed image data is extracted using the grayscale feature adaptive threshold extraction method. The threshold increment stability constraint optimization is performed on the defect region to locate the gray-level boundary of the real defect in the defect region, and the optimized defect region is obtained. Edge interference suppression and variance dynamic hierarchical filtering are performed on the optimized defect area to obtain the internal defects of characters and patterns on the surface of the cup and kettle.

4. The visual inspection method for characters and patterns on the surface of cups and kettles according to claim 3, characterized in that, The method for selecting the channel image or grayscale image that best matches the desired value is as follows: Objective function selected based on channel Select the channel image or grayscale image that best matches the desired value; where O represents using a grayscale image as the channel image, and N represents the grayscale image. C N represents the number of connected components extracted from channel C. expected This is the preset expected number of characters.

5. The visual inspection method for character and pattern defects on the surface of cups and kettles according to claim 4, characterized in that, Based on a robust fitting method using sub-pixel contour segmentation and M-estimation, edge defect detection is performed on the processed image data to obtain edge defects of characters and patterns on the surface of cups and kettles, specifically including: Based on the background-aware Otsu modulation thresholding method, the segmentation threshold is used to binarize the processed image data and extract the character pattern region. Extract the boundary lines of the character pattern area; the boundary lines are high-precision contours at the sub-pixel level. Based on the sub-pixel contour segmentation method, the boundary lines are segmented to obtain several polygonal contours composed of line segments. A robust fitting method based on M-estimation is used to fit a straight line to several polygonal contours composed of line segments, and the fitted straight line is obtained. Based on the distance from each point on the polygonal outline to the fitted line, it is determined whether the polygonal outline has edge defects; when there are points on the polygonal outline whose distance from the fitted line exceeds a preset threshold, it is determined that there are edge defects. Edge defect detection is performed on all polygonal contours to obtain the edge defects of characters and patterns on the surface of cups and kettles.

6. The visual inspection method for characters and patterns on the surface of cups and kettles according to claim 5, characterized in that, The formula for calculating the distance from each point on the polygonal contour to the fitted line is: D i =|Nr·r i +Nc·c i +d|; Wherein, the unit normal vector of the fitted line is r i denoted as , where c is the residual from a point on the polygonal contour to the fitted line, d is the hyperparameter, and d is the distance from the fitted line to the origin of the image.

7. A visual inspection method for character and pattern defects on the surface of cups and kettles according to claim 6, characterized in that, The formula for the fitted straight line is: Nr·x+Nc·y+d=0.

8. A visual inspection method for character and pattern defects on the surface of cups and kettles according to claim 7, characterized in that, Based on connected component morphological reconstruction and dynamic aspect ratio filtering, pattern skew and distortion detection is performed on the processed image data to obtain the morphological distortion results of characters and patterns on the surface of cups and kettles, specifically including: Initial connected component labeling is performed on the character pattern region to obtain a set of several non-overlapping connected components; Based on the circular structuring element, each non-intersecting connected region is expanded and the connected components are marked again to obtain a new set of regions. The areas in the new set of regions are filtered by area to obtain a filtered set of regions; the filtered set of regions consists of connected and complete character pattern regions. Calculate the height features of each character pattern region in the filtered region set and perform threshold filtering to obtain character pattern regions whose height features meet the requirements. The width feature of the character pattern areas that meet the height feature requirements after screening is calculated, and dynamic aspect ratio screening is performed to obtain character pattern areas with normal character shape and character pattern areas with distorted character shape; the character pattern areas with distorted character shape are the results of character shape distortion in the characters and patterns on the surface of the cup or pot.

9. An apparatus for implementing the visual inspection method for character and pattern defects on the surface of a cup or kettle as described in any one of claims 1-8, characterized in that, include: Mechanical structure module, clear imaging and data acquisition module for the cylindrical side of the cup and kettle, and clear imaging and data acquisition module for the top surface of the cup and kettle; The mechanical structure module includes a sample support device for cups and pots to be inspected, a tunnel light source and its support, a line scan camera and its support, a ring light source and its support, and an area scan camera and its support. The sample support device for the cups and jugs to be tested is used to support and fix the cups and jugs to be tested; the tunnel light source, fixed on the tunnel light source bracket, is used to illuminate the cylindrical side surface of the cups and jugs to be tested; the line scan camera is fixed on the line scan camera bracket, and is used to acquire image data of the cylindrical side surface of the cups and jugs to be tested; the ring light source is fixed through the ring light source bracket, and is used to illuminate the top surface of the cups and jugs to be tested; the area scan camera is fixed through the area scan camera special bracket, and is used to acquire image data of the top surface of the cups and jugs to be tested. The clear imaging and data acquisition module for the cylindrical side of the cup / pot includes a tunnel light source, a line scan camera, and a sample synchronous self-rotation drive platform. The tunnel light source provides narrow, uniform, and stable high-brightness illumination for the cylindrical side of the cup / pot sample to be inspected. The line scan camera scans the continuously rotating cylindrical side of the cup / pot sample column by column and stitches the vector images to generate a high-resolution two-dimensional image of the cylindrical side of the cup / pot. The sample synchronous self-rotation drive platform drives the self-rotation of the cup / pot sample to be inspected. The clear imaging and data acquisition module for the top surface of the cup / pot includes a ring light source, an area array camera, and a sample braking platform. The ring light source provides a circular, uniform, and stable high-brightness illumination for the cylindrical top surface of the cup / pot sample to be inspected. The area array camera is used to capture the top surface of the cup / pot sample to be inspected, generating a high-resolution two-dimensional image of the top surface of the cup / pot. The sample braking platform is used to brake the cup / pot sample to be inspected.

10. The apparatus according to claim 9, characterized in that, The self-rotation angular velocity, cylindrical cross-sectional area radius, and data acquisition frequency of the sample cup and pot to be tested are matched.