AI vision flaw sorting method and system for bamboo stick production

By using an AI-based visual defect sorting method, which employs gray-level gradient co-occurrence matrix and multi-scale analysis technology, the method detects subtle texture defects on the surface of bamboo sticks and generates a comprehensive defect index. This solves the problems of detection accuracy and consistency in bamboo stick production and achieves efficient and accurate defect sorting.

CN122156152APending Publication Date: 2026-06-05GUILIN BAMBOO FOREVER TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUILIN BAMBOO FOREVER TECH CO LTD
Filing Date
2026-03-05
Publication Date
2026-06-05

Smart Images

  • Figure CN122156152A_ABST
    Figure CN122156152A_ABST
Patent Text Reader

Abstract

The application provides an AI visual flaw sorting method and system for bamboo stick production, wherein the sorting method comprises the following steps: obtaining an original image containing surface texture details of the bamboo stick, and generating a surface texture change map; dividing the surface texture change map into a high saliency area; determining a threshold standard, and detecting a potential defect area; calculating the potential defect area to obtain a defect area contour extraction result; performing depth level classification; extracting a region shape feature of the defect area contour extraction result, combining the depth level classification, calculating a comprehensive defect index, and performing flaw sorting. The application classifies and sorts the bamboo stick by calculating the region shape feature of the defect area and combining the depth level classification, can accurately sort the flawed bamboo stick according to the difference in depth or distribution density, and can accurately match the quality inspection requirements of different application scenes such as food grade and load bearing type by using the image recognition technology, dynamically adjusting the threshold and flexibly adjusting the sorting standard.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of defect sorting technology, and in particular to an AI visual defect sorting method and system for bamboo skewer production. Background Technology

[0002] In modern manufacturing, bamboo skewer production is a traditional yet crucial sector, where product quality directly impacts food safety and user experience, holding undeniable key value. With rising consumer demand, even minor surface defects in bamboo skewers have become significant factors influencing product competitiveness. However, achieving efficient and accurate defect detection through intelligent methods remains a critical bottleneck for the industry.

[0003] Currently, defect detection in bamboo skewer production largely relies on manual visual inspection or simple mechanical equipment. This method is not only inefficient but also easily affected by subjective factors, especially when dealing with subtle variations in the surface texture of bamboo skewers, making it difficult to guarantee detection accuracy and consistency. A deeper problem is that existing methods often cannot adapt to the complexity of the natural fibrous structure of bamboo skewers, lacking the ability to deeply analyze defect characteristics. This leads to many potential problems being overlooked, affecting the overall quality of the product.

[0004] Texture defects on the surface of bamboo skewers are caused by wear on processing tools or the inherent characteristics of the material. These defects are extremely subtle visually, and ordinary equipment cannot distinguish clear texture details. When texture variations are ignored, another challenge arises: it is impossible to accurately determine the degree and type of defects, such as differences in depth or distribution density. This directly leads to inaccurate classification of defects during the sorting process. Summary of the Invention

[0005] In view of this, the technical problem to be solved by the present invention is to provide an AI visual defect sorting method and system for bamboo skewer production, which can accurately sort defective bamboo skewers according to defect classification.

[0006] The technical solution of this invention is implemented as follows: This invention proposes an AI-based visual defect sorting method for bamboo skewer production, comprising the following steps: S1. Obtain the original image containing details of the surface texture of the bamboo stick, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; S2. Perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and perform smoothing to delineate highly saliency regions; S3. Determine the threshold standard based on historical data, and accurately detect potential defect areas in highly significant regions through gradient features; S4. Calculate the potential defect area by edge tracking to obtain the defect area contour extraction result; S5. Obtain the defect depth distribution analysis data of the defect region contour extraction results through grayscale contrast analysis and internal pixel clustering, and perform depth level classification. S6. Extract the regional shape features of the defect region contour extraction results by calculating the aspect ratio and irregularity of the contour, and calculate the comprehensive defect index by combining the depth level classification. S7. Sorting bamboo skewers for defects based on the comprehensive defect index.

[0007] Preferably, S1 specifically includes: S101. Acquire an original image containing details of the surface texture of the bamboo skewer using an image acquisition device; S102. Convert the original image into a grayscale image, calculate the gradient magnitude and direction of the grayscale image and quantize the grayscale and gradient, and construct a grayscale-gradient co-occurrence matrix; extract texture features from the grayscale-gradient co-occurrence matrix to generate a surface texture change map.

[0008] Preferably, S2 specifically includes: S201. Use multi-scale analysis methods to analyze the surface texture change map at different scales, decompose the texture details at multiple scales, and obtain the gradient change map. S202. Perform directional analysis on the texture details at each scale in the gradient change map, determine the dominant texture direction, and mark areas with abnormal directions. S203. Smooth the gradient change map and divide the highly significant region by combining the directional anomaly region.

[0009] Preferably, S3 specifically includes: S301. Determine the dynamic threshold standard based on historical data; S302. Perform gradient feature accurate detection on highly significant regions and mark potential defect regions that exceed the dynamic threshold standard.

[0010] Preferably, S5 specifically includes: S501. Based on the defect area contour extraction results, analyze the regional difference data between the defect area and the normal area through grayscale contrast analysis. S502. Group the pixels inside the defect area according to grayscale intervals by internal pixel clustering, and obtain the depth distribution data corresponding to each grayscale interval; and classify the depth level by using the depth distribution data. S503. Based on regional difference data and depth distribution data, obtain the overall depth distribution characteristics of the defect area, and classify the depth level according to the depth level division.

[0011] Preferably, S6 specifically includes: S601. Extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour. S602. A weighted average algorithm is used to calculate the depth level and regional shape characteristics to obtain the comprehensive defect index.

[0012] Preferably, S7 specifically includes: The comprehensive defect index is compared with a preset range, and bamboo skewers that exceed the preset range are sorted for defects.

[0013] This invention also proposes an AI-based visual defect sorting system for bamboo skewer production, comprising: Acquisition module: Used to acquire the original image containing details of the surface texture of the bamboo skewer, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; The segmentation module is used to perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and to perform smoothing processing to segment out highly saliency regions; The generation module is used to determine threshold standards based on historical data and accurately detect potential defect areas in highly significant regions through gradient features. The first calculation module is used to calculate the potential defect regions in the priority list through edge tracking and obtain the defect region contour extraction results; The classification module is used to obtain defect depth distribution analysis data of the defect region contour extraction results through grayscale contrast analysis and internal pixel clustering, and to perform depth level classification. The second calculation module is used to extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour, and calculate the comprehensive defect index by combining the depth level classification. The sorting module is used to sort bamboo sticks for defects based on the comprehensive defect index.

[0014] Preferably, the acquisition module is specifically used for: Obtain raw images containing details of the surface texture of bamboo skewers using image acquisition equipment; The original image is converted into a grayscale image. The gradient magnitude and direction of the grayscale image are calculated and the grayscale and gradient are quantized to construct a grayscale-gradient co-occurrence matrix. Texture features are extracted from the grayscale-gradient co-occurrence matrix to generate a surface texture change map.

[0015] Preferably, the modules are divided, specifically for: The surface texture variation map is analyzed at different scales using a multi-scale analysis method, and the texture details at multiple scales are decomposed to obtain the gradient variation map. Directional analysis is performed on the texture details at each scale in the gradient change map to determine the dominant texture direction and mark areas with abnormal directions. The gradient change map is smoothed, and highly significant regions are identified by combining the abnormal directional regions.

[0016] As can be seen, the AI ​​visual defect sorting method and system for bamboo skewer production proposed in this invention performs image recognition on the original image with texture details on the surface of the bamboo skewer to calculate potential defect areas; and sorts and classifies bamboo skewers for defects by calculating the regional shape features of the defect areas and combining depth level classification. It can accurately sort defective bamboo skewers according to different depths or distribution density differences. Attached Figure Description

[0017] Figure 1 This is a flowchart of the AI ​​visual defect sorting method for bamboo skewer production proposed in an embodiment of the present invention; Figure 2 This is a schematic diagram of the aggregation model system in federated learning proposed in an embodiment of the present invention. Detailed Implementation

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

[0019] like Figure 1 As shown in the figure, this invention proposes an AI-based visual defect sorting method for bamboo skewer production, comprising the following steps: S1. Obtain the original image containing details of the surface texture of the bamboo stick, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; S2. Perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and perform smoothing to delineate highly saliency regions; S3. Determine the threshold standard based on historical data, and accurately detect potential defect areas in highly significant regions through gradient features; S4. Calculate the potential defect area by edge tracking to obtain the defect area contour extraction result; S5. Obtain the defect depth distribution analysis data of the defect region contour extraction results through grayscale contrast analysis and internal pixel clustering, and perform depth level classification. S6. Extract the regional shape features of the defect region contour extraction results by calculating the aspect ratio and irregularity of the contour, and calculate the comprehensive defect index by combining the depth level classification. S7. Sorting bamboo skewers for defects based on the comprehensive defect index.

[0020] The AI ​​visual defect sorting method, system, and computer-readable storage medium for bamboo skewer production proposed in this invention perform image recognition on the original image of the bamboo skewer surface with texture details to calculate potential defect areas; and by calculating the regional shape features of the defect areas and combining depth level classification, the bamboo skewers are classified and sorted for defects. It can accurately sort defective bamboo skewers based on different depths or distribution densities.

[0021] In a preferred embodiment of the present invention, S1 specifically includes: S101. Acquire an original image containing details of the surface texture of the bamboo skewer using an image acquisition device; S102. Convert the original image into a grayscale image, calculate the gradient magnitude and direction of the grayscale image and quantize the grayscale and gradient, and construct a grayscale-gradient co-occurrence matrix; extract texture features from the grayscale-gradient co-occurrence matrix to generate a surface texture change map.

[0022] Specifically, the image acquisition equipment can be an industrial-grade high-resolution camera, paired with a macro lens, to ensure clear capture of micron-level texture details on the surface of bamboo skewers (such as bamboo fiber direction, cracks, and defects).

[0023] The gray-level-gradient co-occurrence matrix is ​​a two-dimensional statistical model that integrates image gray-level information and gradient information. Its core is to establish the correlation mapping relationship between the two by quantifying the frequency of occurrence of gray-level-gradient level combinations in the texture image of bamboo sticks, thereby accurately representing the essential features of bamboo stick texture.

[0024] First, the original image is converted into a grayscale image. Since the red, green, and blue channels of a color image are redundant, converting it into a single-channel grayscale image can reduce the amount of computation and focus on the differences in brightness of the bamboo skewer texture, such as the difference in brightness between normal fibers and cracks.

[0025] The gradient reflects the strength and direction of pixel grayscale changes, accurately capturing details such as the edges of bamboo skewer fibers and crack boundaries. That is, the more drastic the change, the stronger the gradient. The gradient magnitude and direction of a grayscale image can be calculated by analyzing the grayscale image using the Sobel operator algorithm. This can yield the gradient magnitude that reflects the clarity of the texture edges and the gradient direction that reflects the texture direction, such as the extension direction of bamboo fibers.

[0026] Gray quantization: The gray range of 0-255 is divided into 8-32 levels. In a preferred embodiment of this application, the gray range can be divided into 16 levels, each level corresponding to a gray range. Gradient quantization: First, the largest gradient value in the image is found, and then the gradient range is divided into the same levels as the gray range. Dividing continuous gray levels and gradient values ​​into a finite number of levels can reduce the complexity of subsequent calculations and avoid the influence of small fluctuations on the results.

[0027] Constructing a gray-level-gradient co-occurrence matrix establishes a correlation between gray-level and gradient levels. The frequency of their combinations can be statistically analyzed in matrix form, visually representing texture characteristics, such as the concentrated combinations of normal fibers and the dispersed combinations of cracks. Key information such as energy and entropy can be obtained from the matrix; energy represents texture uniformity, with higher values ​​indicating more regular textures; entropy represents texture complexity, with higher values ​​indicating a greater probability of defects.

[0028] Key features such as energy and entropy are extracted from the matrix to generate texture change maps, and then visualized images are generated to intuitively display the texture changes.

[0029] In a preferred embodiment of the present invention, S2 specifically includes: S201. Use multi-scale analysis methods to analyze the surface texture change map at different scales, decompose the texture details at multiple scales, and obtain the gradient change map. S202. Perform directional analysis on the texture details at each scale in the gradient change map, determine the dominant texture direction, and mark areas with abnormal directions. S203. Smooth the gradient change map and divide the highly significant region by combining the directional anomaly region.

[0030] In detail, different scales can capture texture features of varying sizes. Large scales reveal the overall fiber direction, while small scales can locate minute cracks. This decomposition comprehensively covers the texture information of the bamboo skewer. This application employs multi-scale analysis methods, such as Gaussian pyramids, to analyze surface texture changes across multiple scale dimensions, breaking down the texture details corresponding to each scale, and finally integrating them to obtain a gradient change map reflecting the intensity of texture changes at each scale. The number of scales can be 3-5: small scales are used to capture minute cracks, medium scales to observe fiber integrity, and large scales to grasp the overall direction, avoiding excessive computation due to too many scales or missing crucial details due to too few.

[0031] Since the texture of bamboo skewers, such as bamboo fibers, has a clear dominant direction, areas with abnormal orientation are likely to have defects, such as fiber breaks or scratches, and need to be accurately marked. By analyzing the texture details at each scale in the gradient change map, the directional characteristics are analyzed separately to comprehensively determine the dominant direction of the entire bamboo skewer texture; areas that deviate too much from the dominant direction are marked as areas with abnormal orientation.

[0032] Smoothing the gradient change map can eliminate noise interference. Combined with directional anomaly regions, this allows for the identification of highly significant regions with a high probability of defects. In this application, the gradient change map can be processed with mean filtering to reduce the impact of random noise. Furthermore, by combining this with the already marked directional anomaly regions, areas with drastic texture changes and directional anomalies can be classified as highly significant regions.

[0033] For example, a Gaussian pyramid + multi-scale gradient fusion method can be used to smooth the image with Gaussian kernels at different scales and decompose the texture details at the corresponding scales; use large scale to capture macroscopic defects and small scale to capture microscopic defects, then use gradient calculation to quantify the intensity of texture changes, and finally fuse multi-scale gradient information to obtain a gradient change map.

[0034] In one specific embodiment of this application, a gradient change map can be generated in the following manner; First, set the scale: Select three hierarchical scales that are suitable for the defect size of bamboo skewers; Small scale: Gaussian kernel 3×3, standard deviation σ=0.5, used to capture fine scratches and micro cracks (width < 0.1mm, length < 5mm). Mesoscale: Gaussian kernel 5×5, standard deviation σ=1.0, used to capture conventional cracks and medium scratches (width 0.1~0.5mm, length 5~15mm). Large scale (Gaussian kernel 7×7, standard deviation σ=1.5, used to capture long cracks and local notches (width>0.5mm, length>15mm).

[0035] Gaussian blurring was performed using the three sets of Gaussian kernels mentioned above to obtain three smooth images of different scales, thus achieving layering of texture details.

[0036] Next, gradient calculation is performed: For each smoothed image, the Sobel operator is used to calculate the gradient information in the horizontal (x-direction) and vertical (y-direction) directions respectively. Then, by combining the gradient results in these two directions, the gradient magnitude of each pixel is further calculated to generate a gradient magnitude map. The magnitude of the gradient magnitude can directly reflect the severity of the texture change. The larger the magnitude, the more obvious the texture change in that area, and it is more likely to correspond to the edge location of the defect.

[0037] Finally, the gradient change map is obtained by weighted fusion: Since the three gradient magnitude maps at different scales each focus on defects of different sizes—with the small scale focusing on the microscopic and the large scale focusing on the macroscopic—single-scale maps have limitations. Small-scale maps are susceptible to noise interference, while large-scale maps are prone to missing small micro-defects. Weighted fusion can integrate the advantages of each scale, allowing the final gradient map to retain the texture details of microscopic defects while highlighting the edge features of macroscopic defects, thus avoiding the problems of missed and false detections in single-scale analysis.

[0038] Weights are assigned based on the priority of bamboo skewer defect detection. The weight for small scales can be set to the highest of 0.4 because microscopic defects such as fine scratches and micro-cracks are easily ignored and their gradient signals need to be strengthened. The weight for medium scales is set to a middle value of 0.35, corresponding to the most common defects such as conventional cracks and medium scratches, balancing the signal contributions of different scales. The weight for large scales is set to the lowest value of 0.25 because long cracks and local gaps are already quite obvious in single-scale images, and their features can be preserved without excessive weighting, while avoiding over-amplification of noise in the macroscopic area.

[0039] First, multiply the three gradient magnitude maps by their corresponding weights: 0.4 for each pixel value in the small-scale map, 0.35 for the medium-scale map, and 0.25 for the large-scale map. Then, add the pixel values ​​at corresponding positions in the three maps to obtain the fused original gradient map. Finally, normalization is performed to ensure that all pixel values ​​are in the same order of magnitude [0-255], which is suitable for the normal brightness range of the image. This ensures that subsequent steps such as gradient map smoothing and abnormal region fusion can be carried out normally, while making the differences in image brightness more intuitive. The more drastic the texture change, the closer the pixel value is to 255, and the higher the brightness.

[0040] The reason for conducting directional analysis is that the normal surface texture of bamboo skewers is dominated by the axial direction of the bamboo fibers, along the length of the bamboo skewer, i.e., the y-axis direction. Defect textures (such as cracks and scratches) are mostly deviated from the axial direction. By analyzing the gradient direction of the texture at various scales, the global / local dominant direction is determined. Areas where the gradient direction deviates too much from the dominant direction are marked as directional anomaly areas.

[0041] In the specific implementation process, the gradient direction is calculated first: based on three horizontal (Gx) and vertical (Gy) gradient maps of different scales in S201, the gradient direction of each pixel in each map is calculated by combining the gradient information of the two directions. The direction value in radians is obtained first, and then converted into an angle value of 0°~180° to accurately represent the orientation of texture changes, providing data support for subsequent direction anomaly judgment. Then, the dominant direction is determined: first, histogram statistics are performed on the gradient directions at each scale (e.g., every 10° is an interval) to determine the global dominant direction, such as the dominant direction of bamboo fiber being 45°; then, a local dominant direction is calculated for each window using 15×15 as a local window to adapt to the local texture fluctuation scene of bamboo fiber. Finally, direction anomaly judgment is performed: a 25° angle deviation threshold can be set. If the gradient direction of a pixel deviates from the local dominant direction of its window by more than the threshold, it is judged as a pixel with an abnormal orientation.

[0042] The gradient change map is smoothed to reduce noise interference and enhance the continuity of defect edges. Then, combined with the direction anomaly region map, the region with "drastic texture changes and abnormal direction" is selected by "abnormal region weighting + threshold segmentation", which is the highly significant defect region.

[0043] First, gradient map smoothing is performed: the gradient change map output by S201 is smoothed using a 5×5 Gaussian blur to remove gradient noise and make defect edges more continuous. Second, abnormal regions and gradient maps are fused: the smoothed gradient map and the directional abnormal region map output by S202 are weighted and fused using a fixed weight allocation (abnormal region weight α=0.6, gradient map weight 1-α=0.4). Pixels within abnormal regions can have their highest brightness (255, white) weighted to prioritize the abnormal region; non-abnormal regions are primarily represented by the original brightness of the gradient map, facilitating accurate defect region localization during subsequent threshold segmentation. Finally, highly saliency regions are segmented: Otsu adaptive threshold segmentation is used to segment the fused map into binary images; morphological closing operations are performed on the segmented binary images to identify highly saliency regions.

[0044] In a preferred embodiment of the present invention, S3 specifically includes: S301. Determine the dynamic threshold standard based on historical data; S302. Perform gradient feature accurate detection on highly significant regions and mark potential defect regions that exceed the dynamic threshold standard.

[0045] Specifically, to avoid the problem of fixed thresholds being difficult to adapt to different batches and varieties of bamboo skewers, dynamic thresholds can be used to improve the versatility and accuracy of defect detection. This is achieved by collecting a large amount of historical detection data and using statistical analysis to determine the dynamic threshold standard for gradient characteristics.

[0046] Historical data can include core features such as the mean, maximum, and variance of gradients in highly significant areas across different batches and defect types (cracks, scratches, notches). The dynamic threshold can be determined using the "3σ principle," where the threshold is the mean gradient of the normal area plus three times the standard deviation, thus filtering out abnormal areas outside the normal range. Simultaneously, subdivided thresholds can be set according to defect type, matching the gradient feature distribution of different defects such as cracks and scratches to improve threshold targeting. Furthermore, a dynamic threshold update mechanism can be established: for every 1000 new bamboo skewers of quality inspection data, the mean gradient and standard deviation of the normal area are recalculated, and the threshold is updated synchronously to adapt to the texture differences of different batches of bamboo skewers, avoiding missed detections and misjudgments caused by fixed thresholds.

[0047] In this embodiment of the invention, it further includes: S4, calculating the potential defect region by edge tracking to obtain the defect region contour extraction result.

[0048] In this application, highly significant regions can be further screened to eliminate false anomalies and accurately pinpoint the true defect regions. For the identified highly significant regions, precise gradient feature detection is performed. The detection results are compared with a defined dynamic threshold standard, and regions exceeding the threshold standard are marked as potential defect regions.

[0049] To refine the boundary morphology of potential defect areas, eliminate contour interference, and obtain clear and regular defect contours, providing an accurate basis for subsequent defect identification and classification, an edge tracking algorithm can be used to delineate the edges of the marked potential defect areas point by point, directly calculating the defect area contour extraction result. In this application, a tracking algorithm with strong noise resistance, such as the 8-neighborhood chain code tracking algorithm, can be preferentially selected to adapt to the potential breakage and blurring problems of bamboo stick defect edges, ensuring complete contour delineation.

[0050] In practice, edge detection can be performed using the Canny edge detection method, and contour tracking can be performed using the 8-neighborhood chain code tracking algorithm.

[0051] When performing edge detection using the Canny edge detection method, Gaussian blur denoising is first performed: a 5×5 Gaussian kernel is used to smooth the potential defect marker image, with the standard deviation of the Gaussian kernel set to 1.0. This size and standard deviation balance the denoising effect and edge preservation, eliminating interference from bamboo fiber texture and minor noise remaining from image acquisition, while avoiding excessive blurring that could lead to the loss of minor defect edges such as fine cracks. Next, Canny dual-threshold edge extraction is performed: two threshold standards are set (low threshold 50, high threshold 150, pixel value range 0-255). The low threshold is used to capture weak parts of defect edges, while the high threshold is used to filter out strong edges with clear contours and high credibility. Finally, only weak edges connected to strong edges are retained, ensuring that defect edges are continuous and unbroken, while isolated noisy weak edges are removed. Finally, isolated edge filtering is performed: continuous edge segments with a length ≥ 3 pixels are selected based on pixel length, while isolated edges with a length less than 3 pixels are directly filtered out, as these edges are mostly noise residues and not true defect edges. This further purifies the edge image, providing a precise foundation for subsequent contour tracking.

[0052] As can be seen, the Canny edge detection method incorporates a Gaussian blur preprocessing step, which effectively filters out noise from the bamboo fiber texture on the bamboo stick surface and slight reflective noise during image acquisition. This avoids misjudging noise as defects such as fine cracks and scratches, solving the edge extraction interference problem caused by the complex texture of the bamboo stick surface. Simultaneously, it employs a dual-threshold (low 50 / high 150, pixel value 0-255) judgment mechanism. The low threshold captures the weak parts of defect edges, while the high threshold filters out strong edges with clear contours. Ultimately, only weak edges connected to strong edges are retained, accurately locating easily missed defects such as fine cracks and shallow scratches, avoiding edge offset or missed detection, and adapting to the detection needs of small micro-defects on bamboo sticks. It can effectively connect common broken edges in bamboo stick defects, such as broken scratches and discontinuous cracks, generating continuous and complete edge contours, avoiding contour tracking failure due to edge breakage. Furthermore, it can remove isolated noisy edges, further purifying the edge image and ensuring the completeness and reliability of the subsequently extracted defect contours.

[0053] Contour tracking is performed using an 8-neighbor chain code tracking algorithm. Compared to four-neighbor tracking (only top, bottom, left, and right), the 8-neighbor chain code tracking algorithm can cover the eight adjacent directions (including the diagonal) of the current pixel. It can accurately capture the boundary contours of irregular defects such as fine cracks, irregular scratches, and edge gaps on the surface of bamboo sticks, avoiding contour loss due to the complexity of defect shapes. It is especially suitable for the characteristic of bamboo stick defects that have no fixed shape. When performing contour tracking, the edge image is first traversed, and the first pixel with a value of 255 (edge ​​pixel) in the upper left corner is taken as the starting tracking point, and its initial coordinates are recorded. With the current pixel as the center, the eight neighboring pixels (including the diagonal) are traversed in a clockwise direction. Untracked edge pixels are selected as the next tracking point, and the coordinates of each tracking point are recorded simultaneously to form a temporary coordinate point set. Contour closure and completion: when the tracking point returns to the starting point, a closed contour is formed, and contour tracking stops. If there are no untracked edge pixels (non-closed contours) after traversing all neighbors, the breakpoints are connected by linear interpolation to complete the closed contour and perfect the coordinate point set. Repeat the above steps to extract all potential defect contours in the image. Mark the set of coordinate points corresponding to the outer boundary of the defect as the main contour and the set of coordinate points corresponding to the boundary of the hole inside the defect as the inner contour. Store them separately to distinguish the boundaries of different regions.

[0054] Meanwhile, addressing issues such as minor breaks and burrs that easily occur at the edges of bamboo skewer defects, the 8-neighbor chain code tracking algorithm can effectively connect discontinuous edge segments through pixel matching in the diagonal direction, generating a complete closed contour. This solves the problems of contour breaks and missed detection of local defect boundaries that easily occur in four-neighbor tracking. Furthermore, it is highly compatible with the single-pixel edge height output of Canny edge detection, allowing the 8-neighbor chain code tracking algorithm to directly start tracking based on the edge pixels extracted by Canny without additional preprocessing. It can also distinguish between the main contour and inner contour of the defect, adapting to complex shapes such as holes and depressions that may exist in bamboo skewer defects.

[0055] In a preferred embodiment of the present invention, S5 specifically includes: S501. Based on the defect area contour extraction results, analyze the regional difference data between the defect area and the normal area through grayscale contrast analysis. S502. Group the pixels inside the defect area according to grayscale intervals by internal pixel clustering, and obtain the depth distribution data corresponding to each grayscale interval; and classify the depth level by using the depth distribution data. S503. Based on regional difference data and depth distribution data, obtain the overall depth distribution characteristics of the defect area, and classify the depth level according to the depth level division.

[0056] In detail, based on the defect region contour extraction results obtained from S4, the average gray value and gray value variance within the defect region can be calculated, as well as the corresponding gray value parameters of the normal region (i.e., the bamboo skewer texture region without abnormalities around the defect). The regional difference data between the two regions is obtained through indicators such as gray value difference and contrast. Based on the defect contour coordinate point set output by S4, the defect region (within the contour) and the normal region (outside the contour) are accurately segmented, ensuring no overlap or omission between the two types of regions, thus defining the scope for difference analysis. The mean gray value and gray value variance of the defect region and the normal region are calculated separately. The regional difference is quantified through difference operations (mean difference, variance difference). The larger the difference, the more significant the difference in texture and brightness between the defect region and the normal region, providing auxiliary judgment criteria for subsequent deep feature analysis.

[0057] For example, when calculating regional difference data, grayscale features are calculated first, with pixel values ​​ranging from 0 to 255: Defect area: Mean grayscale value = 85, Variance grayscale value = 42 Normal area: mean gray level = 152, variance gray level = 18 Then, the difference quantification calculation was performed: grayscale mean difference = |85-152| = 67; grayscale variance difference = |42-18| = 24. It can be seen that both differences are relatively large, with the mean difference greater than 50 and the variance difference greater than 20, indicating that the texture and brightness of this area are abnormally significant, and it can basically be identified as a "deep defect area". When classifying the depth level in the future, the depth data of this area can be given priority to improve the pertinence of the depth assessment.

[0058] When acquiring depth distribution data, a 3D structured light sensor can be used to obtain the depth point cloud data of the defect area, map it to 2D contour coordinates, and match the depth value of each pixel.

[0059] Simultaneously, pixel clustering algorithms, such as K-means clustering, can be used to group pixels within the defect area according to grayscale intervals. The number and distribution of pixels in each grayscale interval are then counted to obtain the corresponding depth distribution data. Specifically, pixels within the defect area can be grouped by grayscale interval, and the depth value distribution data corresponding to each grayscale interval can be statistically analyzed. Furthermore, the grayscale-depth correspondence of historical defect samples can be combined to set classification criteria and complete the depth level classification. When classifying depth levels, classification can also be based on different usage scenarios of bamboo skewers. Taking a differentiated 5-level depth standard as an example, this provides a judgment benchmark for subsequent classification, as detailed below: 1. Edible bamboo skewers, used in food contact scenarios, require strict control over even the smallest defects to avoid residual impurities and scratches to the mouth. 1. Very shallow: depth < 0.05 mm; 2. Shallow: Depth 0.05~0.2mm; 3. Medium: Depth 0.2~0.4mm; 4. Depth: 0.4~0.6mm; 5. Extremely deep: Depth ≥ 0.6 mm.

[0060] II. Load-bearing bamboo skewers, used to support heavy loads, control depth defects, and prevent structural breakage. 1. Very shallow: depth < 0.1 mm; 2. Shallow: Depth 0.1~0.3mm; 3. Medium: Depth 0.3~0.6mm; 4. Depth: 0.6~1.0mm; 5. Extremely deep: Depth ≥ 1.0 mm.

[0061] By integrating regional difference data and depth distribution data, the overall depth distribution characteristics of the defective area can be extracted, such as maximum depth, average depth, and depth distribution uniformity; and the defective area can be finally classified into depth levels.

[0062] In a preferred embodiment of the present invention, S6 specifically includes: S601. Extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour. S602. A weighted average algorithm is used to calculate the depth level and regional shape characteristics to obtain the comprehensive defect index.

[0063] Specifically, by supplementing the shape dimension information of defects and combining it with depth features, a more comprehensive defect assessment can be achieved, avoiding misjudgment of defect severity based solely on depth. For example, although long and short cracks on bamboo skewers may have the same depth, their different shapes have significantly different impacts on the strength of the bamboo skewers. Integrating depth levels and shape features yields a quantified comprehensive defect index, providing a unified and accurate basis for bamboo skewer quality inspection. In a specific embodiment, a weighted average algorithm can be used, first assigning weights to depth levels and regional shape features. These weights can be adjusted according to the bamboo skewer's usage scenario; for example, food-grade bamboo skewers emphasize depth, while load-bearing bamboo skewers emphasize shape features.

[0064] The aspect ratio calculation can be based on the defect profile output by S4, fitting the minimum bounding rectangle, and calculating the aspect ratio by "rectangle length / rectangle width" - the larger the ratio, the more slender the defect, such as long cracks and long scratches, and the stronger its destructive effect on the strength of bamboo sticks.

[0065] Irregularity can be calculated by the ratio of the perimeter to the area of ​​the defect profile. When the value is 1, the defect is a standard circle. The larger the value, the more irregular the defect shape, such as sawtooth cracks or irregular notches, which are more likely to become weak points under stress.

[0066] After calculating the aspect ratio and irregularity, the shape features can be normalized. The aspect ratio and irregularity are normalized to the [0,1] interval respectively, and the average of the two is taken as the shape feature score, so as to achieve the quantitative unification of shape features.

[0067] For example, load-bearing bamboo skewers are suitable for scenarios such as handcrafted construction, load-bearing of handicrafts, and small supports. They have extremely high requirements for structural strength. The shape of their defects, especially the length and direction of the cracks, has a much greater impact on the load-bearing capacity than the depth of the defects. Therefore, the weight of the shape features of the area can be increased during the inspection process.

[0068] The weighted average algorithm integrates depth level and shape features. The core is to adapt the quality inspection priority of different bamboo sticks through scenario-based weight allocation: food-grade bamboo sticks focus on depth (to avoid minor defects that may leave impurities or scratch the mouth), while load-bearing bamboo sticks focus on shape (to avoid slender / irregular defects that may cause structural breakage). Finally, a quantitative comprehensive defect index is obtained, which solves the problem of misjudgment in single-dimensional evaluation and provides a unified judgment standard for sorting.

[0069] For example, with a total weight of 1, w_D is the depth weight, and w_S is the shape weight. The weights can be allocated according to different scenarios, as follows: Food-grade bamboo skewers: w_D=0.7, w_S=0.3; Weight-bearing bamboo skewers: w_D=0.3, w_S=0.7.

[0070] The above settings are because food-grade bamboo skewers prioritize depth defects, while load-bearing bamboo skewers prioritize shape and structural strength. In the actual implementation process, the weight allocation can be further adjusted according to the actual situation.

[0071] In a preferred embodiment of the present invention, S7 specifically includes: The comprehensive defect index is compared with a preset range, and bamboo skewers that exceed the preset range are sorted for defects.

[0072] In this application, the comprehensive defect index is used as the criterion for judgment. By comparing it with a preset range, the automatic sorting of defects in bamboo skewers can be realized, clearly distinguishing between qualified and unqualified products and improving quality inspection efficiency.

[0073] Specifically, the acceptable range of the comprehensive defect index can be preset according to the application scenario of the bamboo skewers. For example, the preset acceptable range for food-grade bamboo skewers is ≤4 points, and the acceptable range for load-bearing bamboo skewers is ≤3 points. The calculated comprehensive defect index of each bamboo skewer is compared with the preset range. Unacceptable bamboo skewers that exceed the preset range are marked and sorted into the defect area, while qualified bamboo skewers that meet the range proceed to the next process.

[0074] In summary, the AI ​​visual defect sorting method and system for bamboo skewer production and the computer-readable storage medium proposed in this invention are based on image recognition technology and run through the entire process from original image acquisition to defect contour extraction. By performing image recognition on the original image with texture details on the surface of the bamboo skewer, potential defect areas are calculated; and by calculating the regional shape features of the defect areas and combining depth level classification, the bamboo skewers are classified and sorted for defects. It can accurately sort defective bamboo skewers based on differences in depth or distribution density.

[0075] This invention converts the original image into a grayscale image. Since the red, green, and blue channels of a color image are redundant, converting it into a single-channel grayscale image can reduce the amount of computation.

[0076] The embodiments of the present invention divide continuous grayscale and gradient values ​​into a finite number of levels, which can reduce the complexity of subsequent calculations and avoid the influence of small fluctuations on the results.

[0077] By supplementing the shape dimension information of defects and combining it with depth features, this embodiment of the invention can achieve a more comprehensive defect assessment, avoiding misjudging the severity of defects based solely on depth. It can also accurately sort defective bamboo sticks based on differences in depth or distribution density.

[0078] The embodiments of the present invention can adapt to the differences in texture of bamboo skewers of different varieties and batches through image recognition technology. With the flexible adjustment of dynamic thresholds, weighting coefficients and sorting standards, it can accurately match the quality inspection requirements of different application scenarios such as food grade and load-bearing type, and adapt to material fluctuations and process adjustments in the production process.

[0079] In one specific embodiment of the present invention, taking the detection of food-grade bamboo skewers as an example, defect sorting is completed using AI image recognition methods. The specific process is as follows: Color images of bamboo sticks were acquired using an industrial macro camera; after converting the original images to grayscale, the gradient magnitude and direction were calculated and quantized, a grayscale-gradient co-occurrence matrix was constructed, and features were extracted to generate a surface texture change map; then, three scales were used: Small: 3×3, Medium: 5×5, Large: 7×7; Multi-scale analysis was performed to obtain a gradient change map; the dominant direction of bamboo fiber was determined to be 45° through directional analysis, and regions deviating from 45° by more than 25° were marked as directional anomalies; after smoothing with 3×3 mean filtering, two highly significant regions were identified.

[0080] Historical detection data, including 500 sets of normal bamboo sticks and 300 sets of bamboo sticks with different crack defects, was retrieved to determine the dynamic threshold of gradient features. A gradient amplitude greater than 85 was considered abnormal. Two highly significant areas were detected, both of which exceeded the threshold and were marked as potential defect areas.

[0081] An 8-neighborhood chain code tracking algorithm was used to perform edge tracking on two potential defect areas, and the following contours were extracted: Contour 1: 2.3 mm in length, irregular curve; Contour 2: 1.8 mm in length, linear. The average gray value of contour 1 region is 68, variance is 12, average gray value of surrounding normal region is 152, variance is 8, gray value difference is 84, and contrast is 1.8; the average gray value of contour 2 region is 75, variance is 10, average gray value of normal region is 150, variance is 9, gray value difference is 75, and contrast is 1.6. K-means clustering was used to divide the pixels within contour 1 into 3 gray-level intervals: 50-60, 61-71, 72-82 The corresponding depth distribution data is as follows: The 50-60 pixel range accounts for 42% of the total pixels, corresponding to a depth of 0.4-0.5mm; The 61-71 range accounted for 38%, corresponding to a depth of 0.2-0.4mm; The 72-82 range accounts for 20%, corresponding to a depth of 0.1-0.2mm; Based on historical data, depth levels are divided into three categories: Level 1 (above 0.4mm), Level 2 (0.2-0.4mm), and Level 3 (0.1-0.2mm).

[0082] Outline 1: Level 1 Depth, Quantitative Score 10 points; Regional shape characteristics: 7.5 points; The calculation uses a weighting of 0.6 for depth and 0.4 for shape features. Overall Defect Index = 10 × 0.6 + 7.5 × 0.4 = 6 + 3 = 9 points.

[0083] Outline 2: Level 3 depth, quantified score 2 points; Regional shape characteristics: 3.5 points; The overall defect index = 2 × 0.6 + 3.5 × 0.4 = 1.2 + 1.4 = 2.6 points.

[0084] For the above food-grade bamboo skewer testing example, the preset acceptable range for the comprehensive defect index is ≤4 points: bamboo skewers with outline 1 have a comprehensive defect index of 9 points, are marked as defective products and sorted to the defect area; bamboo skewers with outline 2 have a comprehensive defect index of 2.6 points, are judged as qualified products and enter the next process.

[0085] like Figure 2 As shown, this invention also proposes an AI visual defect sorting system for bamboo skewer production, comprising: Acquisition Module 1: Used to acquire the original image containing details of the surface texture of the bamboo skewer, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; The segmentation module 2 is used to perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and to perform smoothing processing to segment out highly saliency regions; Generation module 3 is used to determine threshold standards based on historical data and accurately detect potential defect areas in highly significant regions through gradient features; The first calculation module 4 is used to calculate the potential defect regions in the priority list through edge tracking and smoothing methods, and obtain the defect region contour extraction results. Classification module 5 is used to obtain defect depth distribution analysis data of defect region contour extraction results through grayscale contrast analysis and internal pixel clustering, and to perform depth level classification. The second calculation module 6 is used to extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour, and to calculate the comprehensive defect index by combining the depth level classification. Sorting module 7 is used to sort bamboo sticks for defects based on the comprehensive defect index.

[0086] In a preferred embodiment of the present invention, the acquisition module is specifically used for: Obtain raw images containing details of the surface texture of bamboo skewers using image acquisition equipment; The original image is converted into a grayscale image. The gradient magnitude and direction of the grayscale image are calculated and the grayscale and gradient are quantized to construct a grayscale-gradient co-occurrence matrix. Texture features are extracted from the grayscale-gradient co-occurrence matrix to generate a surface texture change map.

[0087] In summary, the AI ​​visual defect sorting method and system for bamboo skewer production proposed in this invention uses image recognition technology as its core support, covering the entire process from original image acquisition to defect contour extraction. By performing image recognition on the original image of the bamboo skewer surface with texture details, potential defect areas are calculated. By calculating the regional shape features of the defect areas and combining them with depth level classification, the bamboo skewers are classified and sorted for defects. This allows for accurate sorting of defective bamboo skewers based on differences in depth or distribution density.

[0088] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, and of course, it can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memory, special components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.

[0089] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0090] Finally, it should be noted that the above description is merely a preferred embodiment of the present invention and is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.

Claims

1. An AI-based visual defect sorting method for bamboo skewer production, characterized in that, Includes the following steps: S1. Obtain the original image containing details of the surface texture of the bamboo stick, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; S2. Perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and perform smoothing processing to divide the highly saliency region; S3. Determine the threshold standard based on historical data, and accurately detect potential defect areas in the highly significant regions through gradient features; S4. Calculate the potential defect region by edge tracking to obtain the defect region contour extraction result; S5. Obtain the defect depth distribution analysis data of the defect region contour extraction result through grayscale contrast analysis and internal pixel clustering, and perform depth level classification. S6. Extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour, and calculate the comprehensive defect index by combining the depth level classification. S7. Sorting bamboo skewers for defects based on the comprehensive defect index.

2. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, S1 specifically includes: S101. Acquire an original image containing details of the surface texture of the bamboo skewer using an image acquisition device; S102. Convert the original image into a grayscale image, calculate the gradient magnitude and direction of the grayscale image and quantize the grayscale and gradient, and construct a grayscale-gradient co-occurrence matrix; extract texture features from the grayscale-gradient co-occurrence matrix to generate a surface texture change map.

3. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, S2 specifically includes: S201. Use multi-scale analysis methods to analyze the surface texture change map at different scales, decompose the texture details at multiple scales, and obtain the gradient change map. S202. Perform directional analysis on the texture details at each scale in the gradient change map, determine the dominant texture direction, and mark areas with abnormal directions. S203. Smooth the gradient change map and divide the high significance region based on the directional anomaly region.

4. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, S3 specifically includes: S301. Determine the dynamic threshold standard based on historical data; S302. Perform gradient feature precision detection on the highly significant region and mark potential defect regions that exceed the dynamic threshold standard.

5. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, S5 specifically includes: S501. Based on the defect area contour extraction results, analyze the regional difference data between the defect area and the normal area through grayscale contrast analysis. S502. Group the pixels within the defect area according to grayscale intervals by internal pixel clustering, and obtain the depth distribution data corresponding to each grayscale interval; and perform depth level classification using the depth distribution data. S503. Based on the regional difference data and the depth distribution data, obtain the overall depth distribution characteristics of the defect area, and classify the depth level according to the depth level classification.

6. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, S6 specifically includes: S601. Extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour; S602. A weighted average algorithm is used to calculate the depth level and regional shape characteristics to obtain the comprehensive defect index.

7. The AI ​​visual defect sorting method for bamboo skewer production as described in claim 1, characterized in that, Specifically, S7 includes: The comprehensive defect index is compared with a preset range, and bamboo skewers that exceed the preset range are sorted for defects.

8. An AI-based visual defect sorting system for bamboo skewer production, characterized in that: include: Acquisition module: Used to acquire the original image containing details of the surface texture of the bamboo skewer, and generate a surface texture change map through the gray-level-gradient co-occurrence matrix; The segmentation module is used to perform multi-scale image analysis and texture directionality feature recognition on the surface texture change map, and to perform smoothing processing to segment out highly saliency regions; The generation module is used to determine the threshold standard based on historical data and accurately detect potential defect areas in the highly significant regions through gradient features; The first calculation module is used to calculate the potential defect regions in the priority list through edge tracking, and obtain the defect region contour extraction result; The classification module is used to obtain the defect depth distribution analysis data of the defect region contour extraction result through grayscale contrast analysis and internal pixel clustering, and to perform depth level classification. The second calculation module is used to extract the regional shape features of the defect region contour extraction result by calculating the aspect ratio and irregularity of the contour, and calculate the comprehensive defect index by combining the depth level classification. The sorting module is used to sort bamboo sticks for defects based on the comprehensive defect index.

9. The AI ​​visual defect sorting system for bamboo skewer production as described in claim 8, characterized in that, The acquisition module is specifically used for: Obtain raw images containing details of the surface texture of bamboo skewers using image acquisition equipment; The original image is converted into a grayscale image, the gradient magnitude and direction of the grayscale image are calculated and the grayscale and gradient are quantized, and a grayscale-gradient co-occurrence matrix is ​​constructed. Texture features are extracted from the gray-level-gradient co-occurrence matrix to generate a surface texture change map.

10. The AI ​​visual defect sorting system for bamboo skewer production as described in claim 8, characterized in that, The partitioning module is specifically used for: The surface texture variation map is analyzed at different scales using a multi-scale analysis method, and the texture details at multiple scales are decomposed to obtain the gradient variation map. Directional analysis is performed on the texture details at each scale in the gradient change map to determine the dominant texture direction and mark areas with abnormal directions. The gradient change map is smoothed, and highly significant regions are identified by combining the abnormal directional regions.