Cigarette hard carton damage defect detection system and method
Through the embedded visual inspection module and image processing algorithm, the problem of detecting damage and scratches on hard gift boxes has been solved, efficient and accurate defect detection has been achieved, and production efficiency and product quality control have been improved.
Patent Information
- Application Number
- CN202510842275.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-23
- Publication Date
- 2025-10-03
AI Technical Summary
Existing technologies make it difficult to effectively detect damage and scratch defects in hard gift boxes, resulting in difficulty in timely discovery of product quality problems, affecting production efficiency and causing waste of raw and auxiliary materials.
By adopting the embedded visual inspection module, combined with Canny edge detection, Hough transform and dynamic mask area tracking algorithm, real-time detection of damage and scratch defects of hard boxes can be achieved through image acquisition, grayscale processing, edge detection, dynamic binarization and feature extraction.
It achieves high-precision detection of defects in rigid boxes, reduces false detections, improves production efficiency, reduces the waste of raw and auxiliary materials, and enhances product quality control capabilities.
Smart Images

Figure CN120741344A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial visual inspection, and in particular to a system and method for detecting damage defects in cigarette hard cartons. Background Art
[0002] With the rapid development of modern manufacturing, the demand for product quality is becoming increasingly stringent. During the production process, defect detection is a crucial step in ensuring product quality. The hard gift boxes used in Diamond (Soft Lotus) products are prone to various defects due to their manual manufacturing. They are also prone to appearance defects such as scratches when used on machines and lack compatibility with other machines. These quality issues occur infrequently and with poor regularity. Operators are unable to observe the box's condition before the lid is closed, making them difficult to detect during self-inspections. Cartoning machine visual inspections and manual inspections during the manual packing process are limited to inspecting the side edges after the transparent paper wrapping. Full inspection of the front long edges before the lid is closed is impossible. This results in a long traceability period for these quality issues, severely impacting equipment efficiency and resulting in significant waste of raw and auxiliary materials. This issue demands urgent resolution. Relying solely on manual control is extremely difficult, and traditional defect detection methods also suffer from inefficiencies and insufficient precision, making them unable to meet the demands of modern production. For example: 1. Existing cigarette packaging inspection relies heavily on industrial cameras and high-computing platforms, which are costly and complex to deploy. 2. Due to computing power limitations on embedded devices, traditional image processing methods are difficult to directly apply to high-precision defect detection. 3. The central edges of rigid cartons easily produce interfering lines, making existing algorithms prone to false detections. 4. Existing systems lack the ability to centrally debug multiple devices, resulting in inefficient maintenance.
[0003] Therefore, the present invention hopes to introduce a defect detection system based on machine vision to improve the accuracy and efficiency of gift box appearance defect detection, so as to timely discover product problems and issue alarms to eliminate them, ensure product quality, and prevent defective products from entering the market. Summary of the Invention
[0004] In light of this, the present invention provides a system and method for detecting damaged and scratched cigarette cartons. This system utilizes an embedded visual inspection module to perform online machine vision inspection of damaged and scratched cartons, triggering an audible and visual alarm and eliminating defective cartons. This prevents defective cartons from entering the next process and avoids lengthy tracing back due to difficulty in identifying problems. This significantly improves the workshop's ability to control cartons' quality issues.
[0005] The technical solution adopted by the present invention to solve the above technical problems is: The method for detecting damage defects of cigarette rigid cartons includes: S1 strip box image acquisition Capture images of the in-place strip box; During image acquisition, the camera box is illuminated, and the lighting intensity is adaptively adjusted based on the ambient brightness; S2 Image Processing S2.1 Grayscale processing Used to convert the color image collected by S1 into a grayscale image; First, receive and verify the original color image from S1 to ensure that the image format is correct and the data is intact; Then, perform color space conversion to convert the RGB three-channel image into a single-channel grayscale image. Apply the grayscale conversion formula to each pixel and quantize the calculated result into an integer value in the range of 0-255. At the same time, pay special attention to processing the image edges and special areas to avoid information loss. Finally, a single-channel grayscale image containing only brightness information is output; S2.2 Edge Detection Perform edge detection on the S2.1 grayscale image using the Canny edge detection algorithm; its goal is to find an optimal edge detection solution or to find the location with the strongest grayscale intensity change in an image; The steps of the Canny edge detection algorithm are as follows: Denoising: Gaussian filtering is used to smooth the image to remove noise; Gradient: Use the Sobel operator to calculate the gradient magnitude and direction and find the gradient of the image; Non-maximum suppression: Use non-maximum suppression to filter non-edge pixels, retain the maximum value of the gradient intensity at each pixel, and filter out other values; Double threshold: A double threshold method is used to determine possible boundaries. An upper threshold and a lower threshold are set. If a pixel in the image is greater than the upper threshold, it is considered to be a boundary, called a strong boundary. If it is less than the lower threshold, it is considered not to be a boundary. If it is between the upper and lower thresholds, it is considered to be a candidate, called a weak boundary, and requires further processing. Hysteresis threshold: Weak boundaries are tracked based on the hysteresis threshold. Weak boundaries where a certain pixel position is connected to a strong boundary are considered boundaries, and other weak boundaries are deleted. S2.3 Dynamic Binarization S2.3.1 Light compensation preprocessing Calculate local brightness differences in the image in blocks to compensate for uneven lighting and improve the robustness of subsequent binarization; Divide the image into 16×16 blocks and calculate the mean brightness of each block; Taking the global brightness mean as the benchmark, the difference between the brightness of each block and the global brightness mean is used to generate a compensation matrix through bicubic interpolation. The compensation matrix is subtracted from the original image to obtain an image with balanced illumination. S2.3.2 Dynamic Binarization Adopting the adaptive threshold binarization algorithm, the image is divided into the same number of small blocks as the illumination compensation preprocessing. The threshold value of each small block is calculated separately, and then the calculated threshold value is used to segment the small block. The threshold value is dynamically adjusted according to the local brightness of the image. Adaptive threshold type: Gaussian weighted average or mean; S2.3.3 Post-processing optimization Secondary denoising: Use median filtering or Gaussian filtering to eliminate noise; Sharpening enhancement: Enhance edges through unsharp masking and improve the contrast of binary images; S3 feature extraction and image analysis S3.1 Line Recognition Hough transform is used to detect straight lines in the image, and the points in the image space are mapped to the parameter space to find the parameters of the line. For a straight line, the polar coordinate form can be expressed as: [r= x\cdot \cos(\theta)+y \cdot \sin(\theta) ], where (r) is the distance from the origin to the line, and (\theta) is the angle between the line and the x-axis. By transforming the points, the representation of the line in the parameter space can be obtained. The specific steps are: a: After edge detection is performed on the image, the parameter space is initialized, that is, a two-dimensional array accumulator is created to record the number of votes corresponding to each ( (r, \theta) ); b: For each edge point in the image, all possible ( \theta ) values are traversed, the corresponding ( r ) is calculated, and the vote is added to the corresponding position in the accumulator; c: A threshold is set. Only when the value in the accumulator exceeds the threshold, a line is considered to exist at the corresponding position; d: The line parameters are extracted based on the high vote value in the accumulator, and the line is drawn in the original image; e: When the line cannot be found, the threshold value is modified or the angle limit is relaxed to continue detection; S3.2 Dynamic Mask Based on the detected lines and dynamic rectangle tracking algorithm, a dynamic mask area is generated and defects are detected on the image; The Hough transform is used to extract reference lines from the image, and an initial tilted rectangular region is generated based on the line angle and spacing parameters. A Kalman filter is used to establish a five-dimensional state vector containing the center coordinates, length, width, and rotation angle. A prediction-update mechanism is used to achieve real-time tracking of the dynamic mask area. After the tracked dynamic area is normalized through perspective transformation, multi-scale feature analysis is used to detect defects in the image. S3.3 Defect Detection After image processing, defects appear as a region consisting of a group of connected pixels, namely spots; When a spot is detected, it is detected by a rectangle matching algorithm based on coordinate transformation. Through multiple steps, high-precision spatial positioning of the spot is achieved to determine whether the center of the spot is within any rotated rectangle. First, adaptive threshold segmentation and centroid calculation are used to extract the center coordinates of the spots and retain candidate regions that meet the size requirements. Second, for each rotated rectangle, transform the spot coordinates from the image coordinate system to the normalized rectangular local coordinate system centered on the rectangle: Align the center through translation transformation, eliminate angular deviation through rotation transformation, normalize the semi-axis through scale transformation, and obtain the standardized coordinates (x_norm, y_norm) by scaling the rectangle according to its half length and width; The judgment condition is: when |x_norm|<1 and |y_norm|<1, the spot is within the rectangular range; at the same time, the distance threshold D_thresh=0.5 is introduced to calculate the normalized coordinate Euclidean distance ,If d<0.5 and the absolute value of the coordinate is <0.9, it is determined to be a valid match, that is, the detected spot area is within the rectangular range; S3.4 Color Block Feature Analysis When a spot is detected that is not within any rectangular range, its color block characteristics are analyzed; a grading algorithm based on the color block area threshold is used to determine whether it is a defect; By calculating the number of pixels and area of each color block in the image, the color blocks are graded and filtered according to the preset threshold range for defect screening and judgment; a: Convert the image to black and white lines by setting a color threshold, and detect connected areas in the image that meet the color threshold; b: Scan the specified area through ROI detection, find all continuous pixel areas that meet the color conditions, and return the geometric and color feature information of these areas; c: Set the pixel number threshold to filter out color blocks with a pixel number less than the threshold; d: Set the area filtering threshold to filter out color blocks with an area less than the threshold; e: Use the return value of the find_blob function to determine whether it is a defect. S4 test results When spots in the image are determined to be defects, the defect detection results are output to the rejection mechanism and the early warning mechanism; The defect images are displayed synchronously and the defect images are constructed into a defect database.
[0006] In order to solve the above technical problems, the present invention also adopts the following technical solutions: Cigarette rigid carton damage defect detection system, including: An image acquisition unit, which is used to capture images of the in-place strip box, includes a camera component with adjustable shooting angle and an array-type LED light source component with adaptive adjustment of light intensity; The image processing unit is used to perform grayscale processing, edge detection, dynamic binarization processing on the acquired image, and denoise and sharpen the binary image: The image detection unit uses Hough transform to detect straight lines in the image. Based on the detected straight lines and the dynamic rectangle tracking algorithm, it generates a dynamic mask area to detect defects in the image. Then, it uses a rectangle matching algorithm based on coordinate transformation to spatially locate spots in the image. When a spot is detected that is not within any rectangle, it is combined with a grading algorithm based on the color block area threshold to determine whether it is a defect; The result execution unit is used to output the defect detection results to the rejection mechanism, the early warning mechanism and the display mechanism, and to construct the defect images into a real-time updated defect database.
[0007] As an improvement of the above technical solution, the camera assembly and the array LED light source assembly are installed on a detection bracket, and the detection bracket includes a base and a detection head. The base is provided with a fixing hole with a shock-absorbing rubber ring. The detection head and the base are connected by a rotatable adjustable hinge, and a matrix light source window and a camera hole are provided at the front end of the detection head.
[0008] As an improvement to the above technical solution, the array-type LED light source assembly realizes adaptive adjustment of the LED light source illumination intensity according to the ambient brightness conditions through a PWM signal generating circuit.
[0009] As an improvement to the above technical solution, a single-chip microcomputer chip board is integrated on the detection bracket.
[0010] As an improvement to the above technical solution, a WiFi communication module is integrated on the single-chip microcomputer chip board.
[0011] As an improvement to the above technical solution, the specific steps of the dynamic rectangle tracking algorithm include: The Hough transform is used to extract the reference lines in the image, and the initial tilted rectangular area is generated according to the line angle and spacing parameters. The Kalman filter is used to establish a five-dimensional state vector containing the center coordinates, length, width and rotation angle. The real-time tracking of the dynamic mask area is achieved through the prediction-update mechanism. After the tracked dynamic area is normalized by perspective transformation, multi-scale feature analysis is used to detect defects in the image.
[0012] As an improvement to the above technical solution, the specific steps of the rectangle matching algorithm include: First, adaptive threshold segmentation and centroid calculation are used to extract the center coordinates of the spots and retain candidate regions that meet the size requirements. Second, for each rotated rectangle, transform the spot coordinates from the image coordinate system to the normalized rectangular local coordinate system centered on the rectangle: Align the center through translation transformation, eliminate angular deviation through rotation transformation, normalize the semi-axis through scale transformation, and obtain the standardized coordinates (x_norm, y_norm) by scaling the rectangle according to its half length and width; The judgment condition is: when |x_norm|<1 and |y_norm|<1, the spot is within the rectangular range; at the same time, the distance threshold D_thresh=0.5 is introduced to calculate the normalized coordinate Euclidean distance If d < 0.5 and the absolute value of the coordinate is < 0.9, it is determined to be a valid match, that is, the detected spot area is within the rectangular range.
[0013] As an improvement to the above technical solution, the specific steps of the color block area threshold based grading algorithm include: a: Convert the image to black and white lines by setting a color threshold, and detect connected areas in the image that meet the color threshold; b: Scan the specified area through ROI detection, find all continuous pixel areas that meet the color conditions, and return the geometric and color feature information of these areas; c: Set a pixel number threshold to filter out color blocks with a pixel number less than the threshold; d: Set an area filtering threshold to filter out color blocks with an area less than the threshold; e: Use the return value of the find_blob function to determine whether it is a defect.
[0014] At the same time, the present invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the computer program, the steps of the above-mentioned method for detecting damaged defects in cigarette hard strips are implemented.
[0015] At the same time, the present invention also proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the above-mentioned method for detecting damage defects in cigarette hard cartons.
[0016] The beneficial effects brought by the present invention are: The present invention uses embedded visual detection to perform machine vision online detection of damaged and scratched defects in cigarette hard cartons. It is installed and deployed on the side of the carton filling machine outlet and the carton conveyor belt outlet. It can perform real-time detection of damaged and scratched quality problems in cartons, realize sound and light alarm and removal of defective cartons, reduce rework and scrap caused by quality problems, thereby reducing production costs and making product process control develop in the direction of intelligence and digitization.
[0017] The visual inspection algorithm adopted by the present invention is suitable for the surface inspection of hard gift boxes. It cooperates with in-place detection and trigger detection to take a picture when the hard gift box reaches the shooting position. Through the image preprocessing algorithm that can adapt to highly reflective surfaces, it solves the problems of reflective interference and edge interference on the pearlescent paint surface of the hard gift box based on dynamic threshold segmentation and feature enhancement algorithms. It can clearly and unambiguously determine whether there are defects, and will not cause false detection due to the influence of the edges of the hard box. The system runs stably and has high detection accuracy.
[0018] When the real-time captured image is determined to be a defect by the detection method of the present invention, the defect detection result is immediately output to the rejection mechanism and the early warning mechanism; after receiving the sound and light alarm or rejecting the cigarette carton, the operator will judge the carton. If it is confirmed that the carton is damaged or scratched with quality problems, the operator can immediately stop and call a repairman for inspection and repair, so as to avoid the defective cigarette carton from entering the next process, and also avoid long-term tracing due to the difficulty in finding the problem, reduce the probability of problematic products caused by appearance defects of hard gift boxes entering the market, greatly improve the workshop's control over the quality problems of carton defects, improve the equipment operation efficiency and reduce the waste of raw and auxiliary materials caused by large-scale tracing. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 1. It is a schematic flow chart of the method for detecting damage defects of cigarette hard cartons of the present invention; Figure 2 Schematic diagram of the structure of the cigarette hard carton damage defect detection system of the present invention; Figure 3 Schematic diagram of the structure of the detection bracket provided by an embodiment of the present invention; Figure 4 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention; Figure 5 3 is a schematic diagram of the effect of feature extraction and image analysis in step S3 of the defect detection method of the present invention; Figure 6 Collect images of the actual box; Figure 7 Schematic diagram of the effect after image processing; Figure 8 Collect images of the actual box with defects; Figure 9 Schematic diagram of defect results detected based on the method of the present invention. DETAILED DESCRIPTION The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0021] Furthermore, the following description is for purposes of illustration and not limitation, and specific details, such as particular system structures and techniques, are provided to facilitate a thorough understanding of the embodiments of the present invention. However, it will be apparent to those skilled in the art that the present invention may be practiced in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
[0022] Reference Figure 1 The first embodiment of the present invention relates to a method for detecting damage defects in cigarette hard cartons, comprising: S1 strip box image acquisition Capture images of the in-place boxes. To meet different inspection requirements, we mainly capture images of the long sides and QR code sides of rigid boxes, as these are the locations where the boxes are most likely to be damaged during the production process and during transportation. During image acquisition, the camera box is illuminated by emitting white light onto the object, reducing camera exposure time and increasing detection speed. The lighting intensity is adaptively adjusted based on the ambient brightness to ensure stable capture.
[0023] S2 Image Processing S2.1 Grayscale processing Used to convert color images collected by S1 into grayscale images, mainly to achieve goals such as data simplification, feature highlighting, standardization and calculation optimization; First, receive and verify the original color image from S1 to ensure that the image format is correct and the data is intact; Then, perform color space conversion. Use a brightness weighting method based on human eye perception to convert the RGB three-channel image into a single-channel grayscale image. Apply the grayscale conversion formula (Gray = 0.299 × R + 0.587 × G + 0.114 × B) to each pixel and quantize the calculated result into an 8-bit unsigned integer value in the range of 0-255. At the same time, pay special attention to processing image edges and special areas to avoid information loss. Finally, a single-channel grayscale image containing only brightness information is output and saved in a lossless format such as PNG, and relevant processing parameters and metadata are recorded; The processing method is flexibly adjusted according to the image characteristics. After the processing is completed, quality verification is required to ensure that the converted grayscale image retains key features and the histogram distribution is reasonable. The final output grayscale image serves as the standard input for the subsequent image processing process, providing unified and standardized preprocessing results for subsequent steps such as edge detection and binarization.
[0024] S2.2 Edge Detection Edge detection is performed on the S2.1 grayscale image using the Canny edge detection algorithm. The goal is to find an optimal edge detection solution or the location with the strongest grayscale intensity change in an image. The optimal edge detection is evaluated based on three criteria: low error rate, high localization, and minimum response. The steps of the Canny edge detection algorithm are as follows: Denoising: Gaussian filtering is used to smooth the image to remove noise; Gradient: Use the Sobel operator to calculate the gradient magnitude and direction and find the gradient of the image; Non-maximum suppression: Non-maximum suppression is used to filter non-edge pixels, retaining the maximum value of the gradient intensity at each pixel and filtering out other values to make the blurred boundary clear: First, the gradient direction is approximated to one of the following values: 0, 45, 90, 135, 180, 225, 270, and 315, which represent the up, down, left, right, and 45-degree directions, respectively. Then, the gradient intensity of the pixel is compared with the pixels in the positive and negative directions of its gradient. If the pixel has the largest gradient intensity, it is retained; otherwise, it is suppressed (deleted, i.e., set to 0); Double thresholding: A double thresholding method is used to determine possible (potential) edges. If the image after non-maximum suppression still has many noise points, a double thresholding method is used. This method sets an upper threshold and a lower threshold. Pixels in the image that are greater than the upper threshold are considered to be edges (called strong edges). Pixels that are less than the lower threshold are considered not edges. Pixels between the upper and lower thresholds are considered to be candidates (called weak edges) and require further processing. Hysteresis threshold: Tracking boundaries based on the hysteresis threshold, considering weak boundaries connected to a certain pixel position and a strong boundary as boundaries, and deleting other weak boundaries; Figure 6 The image shown is a real-life image of a box. Figure 7 This is the effect picture after the image processing steps mentioned above.
[0025] S2.3 Dynamic Binarization S2.3.1 Light compensation preprocessing Calculate local brightness differences in the image in blocks to compensate for uneven lighting and improve the robustness of subsequent binarization; Divide the image into 16×16 blocks and calculate the mean brightness of each block; Taking the global brightness mean as the benchmark, the difference between the brightness of each block and the global brightness mean is used to generate a compensation matrix through bicubic interpolation. The compensation matrix is subtracted from the original image to obtain an image with balanced illumination.
[0026] S2.3.2 Dynamic Binarization Adaptive threshold binarization method is used to dynamically adjust the threshold according to the local brightness of the image: The image is divided into 16×16 blocks, and the threshold value is calculated for each block separately. The calculated threshold value is then used to segment the block. This ensures that even if a block in the image is darker or brighter due to lighting conditions, the block can still be segmented using the separately calculated reasonable threshold value instead of a global fixed threshold value. The threshold value is dynamically adjusted according to the local brightness of the image, with a larger threshold value corresponding to bright blocks and a smaller threshold value corresponding to dark blocks, thus achieving a good segmentation effect. Adaptive threshold type: Gaussian weighted average or mean; Parameter optimization: blockSize (neighborhood size) is an odd number, and C (offset constant) is fine-tuned according to the scene.
[0027] S2.3.3 Post-processing optimization Secondary denoising: Use median filtering (medianBlur) or Gaussian filtering (GaussianBlur) to remove noise; Sharpening enhancement: Enhance edges and improve the contrast of binary images through unsharp masking (USM).
[0028] S3 feature extraction and image analysis S3.1 Line Recognition Detect straight lines in the image through Hough transform; Map the points in the image space to the parameter space to find the parameters of the line. For a line, the polar coordinate form can be expressed as: [r = x\cdot \cos(\theta) + y \cdot \sin(\theta) ], where (r) is the distance from the origin to the line, and (\theta) is the angle between the line and the x-axis. By transforming the points, the line can be represented in the parameter space. The specific steps are: a: After edge detection calculations are performed on the image, the parameter space is initialized, that is, a two-dimensional array (accumulator) is created to record the number of votes corresponding to each ( (r, \theta) ); b: For each edge point in the image, all possible ( \theta ) values are traversed, the corresponding ( r ) is calculated, and the vote is added to the corresponding position in the accumulator; c: A threshold is set. Only when the value in the accumulator exceeds the threshold, a straight line is considered to exist at the corresponding position; d: The line parameters are extracted based on the high vote value in the accumulator, and the line is drawn in the original image; e: When the line cannot be found, the threshold value can be modified or the angle limit can be relaxed to continue detection.
[0029] S3.2 Dynamic Mask Based on the detected straight lines and dynamic rectangle tracking algorithm, a dynamic mask area is generated and defects are detected on the image to achieve adaptive masking of the interference area; The reference straight line extracted from the image using Hough transform is used to generate the initial tilted rectangular area (RotatedRect) according to the straight line angle and spacing parameters, as shown in the following example: Figure 5 The green rectangular box shown in the figure (the area not judged); the Kalman filter is used to establish a five-dimensional state vector containing the center coordinates, length, width and rotation angle, and the real-time tracking of the mask area is achieved through the prediction-update mechanism. The process noise matrix Q and the observation noise matrix R are strictly calibrated. After the dynamic area obtained by tracking is normalized by perspective transformation, multi-scale feature analysis is used to detect defects in the image.
[0030] S3.3 Defect Detection After image processing, defects appear as a region consisting of a group of connected pixels, namely spots. At a specific scale, spots are local maximum or minimum areas of grayscale / color values.
[0031] When a spot is detected, it is detected through coordinate transformation and rectangle matching algorithm, and high-precision spatial positioning of the spot is achieved through multiple steps to determine whether the center of the spot is within any rotated rectangle; First, adaptive threshold segmentation and centroid calculation are used to extract the center coordinates of the spots, and candidate regions with an area of 5-200 pixels are filtered and retained; Specific steps: Adaptive threshold segmentation: using OTSU or local threshold method; Output binary image: spot area is white (255), background is black (0); Connected region labeling: 8-connected region analysis algorithm is used to assign a unique label to each connected region; Calculate region properties: area, centroid, bounding box; Area filtering: remove noise points with an area of less than 5 pixels, exclude non-spot areas with an area of more than 200 pixels, and retain candidate spots that meet the size requirements; Secondly, in order to eliminate the influence of target pose changes on spot positions and provide geometrically invariant descriptors for subsequent recognition / matching, a rotationally invariant standard coordinate system is established; For each rotated rectangle (including center x_k, y_k, width w_k, height h_k and rotation angle θ_k), transform the spot coordinates from the image coordinate system to the normalized rectangular local coordinate system centered on the rectangle: Align the center through translation transformation, eliminate angular deviation through rotation transformation, normalize the semi-axis through scale transformation, and obtain standardized coordinates (x_norm, y_norm) by scaling according to the half length and width of the rectangle.
[0032] Specific steps for spot coordinate transformation of each rotated rectangle: Translation alignment center: calculate relative coordinates: dx = x-x_k, dy = y-y_k; Rotation transformation: Construct the rotation matrix: ; Apply a rotation transformation: align the rectangle's major axes with the coordinate axes: x_rot = dx*cosθ_k + dy*sinθ_k; y_rot = -dx*sinθ_k + dy*cosθ_k; Semi-axis scaling normalization: Calculate the scaling factor: s_x = w_k / 2 / / half length of X axis; s_y = h_k / 2 / / Y-axis half length; Get the normalized coordinates: x_norm = x_rot / s_x, y_norm = y_rot / s_y; Final coordinate range: [-1, 1]×[-1, 1]; The judgment condition is: when |x_norm|<1 and |y_norm|<1, the spot is within the rectangular range; at the same time, the distance threshold D_thresh=0.5 is introduced to calculate the normalized coordinate Euclidean distance If d < 0.5 and the absolute value of the coordinate is < 0.9, it is determined to be a valid match, that is, the detected spot area is within the rectangular range.
[0033] The key advantages of this step algorithm are: Rotation / translation invariance: the same pattern has the same coordinates in different poses; Scale consistency: patterns of different sizes are normalized to the same coordinate range; and feature stability.
[0034] S3.4 Color Block Feature Analysis When a spot is detected that is not within any rectangular range, its color block characteristics are analyzed and a grading algorithm based on the color block area threshold is used to determine whether it is a defect. Parameters such as defect detection range, sensitivity, and minimum defect size can be configured as needed.
[0035] By calculating the number of pixels and area of each color block in the image, the color blocks are graded and filtered according to the preset threshold range for defect screening and judgment; a: By setting the threshold, the image is converted into black and white lines to facilitate defect judgment. The color threshold thresholds is set to [(100,255)], and the connected areas in the image that meet the color threshold are detected; b: ROI region of interest detection, such as Figure 5 The red rectangle shown is the ROI detection area. The scanning specified area is set to (2, 59, 256, 78). Only this area is judged to avoid false detection caused by the surrounding environment. All continuous pixel areas that meet the color conditions are found, and the geometric and color feature information of these areas is returned; c: The pixel number threshold pixels_threshold is set to 5 to filter out color blocks with less than 5 pixels; d: The area filtering threshold area_threshold is set to 5 to filter out color blocks with an area less than 5; e: Use the return value of find_blob function to determine whether it is a defect and display the detection result.
[0036] Under normal circumstances, except for the dynamic mask part, the rest of the binary processed area in the detection area frame is all black; When a white blob that meets the area threshold condition is detected using the find_blob function, it is judged as a defect. Figure 8 Collect images of the actual box with defects. Figure 9 The white spots near the center straight line shown in the image are the detected defects.
[0037] S4 test results When spots in the image are determined to be defects, the defect detection results are output to the rejection mechanism and the sound and light alarm; Defect images are synchronously transmitted to the auxiliary machine's industrial display, allowing operators to intuitively view them, reminding them to judge the actual quality and analyze the causes, and promptly call maintenance workers for targeted repairs to identify possible equipment problems. The defect images are constructed into a defect image database to cover surface defect features under different lighting conditions.
[0038] Based on the constructed defect image database, this embodiment can also: Centralizing and storing scattered defect images to form a standardized dataset facilitates rapid comparison and recall during subsequent algorithm training, testing, and iteration. This avoids inefficiencies caused by data fragmentation, allows rapid verification of new algorithms for scratch detection in low light, and shortens development cycles. By covering defect samples under varying lighting and camera angles, the database enables the algorithm to learn more essential defect characteristics, supporting the generalization capabilities of machine learning. Furthermore, the defect database supports defect classification and traceability. The database can correlate defect type, size, location, and other information to help locate production issues (e.g., if defects in a batch of products are concentrated in the same area).
[0039] Reference Figure 2 The second embodiment of the present invention relates to a cigarette hard carton damage defect detection system, comprising An image acquisition unit, which is used to capture images of the in-place strip box at different positions, includes a camera component with adjustable shooting angle and an array-type LED light source component with adaptive adjustment of light intensity; The image processing unit is used to perform grayscale processing, edge detection, dynamic binarization processing on the acquired image, and denoise and sharpen the binary image: The image detection unit uses Hough transform to detect straight lines in the image. Based on the detected straight lines and the dynamic rectangle tracking algorithm, it generates a dynamic mask area to detect defects in the image. Then, it uses a rectangle matching algorithm based on coordinate transformation to spatially locate spots in the image. When a spot is detected that is not within any rectangle, it is combined with a grading algorithm based on the color block area threshold to determine whether it is a defect; The result execution unit is used to output the defect detection results to the rejection mechanism, the sound and light alarm component and the display component, and construct the defect image into a real-time updated defect database.
[0040] As an improvement of this embodiment, the camera assembly and the array LED light source assembly are installed on a detection bracket. Figure 3 The detection bracket includes a base and a detection head. The base is provided with a fixing hole with a shock-absorbing rubber ring. The detection head and base are connected by a rotatable adjustable hinge. The front end of the detection head is provided with a matrix light source window and a camera aperture. Component 1 in the figure is a locking knob for the detection head to rotate left and right, and is tightened by threads. Component 2 in the figure is the rotation axis for the detection head's pitch angle, which enables the pitch rotation of the lens. Component 3 in the figure is a locking knob for the detection head's pitch angle adjustment, which is tightened by threads. Component 4 in the figure is the rotation axis for the detection head's left and right rotation angle, which enables the left and right rotation of the lens.
[0041] The array-type LED light source assembly uses a PWM signal generation circuit to adaptively adjust the LED light source light intensity according to the ambient brightness conditions. When the ambient light increases, the LED light source automatically dims; when the ambient light decreases, the LED light source gradually brightens, ensuring shooting stability.
[0042] As an improvement of this embodiment, the detection bracket is integrated with a single-chip microcomputer chip board, and the single-chip microcomputer chip board is integrated with a WiFi communication module, which is convenient for later integrated remote debugging in the workshop and increases the centralized management and deployment and modification configuration capabilities.
[0043] Figure 4 FIG is a schematic diagram of an electronic device 10 provided by another embodiment of the present invention. Figure 4 As shown, the electronic device 10 of this embodiment includes: a processor 11, a memory 12, and a computer program 13 stored in the memory 12 and executable on the processor 11, such as a program for detecting a damaged defect in a cigarette hard carton. When the processor 11 executes the computer program 13, the steps in the above-mentioned embodiments of the method for detecting a damaged defect in a cigarette hard carton are implemented, such as Figure 1 Steps shown.
[0044] For example, the computer program 13 may be divided into one or more modules / units, one or more of which are stored in the memory 12 and executed by the processor 11 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, and the instruction segments are used to describe the execution process of the computer program 13 in the electronic device 10.
[0045] The electronic device 10 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device 10 may include, but is not limited to, a processor 11 and a memory 12. Those skilled in the art will understand that Figure 4 This is merely an example of the electronic device 10 and does not constitute a limitation of the electronic device 10. The electronic device 10 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 10 may also include input and output devices, network access devices, buses, etc.
[0046] The processor 11 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0047] The memory 12 can be an internal storage unit of the electronic device 10, such as the hard disk or memory of the electronic device 10. The memory 12 can also be an external storage device of the electronic device 10, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the electronic device 10. Furthermore, the memory 12 can include both the internal storage unit of the electronic device 10 and an external storage device. The memory 12 is used to store computer programs and other programs and data required by the electronic device 10. The memory 12 can also be used to temporarily store data that has been output or is about to be output.
[0048] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0049] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0050] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0051] In the embodiments provided by the present invention, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely schematic. For example, the division of modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0052] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0053] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0054] If the integrated module / unit is implemented as a software functional unit and sold or used as a standalone product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the process steps in the above-mentioned method embodiments by using a computer program to instruct the relevant hardware. The computer program can be stored in a computer-readable storage medium. When executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, mobile hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunications signals, and software distribution media.
[0055] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A method for detecting damaged defects in cigarette rigid cartons, characterized by: include S1 strip box image acquisition Capture images of the in-place strip box; During image acquisition, the camera box is illuminated, and the lighting intensity is adaptively adjusted based on the ambient brightness; S2 Image Processing S2.1 Grayscale processing Used to convert the color image collected by S1 into a grayscale image; S2.2 Edge Detection Perform edge detection on the S2.1 grayscale image using the Canny edge detection algorithm; Its goal is to find an optimal edge detection solution or to find the location where the grayscale intensity changes most strongly in an image; S2.3 Dynamic Binarization S2.3.1 Light compensation preprocessing Calculate local brightness differences in the image in blocks to compensate for uneven lighting; Divide the image into N×M blocks and calculate the mean brightness of each block; Taking the global brightness mean as the benchmark, the difference between the brightness of each block and the global brightness mean is used to generate a compensation matrix through bicubic interpolation. The compensation matrix is subtracted from the original image to obtain an image with balanced illumination. S2.3.2 Dynamic Binarization Adopting the adaptive threshold binarization algorithm, the image is divided into N×M blocks, the threshold of each block is calculated separately, and then the block is segmented using the calculated threshold, and the threshold is dynamically adjusted according to the local brightness of the image; S2.3.3 Post-processing optimization Secondary denoising: Use median filtering or Gaussian filtering to eliminate noise; Sharpening enhancement: Enhance edges through unsharp masking and improve the contrast of binary images; S3 feature extraction and image analysis S3.1 Line Recognition Hough transform is used to detect straight lines in an image. Points in the image space are mapped to the parameter space to find the parameters of the line. For a line, the polar coordinate form can be expressed as: [r = x\cdot \cos(\theta) + y \cdot \sin(\theta) ], where (r) is the distance from the origin to the line, and (\theta) is the angle between the line and the x-axis. By transforming the points, the line can be represented in the parameter space. S3.2 Dynamic Mask Based on the detected lines and dynamic rectangle tracking algorithm, a dynamic mask area is generated and defects are detected on the image; The Hough transform is used to extract reference lines from the image, and an initial tilted rectangular region is generated based on the line angle and spacing parameters. A Kalman filter is used to establish a five-dimensional state vector containing the center coordinates, length, width, and rotation angle. A prediction-update mechanism is used to achieve real-time tracking of the dynamic mask area. After the tracked dynamic area is normalized through perspective transformation, multi-scale feature analysis is used to detect defects in the image. S3.3 Defect Detection After image processing, defects appear as a region consisting of a group of connected pixels, namely spots; When a spot is detected, it is detected by a rectangle matching algorithm based on coordinate transformation. Through multiple steps, high-precision spatial positioning of the spot is achieved to determine whether the center of the spot is within any rotated rectangle. First, adaptive threshold segmentation and centroid calculation are used to extract the center coordinates of the spots and retain candidate regions that meet the size requirements. Second, for each rotated rectangle, transform the spot coordinates from the image coordinate system to the normalized rectangular local coordinate system centered on the rectangle: Align the center through translation transformation, eliminate angular deviation through rotation transformation, normalize the semi-axis through scale transformation, and obtain the standardized coordinates (x_norm, y_norm) by scaling the rectangle according to its half length and width; The judgment condition is: when |x_norm|<1 and |y_norm|<1, the spot is within the rectangular range; at the same time, the distance threshold D_thresh=0.5 is introduced to calculate the normalized coordinate Euclidean distance ,If d<0.5 and the absolute value of the coordinate is <0.9, it is determined to be a valid match, that is, the detected spot area is within the rectangular range; S3.4 Color Block Feature Analysis When a spot is detected that is not within any rectangular range, its color block characteristics are analyzed; a grading algorithm based on the color block area threshold is used to determine whether it is a defect; By calculating the number of pixels and area of each color block in the image, the color blocks are graded and filtered according to the preset threshold range for defect screening and judgment; a: Convert the image to black and white lines by setting a color threshold, and detect connected areas in the image that meet the color threshold; b: Scan the specified area through ROI detection, find all continuous pixel areas that meet the color conditions, and return the geometric and color feature information of these areas; c: Set the pixel number threshold to filter out color blocks with a pixel number less than the threshold; d: Set the area filtering threshold to filter out color blocks with an area less than the threshold; e: Use the return value of the find_blob function to determine whether it is a defect. S4 test results When spots in the image are determined to be defects, the defect detection results are output to the rejection mechanism and the early warning mechanism; The defect images are displayed synchronously and the defect images are constructed into a defect database.
2. Cigarette hard carton damage defect detection system, characterized by: include An image acquisition unit, which is used to capture images of the in-place strip box at different positions, includes a camera component with adjustable shooting angle and an array-type LED light source component with adaptive adjustment of light intensity; The image processing unit is used to perform grayscale processing, edge detection, dynamic binarization processing on the acquired image, and denoise and sharpen the binary image: The image detection unit uses Hough transform to detect straight lines in the image. Based on the detected straight lines and the dynamic rectangle tracking algorithm, it generates a dynamic mask area to detect defects in the image. Then, it uses a rectangle matching algorithm based on coordinate transformation to spatially locate spots in the image. When a spot is detected that is not within any rectangle, it is combined with a grading algorithm based on the color block area threshold to determine whether it is a defect; The result execution unit is used to output the defect detection results to the rejection mechanism, the early warning mechanism and the display mechanism, and to construct the defect images into a real-time updated defect database.
3. The cigarette hard carton damage defect detection system according to claim 2, characterized in that: The camera assembly and array LED light source assembly are installed on a detection bracket, which includes a base and a detection head. The base is provided with a fixing hole with a shock-absorbing rubber ring. The detection head and the base are connected by a rotatable adjustable hinge. The front end of the detection head is provided with a matrix light source window and a camera hole.
4. The cigarette hard carton damage defect detection system according to claim 2, characterized in that: The array-type LED light source assembly uses a PWM signal generation circuit to adaptively adjust the illumination intensity of the LED light source according to the ambient brightness conditions.
5. The cigarette hard carton damage defect detection system according to claim 3, characterized in that: The detection bracket is integrated with a single-chip microcomputer chip board; The single chip microcomputer chip board is integrated with a WiFi communication module.
6. The cigarette hard carton damage defect detection system according to claim 2, characterized in that: The specific steps of the dynamic rectangle tracking algorithm include: The Hough transform is used to extract the reference lines in the image, and the initial tilted rectangular area is generated according to the line angle and spacing parameters. The Kalman filter is used to establish a five-dimensional state vector containing the center coordinates, length, width and rotation angle. The real-time tracking of the dynamic mask area is achieved through the prediction-update mechanism. After the tracked dynamic area is normalized by perspective transformation, multi-scale feature analysis is used to detect defects in the image.
7. The cigarette rigid carton damage defect detection system according to claim 2, characterized in that: The specific steps of the rectangle matching algorithm include: First, adaptive threshold segmentation and centroid calculation are used to extract the center coordinates of the spots and retain candidate regions that meet the size requirements. Second, for each rotated rectangle, transform the spot coordinates from the image coordinate system to the normalized rectangular local coordinate system centered on the rectangle: Align the center through translation transformation, eliminate angular deviation through rotation transformation, normalize the semi-axis through scale transformation, and obtain the standardized coordinates (x_norm, y_norm) by scaling the rectangle according to its half length and width; The judgment condition is: when |x_norm|<1 and |y_norm|<1, the spot is within the rectangular range; at the same time, the distance threshold D_thresh=0.5 is introduced to calculate the normalized coordinate Euclidean distance If d < 0.5 and the absolute value of the coordinate is < 0.9, it is determined to be a valid match, that is, the detected spot area is within the rectangular range.
8. The cigarette hard carton damage defect detection system according to claim 2, characterized in that: The specific steps of the color block area threshold based grading algorithm include: a: Convert the image to black and white lines by setting a color threshold, and detect connected areas in the image that meet the color threshold; b: Scan the specified area through ROI detection, find all continuous pixel areas that meet the color conditions, and return the geometric and color feature information of these areas; c: Set a pixel number threshold to filter out color blocks with a pixel number less than the threshold; d: Set an area filtering threshold to filter out color blocks with an area less than the threshold; e: Use the return value of the find_blob function to determine whether it is a defect.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the cigarette hard carton damage defect detection method according to claim 1 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for detecting damaged defects in cigarette hard cartons as claimed in claim 1 are implemented.
Citation Information
Cited By
Photomask plate defect detection method of photoetching machine
CN121091595A
Steel surface defect online detection method, device and system and storage medium
CN121453831A
Defect detection method and system based on multi-factor image processing and storage medium
CN122597283A