Sock defect detection method and system based on machine vision
By employing a multi-stage region segmentation and fabric structure similarity adaptive growth algorithm, the accuracy problem of sock defect detection under different fabric structure backgrounds is solved, achieving efficient and reliable defect detection.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- ZHUJI ZHISHEN SOCKS IND CO LTD
- Filing Date
- 2025-09-18
- Publication Date
- 2026-05-15
AI Technical Summary
Existing technologies are ill-suited for detecting diverse defect types in socks under different fabric structures, resulting in insufficient accuracy and reliability.
A multi-stage region segmentation algorithm is adopted. By constructing an energy function and a fabric structure similarity region adaptive growth algorithm, the sock image is segmented into regions with different fabric structures. The fabric structure shape is extracted, the shape difference is calculated and the defect points are marked. The difference is evaluated by combining shape distance and phase distance, and an adaptive threshold is established for defect detection.
It improves the accuracy and reliability of defect detection under different fabric structure backgrounds, reduces detection errors, is highly adaptable, and is suitable for diverse sock weaving characteristics.
Smart Images

Figure CN2025122205_15052026_PF_FP_ABST
Abstract
Description
A machine vision-based method and system for detecting defects in socks Technical Field
[0001] This invention relates to the field of textile defect detection technology, specifically to a machine vision-based method and system for detecting defects in socks. Background Technology
[0002] In the sock manufacturing process, defect detection is a crucial step in ensuring product quality. It not only promptly identifies and removes defective products, reducing the yield rate, but also helps companies adjust production process parameters in a timely manner, preventing batch quality problems. Sock production typically employs circular knitting technology, which can create various fabric structures, including plain weave, rib knit, and jacquard. Different fabric structures have different shape characteristics, and different parts of the same sock may use different fabric structures. For example, the sock cuff often uses rib knit to provide appropriate elasticity, while the leg area may use plain knit to ensure a snug fit. This diversity and complexity of structures presents challenges for sock defect detection. Detection methods need to be adaptable to the characteristics of different fabric structures to accurately detect various potential defects.
[0003] Currently, machine vision technology has been applied to the field of sock defect detection, improving the accuracy and efficiency of defect detection. For example, by capturing sock images with high-speed cameras and combining them with deep learning algorithms, common defects can be quickly identified, avoiding missed detections caused by human fatigue. However, for the diverse types of defects in socks with different fabric structures, the generalization ability of existing technologies is limited, making it difficult to guarantee detection accuracy and reliability.
[0004] To address this, a machine vision-based method and system for detecting defects in socks is proposed. Summary of the Invention
[0005] The purpose of this invention is to provide a machine vision-based method and system for detecting defects in socks. First, a high-resolution camera is used to acquire images of socks to be detected and corresponding images of flawless socks, which are then preprocessed. A multi-stage region segmentation algorithm is constructed to segment both the images into multiple regions, resulting in a set of regions to be detected and a set of flawless regions. Then, the fabric structure shape of each region in the set of regions to be detected is extracted, resulting in a set of fabric structure shapes to be detected for each region. The fabric structure shape of each region in the set of flawless regions is extracted, and the mean value of all fabric structure shapes in each region is calculated to obtain a standard fabric structure shape model for each region. Next, for each region in the set of regions to be detected, the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and its corresponding standard fabric structure shape model is calculated. If the shape difference exceeds a difference threshold, the location of the fabric structure shape to be detected is marked as a defect point. Finally, the defect detection results of all regions are integrated to obtain the sock defect detection result.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A machine vision-based method for detecting defects in socks includes:
[0008] Acquire images of the socks to be inspected and their corresponding images of flawless socks, and perform preprocessing.
[0009] A multi-stage region segmentation algorithm is constructed to process the image of the socks to be detected and the image of the flawless socks to obtain a set of regions to be detected and a set of regions without defects, respectively. The multi-stage region segmentation algorithm includes: constructing an energy function to obtain an initial region set; constructing an adaptive growth algorithm based on fabric structure similarity regions according to the initial region set to obtain a set of regions with consistent fabric structure; and obtaining the region segmentation result according to the set of regions with consistent fabric structure.
[0010] Extract the fabric structure shape of each region in the set of regions to be detected to obtain a set of fabric structure shapes to be detected for each region; the fabric structure shape is the shape formed by the interlacing of yarns in the sock;
[0011] Extract the fabric structure shape of each region in the set of flawless regions, and calculate the mean value of all fabric structure shapes in each region to obtain the standard fabric structure shape model of each region;
[0012] For each region in the set of regions to be detected, calculate the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model. If the shape difference exceeds the difference threshold, mark the location of the fabric structure shape to be detected as a defect point.
[0013] The detection results of all regions are integrated to determine whether there are defects in the sock image to be detected, and the sock defect detection result is obtained.
[0014] Preferably, the specific steps of the multi-stage region segmentation algorithm include:
[0015] Construct an energy function, and obtain an initial region set by minimizing the energy function;
[0016] Calculate the contour curvature for each initial region in the initial region set;
[0017] Extract a set of contour feature points for each initial region based on the contour curvature;
[0018] A spatial constraint function is constructed for each initial region based on the set of contour feature points, and the effective range of the initial region is defined based on the spatial constraint function.
[0019] Intensity and orientation features are extracted within the effective range of each initial region;
[0020] A fabric structure similarity function is constructed based on the intensity feature and the orientation feature, and the fabric structure similarity is calculated.
[0021] Based on the fabric structure similarity, a set of fabric structure consistency regions is obtained through a region adaptive growth method.
[0022] Regions with the same fabric structure but belonging to different areas are merged, and the region segmentation result is obtained after boundary optimization.
[0023] Preferably, the specific steps for extracting the contour feature point set include: constructing a contour curvature sequence based on the contour curvature of the initial region, and processing the contour curvature sequence using Gaussian filtering; detecting local maxima and local minima in the filtered contour curvature sequence; setting a curvature threshold and a minimum spacing threshold, and filtering the local maxima and local minima based on the curvature threshold and the minimum spacing threshold to obtain the contour feature point set.
[0024] Preferably, generating the spatial constraint function and defining the effective range specifically includes: calculating the centroid of the region based on the set of contour feature points of each initial region; constructing the spatial constraint function based on the centroid of the region and the set of contour feature points; setting a constraint threshold and defining the effective range of the initial region; adjusting the effective range of adjacent initial regions and updating the effective range of each initial region.
[0025] Preferably, the specific steps of the adaptive growth algorithm based on fabric structure similarity regions include:
[0026] For each initial region, the set of contour feature points is used as the initial seed point set;
[0027] Pixels satisfying the first constraint condition within the neighborhood of each initial seed point are selected and added to the initial seed point set to obtain the seed point set; the first constraint condition includes: the fabric structure consistency of the pixel is greater than the consistency threshold, the fabric structure consistency and the consistency threshold are calculated based on the fabric structure similarity; the pixel is within the effective range of the initial region; the distance between the pixel and the existing seed point is greater than the seed point spacing threshold, the seed point spacing threshold is determined by the average distance of adjacent contour feature points;
[0028] Add all seed points from the seed point set to the unprocessed point queue Q and the segmented point set A; while the unprocessed point queue Q is not empty, perform the following iterative steps: take a point p from Q; for each point q in the neighborhood of p, if point q satisfies the second constraint condition, add q to the segmented point set A and the unprocessed point queue Q; the second constraint condition includes: point q is not in the segmented point set A; point q is within the effective range of the initial region; the growth probability of q is greater than the adaptive threshold, the growth probability and the adaptive threshold are calculated based on the fabric structure similarity; when the unprocessed point queue Q is empty, end the region adaptive growth.
[0029] Preferably, the specific steps for extracting the fabric structure shape include: generating a binarized edge image using an edge detection operator; performing connected component analysis on the binarized edge image to label each independent sub-region; extracting the contour point sequence of the independent sub-region using a neighborhood tracing algorithm; performing a closure test on the contour point sequence, and when the contour is not closed, interpolating through curve fitting to obtain a set of closed contour curves; and optimizing each closed contour curve in the set of closed contour curves to obtain the fabric structure shape.
[0030] Preferably, the square root velocity function is used to represent the shape of the fabric structure, specifically including: normalizing the optimized closed contour curve into a parametric equation; calculating the velocity vector and velocity vector magnitude of the closed contour curve according to the parametric equation to obtain the square root velocity function of the fabric structure shape.
[0031] Preferably, the calculation steps for the shape difference are as follows: calculate the shape distance and phase distance between the shape of the fabric structure to be detected and the standard fabric structure shape model, calculate the total distance based on the shape distance and the phase distance, and obtain the shape difference.
[0032] Preferably, the difference threshold is calculated based on the flawless sock image, and the specific steps are as follows: obtain all the fabric structure shapes in each region; calculate the shape distance and phase distance between each fabric structure shape and the standard fabric structure shape model; calculate the total distance based on the shape distance and the phase distance to obtain a total distance set; perform statistical analysis on the total distance set, and determine the difference threshold based on the upper limit of the total distance set.
[0033] A machine vision-based sock defect detection system includes:
[0034] The image acquisition module acquires images of the socks to be inspected and corresponding images of flawless socks, and performs preprocessing.
[0035] The region segmentation module constructs a multi-stage region segmentation algorithm to process the sock image to be detected and the flawless sock image respectively to obtain a set of regions to be detected and a set of flawless regions;
[0036] The shape extraction module extracts the fabric structure shape of each region in the set of regions to be detected, and obtains a set of fabric structure shapes to be detected for each region; it also extracts the fabric structure shape of each region in the set of flawless regions, and calculates the mean value of all the fabric structure shapes in each region to obtain a standard fabric structure shape model for each region.
[0037] The defect detection module calculates the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model for each region in the set of fabric structure shapes to be detected. If the shape difference exceeds the difference threshold, the location of the fabric structure shape to be detected is marked as a defect point.
[0038] The result integration module integrates the defect detection results of all regions to determine whether there are defect points in the image of the socks to be detected, and obtains the defect detection result of the socks.
[0039] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0040] 1. A multi-stage region segmentation algorithm first obtains an initial region by minimizing an energy function. Then, it calculates the region contour curvature and extracts contour feature points. Based on the contour feature points, it constructs a spatial constraint function to define the effective range. Within the effective range, it extracts the strength and orientation features of the fabric structure and establishes a fabric structure similarity function. Based on the fabric structure similarity function, it implements an adaptive region growth method, which can obtain a set of regions divided according to fabric structure features. After region merging and boundary optimization, the final segmentation result is obtained. This algorithm can accurately identify and segment different regions of the fabric structure in sock images, perform targeted defect detection, and improve the accuracy and reliability of detection under different fabric structure backgrounds.
[0041] 2. The fabric structure shape of different regions of the socks is extracted. First, an edge detection operator is used to generate a binary edge image. Independent sub-regions are marked by connected component analysis. Then, a neighborhood tracking algorithm is used to extract the contour point sequence. For non-closed contours, curve fitting is used for interpolation to ensure that a complete set of closed contour curves is obtained. The square root velocity function is used to represent the fabric structure shape. The method of extracting and representing the fabric structure shape can accurately extract the fabric structure features of different regions of the socks, providing a standardized shape expression method, effectively improving the accuracy and reliability of defect detection under different fabric structure backgrounds, and providing an objective basis for defect judgment.
[0042] 3. By simultaneously considering both shape distance and phase distance, the difference between the fabric structure shape to be detected and the standard fabric structure shape model is comprehensively evaluated, which can accurately capture minute defects. By statistically analyzing the differences between all fabric structure shapes in the defect-free area and the standard fabric structure shape model, the difference threshold is determined. This threshold can be adjusted according to the material and weaving characteristics of different socks, avoiding detection errors caused by fixed thresholds. It has versatility and adaptability, and can maintain high defect detection accuracy and reliability when dealing with socks with different fabric structures. Attached Figure Description
[0043] Figure 1 is a schematic flowchart of a machine vision-based sock defect detection method provided in an embodiment of the present invention;
[0044] Figure 2 is a schematic diagram of a machine vision-based sock defect detection system provided in an embodiment of the present invention. Detailed Implementation
[0045] 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.
[0046] With the rapid development of the textile industry, socks have become increasingly diverse in weaving techniques and design. However, because socks use different weaving methods for different functional areas, resulting in different fabric structures, the types of defects also exhibit diverse characteristics. Common defects include knots, skipped patterns, star-shaped patterns, and broken warp threads, and the specific manifestations of these defects vary under different fabric structures. Traditional manual inspection methods suffer from low efficiency, poor accuracy, and difficulty in standardizing inspection criteria. Currently, mainstream defect detection methods are mainly based on artificial intelligence technologies such as deep learning, requiring a large amount of labeled sample data to train and optimize the model. Furthermore, when faced with new fabric structures or defect types, the trained model often needs to be retrained using newly collected samples, resulting in limited generalization ability. This not only increases detection costs but also affects the accuracy and reliability of the detection.
[0047] This invention proposes a machine vision-based method and system for detecting defects in socks. It can automatically segment socks into different regions for targeted analysis based on different fabric structural features, and combined with fabric structure shape extraction, achieves accurate detection of defects against different fabric structural backgrounds. To illustrate the effectiveness of this invention, the following two embodiments will demonstrate its validity. Embodiments
[0048] A sock factory has implemented a machine vision-based sock defect detection method on its production line, as shown in Figure 1, which includes:
[0049] The system acquires images of the socks to be inspected and corresponding images of flawless socks, and performs preprocessing steps, including contrast enhancement, adaptive contrast equalization, and noise reduction.
[0050] A multi-stage region segmentation algorithm is constructed to process the image of the socks to be detected and the image of the flawless socks to obtain a set of regions to be detected and a set of regions without defects, respectively. The multi-stage region segmentation algorithm includes: constructing an energy function to obtain an initial region set; constructing an adaptive growth algorithm based on fabric structure similarity regions according to the initial region set to obtain a set of regions with consistent fabric structure; and obtaining the region segmentation result according to the set of regions with consistent fabric structure.
[0051] Extract the fabric structure shape of each region in the set of regions to be detected to obtain a set of fabric structure shapes to be detected for each region; the fabric structure shape is the shape formed by the interlacing of yarns in the sock;
[0052] Extract the fabric structure shape of each region in the set of flawless regions, and calculate the mean value of all fabric structure shapes in each region to obtain the standard fabric structure shape model of each region;
[0053] For each region in the set of regions to be detected, calculate the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model. If the shape difference exceeds the difference threshold, mark the location of the fabric structure shape to be detected as a defect point.
[0054] The detection results of all regions are integrated to determine whether there are defects in the sock image to be detected, and the sock defect detection result is obtained.
[0055] This application embodiment conducted defect detection tests on socks with different fabric structures in different parts. The test dataset included: 1000 normal samples and 200 defective samples. The defect types and sample numbers included: 50 knots; 60 skipped stitches; 45 star skipped stitches; and 45 broken warp threads. Among them, knots are caused by yarn tangling or knotting during the knitting process, resulting in yarn accumulation on the surface of the sock; skipped stitches are two or more consecutive skipped warp or weft yarns in the same part, forming a mesh-like pattern on the surface of the sock; star skipped stitches are caused by a single yarn skipping two to four yarns, forming star-like patterns; and broken warp threads are caused by one or more broken warp yarns, forming obvious strip-like structural abnormalities on the surface of the sock. Table 1 shows the detection effect of the method of this embodiment on different defect types. On the same sock, the same defect type has certain characteristic differences under different fabric structure backgrounds, which will bring challenges to defect detection. As can be seen from Table 1, the method of this embodiment can still achieve a high detection recall and precision.
[0056] First, images are acquired using a high-resolution camera and preprocessed to ensure the quality of the input images, providing a reliable data foundation for subsequent analysis. Then, a multi-stage region segmentation algorithm is employed to accurately identify and segment regions with different fabric structures, improving the accuracy of subsequent defect detection. Next, the fabric structure shape is extracted and analyzed to accurately capture the interlacing characteristics of the sock yarns, making defect detection more targeted. A standard fabric structure shape model is constructed and shape differences are calculated, realizing an adaptive defect judgment standard. This significantly improves the efficiency and accuracy of sock defect detection.
[0057] Furthermore, the specific steps of the multi-stage region segmentation algorithm include: constructing an energy function, and obtaining an initial region set R by minimizing the energy function. init ;Calculate the contour curvature for each initial region in the initial region set;
[0058] Extract a set of contour feature points for each initial region based on the contour curvature;
[0059] A spatial constraint function is constructed for each initial region based on the set of contour feature points, and the effective range of the initial region is defined based on the spatial constraint function.
[0060] Intensity and orientation features are extracted within the effective range of each initial region;
[0061] A fabric structure similarity function is constructed based on the intensity feature and the orientation feature, and the fabric structure similarity is calculated.
[0062] Based on the fabric structure similarity, a set of fabric structure consistency regions is obtained through a region adaptive growth method.
[0063] Regions with the same fabric structure but belonging to different areas are merged, and the region segmentation result is obtained after boundary optimization.
[0064] Furthermore, the formula for the energy function is as follows: Where E(C) represents the energy function; C represents the profile curve; λ1 and λ2 represent the weighting coefficients; E data (C), E shape (C) and E smooth (C) represent the data term, shape term, and smoothing term of the energy function, respectively; I(a) represents the image feature vector at point a on the contour curve; μ R σ represents the average eigenvalue of region R. R C represents the characteristic standard deviation of region R; C(a) represents the position coordinates of point a on the current curve; C ref The coordinates of point a on the reference contour curve template are represented by the reference contour curve template obtained from the corresponding flawless sock image; D(·,·) represents the Euclidean distance between the two points; C″(a) represents the second derivative of the curve at point a; the fabric structure similarity function S(p,q)=w1D1(p,q)+w2D2(p,q) where D1 represents the intensity feature difference measure of pixel points p and q, D2 represents the directional feature difference measure of pixel points p and q, and w1 and w2 represent weight coefficients.
[0065] Initial segmentation is performed by minimizing the energy function, ensuring basic segmentation accuracy. Contour curvature and feature point extraction enable more accurate identification of region boundaries. A spatial constraint function is introduced to limit the effective range and avoid over-segmentation. A fabric structure similarity function is constructed by combining intensity and direction features, achieving an accurate description of fabric structure features. A region growing method based on fabric structure similarity ensures the consistency of fabric structure features in segmented regions. Finally, region merging and boundary optimization are used to obtain the final segmentation result, improving the segmentation effect.
[0066] Further, the specific steps for extracting the contour feature point set include: constructing a contour curvature sequence based on the contour curvature of the initial region, and processing the contour curvature sequence using Gaussian filtering; detecting local maxima and local minima in the filtered contour curvature sequence; setting a curvature threshold and a minimum spacing threshold, and filtering the local maxima and local minima based on the curvature threshold and the minimum spacing threshold to obtain the contour feature point set.
[0067] Gaussian filtering is used to process the curvature sequence to reduce the impact of noise; local maxima and minima are detected to accurately capture key feature points; curvature thresholds and minimum spacing thresholds are introduced to ensure the representativeness and reasonable distribution of feature points.
[0068] Further, generating the spatial constraint function and defining the effective range specifically includes: based on the set of contour feature points P = (p1, p2, ..., p) of each initial region. k ) Calculate the centroid of the region c = (x c ,y c );in, k represents the number of contour feature points in the set of contour feature points, (x i ,y i ) represents the i-th contour feature point p i The coordinates;
[0069] The spatial constraint function is constructed based on the centroid of the region and the set of contour feature points, as shown in the following formula: Where M(x, y) represents the spatial constraint function of the pixel with coordinates (x, y); the first term represents the constraint of the pixel's distance from the centroid of the region; the second term represents the constraint of the pixel's distance from the contour feature point; This represents the region scale parameter, which is proportional to the size of the initial region; The influence range parameter of the feature points is determined by the distribution density of the contour feature points;
[0070] Set constraint threshold T v Define the effective range of the initial region as V = (x,y)|M(x,y)>T vAdjusting the effective range of adjacent initial regions specifically includes: when the effective range V of two adjacent regions... i and V j When overlap exists, within the overlapping region, if the spatial constraint value M i (x,y)≥M j If (x, y), then the point (x, y) belongs to V. i If the spatial constraint value M i (x,y)<M j If (x,y), then the point belongs to V. j ;
[0071] Update the effective range of each initial region.
[0072] By providing stable reference points through the centroid of the region and feature points of the contour map, and then designing spatial constraint functions and defining the effective range of the region, the region's overexpansion is avoided; the adjustment mechanism for the effective range of adjacent regions avoids the problems of region overlap and missed detection.
[0073] Furthermore, the specific steps of the adaptive growth method based on fabric structure similarity regions include:
[0074] For each initial region, the set of contour feature points is used as the initial seed point set;
[0075] Select pixels in the neighborhood of each initial seed point that satisfy the first constraint condition and add them to the initial seed point set to obtain the seed point set; add all seed points in the seed point set to the unprocessed point queue Q and the segmented point set A;
[0076] When the queue of points to be processed Q is not empty, the following steps are performed in a loop: take a point p from Q; for each pixel q in the neighborhood of p, if point q satisfies the second constraint condition, add q to the set of segmented points A and the queue of points to be processed Q.
[0077] When the queue of points to be processed, Q, is empty, the termination region undergoes adaptive growth.
[0078] Further, the first constraint includes: the fabric structure consistency of pixel n is greater than a consistency threshold, the consistency threshold being the weighted sum of the mean and standard deviation of the fabric structure consistency of all points in the neighborhood; the pixel is within the effective range of the initial region; the distance between the pixel and existing seed points is greater than a seed point spacing threshold, the seed point spacing threshold being determined by the average distance between adjacent contour feature points; the formula for calculating the fabric structure consistency of point n is: Where N represents the number of points in the neighborhood of point n; n′ i S(n,n′) represents the i-th point in the neighborhood of point n; i): represents the relationship between point n and point n′ i Fabric structural similarity;
[0079] The second constraint includes: point q is not in the already segmented point set A; point q is within the effective range of the initial region; the growth probability of q is greater than the adaptive threshold; the calculation formulas for the growth probability and the adaptive threshold are as follows: Wherein, P(q|R grown R represents the growth probability of point q; grown : Indicates the region that has been grown; S(q:R gown ) represents the relationship between point q and region R grown The average fabric structure similarity of all points within the range; τ represents the tolerance parameter; T(R) represents the adaptive threshold; mean(S(R) init )) and std(S(R init )) respectively represent the initial region R init The mean and standard deviation of fabric structure similarity among all point pairs within the range, where α and β represent adjustment coefficients.
[0080] Using contour feature points as initial seed points ensures the reliability of the starting point for adaptive region growth; two constraints are introduced to ensure the accuracy and controllability of adaptive region growth; and the application of a processing queue enables efficient adaptive region growth.
[0081] Further, the specific steps for extracting the fabric structure shape include: generating a binarized edge image using an edge detection operator; performing connected component analysis on the binarized edge image to label each independent sub-region; extracting the contour point sequence of the independent sub-region using a neighborhood tracing algorithm; performing a closure test on the contour point sequence, and when the contour is not closed, interpolating through curve fitting to obtain a set of closed contour curves; and optimizing each closed contour curve in the set of closed contour curves to obtain the fabric structure shape.
[0082] Edge detection and connected component analysis can accurately extract the outline of the fabric structure shape; neighborhood tracing and curve fitting are used to ensure the integrity of the shape outline.
[0083] Furthermore, the square root velocity function is used to represent the fabric structure shape, specifically including: normalizing the optimized closed contour curve into a parametric equation; calculating the velocity vector and velocity vector magnitude of the closed contour curve based on the parametric equation to obtain the square root velocity function of the fabric structure shape, as shown in the following formula: Where β′(t) represents the derivative of the parametric equation of the closed contour curve, i.e. the velocity vector of the curve at time t; |β′(t)| represents the magnitude of the velocity vector; t∈[0,1].
[0084] The square root velocity function is used to represent the shape, which depends only on the derivative information of the closed contour curve. Therefore, it has translation invariance and provides a standardized shape description method, which facilitates subsequent shape difference calculation and comparative analysis.
[0085] Further, the calculation steps for the shape difference are as follows: calculate the shape distance and phase distance between the shape of the fabric structure to be detected and the standard fabric structure shape model; calculate the total distance based on the shape distance and the phase distance to obtain the shape difference. Further, the shape distance d... shape Phase distance d phose Total distance d totol The calculation formula is as follows: Where c1 and c2 represent the fabric structure shape to be detected and the standard fabric structure shape model, respectively; c1(t) and c2(t) represent the square root velocity functions of the fabric structure shape to be detected and the standard fabric structure shape model, respectively; ψ(t) represents the optimal parameterization function found by the optimization algorithm, which makes the closed contour curves of c1 and c2 aligned; and ψ′(t) represents its derivative.
[0086] L through the square root velocity function 2 Using norms to represent shape distance can eliminate the effects of translation, rotation, and scaling transformations, ensuring that only differences related to the curve shape itself are captured; phase distance can measure the parametric differences between two curves, capturing subtle imperfections; combining shape distance and phase distance can provide a more comprehensive measure of shape difference.
[0087] Further, the difference threshold is calculated based on the flawless sock image, and the specific steps are as follows: obtain all the fabric structure shapes in each region; calculate the shape distance and phase distance between each fabric structure shape and the standard fabric structure shape model; calculate the total distance based on the shape distance and the phase distance to obtain a total distance set; perform statistical analysis on the total distance set, and determine the difference threshold based on the upper limit of the total distance set.
[0088] A difference threshold standard was established based on images of flawless socks to ensure the rationality of the threshold; the difference threshold was determined through statistical analysis, which improved the accuracy and reliability of defect judgment; and the adaptive threshold determination mechanism enhanced the practicality and adaptability of the defect detection method in handling different types of socks.
[0089] Example 2
[0090] The present invention also provides a machine vision-based sock defect detection system, comprising:
[0091] The image acquisition module acquires images of the socks to be inspected and corresponding images of flawless socks, and performs preprocessing.
[0092] The region segmentation module constructs a multi-stage region segmentation algorithm to process the sock image to be detected and the flawless sock image respectively to obtain a set of regions to be detected and a set of flawless regions;
[0093] The shape extraction module extracts the fabric structure shape of each region in the set of regions to be detected, and obtains a set of fabric structure shapes to be detected for each region; it also extracts the fabric structure shape of each region in the set of flawless regions, and calculates the mean value of all the fabric structure shapes in each region to obtain a standard fabric structure shape model for each region.
[0094] The defect detection module calculates the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model for each region in the set of fabric structure shapes to be detected. If the shape difference exceeds the difference threshold, the location of the fabric structure shape to be detected is marked as a defect point.
[0095] The result integration module integrates the defect detection results of all regions to determine whether there are defect points in the image of the socks to be detected, and obtains the defect detection result of the socks.
[0096] Furthermore, the specific steps of the multi-stage region segmentation algorithm include:
[0097] Construct an energy function, and obtain an initial region set by minimizing the energy function;
[0098] Calculate the contour curvature for each initial region in the initial region set;
[0099] Extract a set of contour feature points for each initial region based on the contour curvature;
[0100] A spatial constraint function is constructed for each initial region based on the set of contour feature points, and the effective range of the initial region is defined based on the spatial constraint function.
[0101] Intensity and orientation features are extracted within the effective range of each initial region;
[0102] A fabric structure similarity function is constructed based on the intensity feature and the orientation feature, and the fabric structure similarity is calculated.
[0103] Based on the fabric structure similarity, a set of fabric structure consistency regions is obtained through a region adaptive growth method.
[0104] Regions with the same fabric structure but belonging to different areas are merged, and the region segmentation result is obtained after boundary optimization.
[0105] Furthermore, the specific steps of the adaptive growth algorithm based on fabric structure similarity regions include:
[0106] For each initial region, the set of contour feature points is used as the initial seed point set;
[0107] Pixels satisfying the first constraint condition within the neighborhood of each initial seed point are selected and added to the initial seed point set to obtain the seed point set; the first constraint condition includes: the fabric structure consistency of the pixel is greater than the consistency threshold, the fabric structure consistency and the consistency threshold are calculated based on the fabric structure similarity; the pixel is within the effective range of the initial region; the distance between the pixel and the existing seed point is greater than the seed point spacing threshold, the seed point spacing threshold is determined by the average distance of adjacent contour feature points;
[0108] Add all seed points in the seed point set to the unprocessed point queue Q and the already segmented point set A;
[0109] When the queue of points to be processed Q is not empty, the following steps are performed in a loop: a point p is taken out from Q; for each point q in the neighborhood of p, if point q satisfies the second constraint condition, q is added to the set of segmented points A and the queue of points to be processed Q; the second constraint condition includes: point q is not in the set of segmented points A; point q is within the effective range of the initial region; the growth probability of q is greater than the adaptive threshold, the growth probability and the adaptive threshold are calculated based on the fabric structure similarity.
[0110] When the queue of points to be processed, Q, is empty, the termination region undergoes adaptive growth.
[0111] Further, the specific steps for extracting the fabric structure shape include: generating a binarized edge image using an edge detection operator; performing connected component analysis on the binarized edge image to label each independent sub-region; extracting the contour point sequence of the independent sub-region using a neighborhood tracing algorithm; performing a closure test on the contour point sequence, and when the contour is not closed, interpolating through curve fitting to obtain a set of closed contour curves; and optimizing each closed contour curve in the set of closed contour curves to obtain the fabric structure shape.
[0112] Further, the calculation steps for the shape difference are as follows: calculate the shape distance and phase distance between the shape of the fabric structure to be detected and the standard fabric structure shape model, calculate the total distance based on the shape distance and the phase distance, and obtain the shape difference.
[0113] Further, the difference threshold is calculated based on the flawless sock image, and the specific steps are as follows: obtain all the fabric structure shapes in each region; calculate the shape distance and phase distance between each fabric structure shape and the standard fabric structure shape model; calculate the total distance based on the shape distance and the phase distance to obtain a total distance set; perform statistical analysis on the total distance set, and determine the difference threshold based on the upper limit of the total distance set.
[0114] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A machine vision-based method for detecting defects in socks, characterized in that, include: Acquire images of the socks to be inspected and their corresponding images of flawless socks, and perform preprocessing. A multi-stage region segmentation algorithm is constructed to process the image of the socks to be detected and the image of the flawless socks respectively to obtain a set of regions to be detected and a set of flawless regions; The multi-stage region segmentation algorithm includes: constructing an energy function to obtain an initial region set; constructing an adaptive growth algorithm based on fabric structure similarity regions according to the initial region set to obtain a set of fabric structure consistent regions; and obtaining the region segmentation result according to the set of fabric structure consistent regions. Extract the fabric structure shape of each region in the set of regions to be detected to obtain a set of fabric structure shapes to be detected for each region; the fabric structure shape is the shape formed by the interlacing of yarns in the sock; Extract the fabric structure shape of each region in the set of flawless regions, and calculate the mean value of all the fabric structure shapes in each region to obtain the standard fabric structure shape model of each region. For each region in the set of regions to be detected, calculate the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model. If the shape difference exceeds the difference threshold, mark the location of the fabric structure shape to be detected as a defect point. The detection results of all regions are integrated to determine whether there are defects in the sock image to be detected, and the sock defect detection result is obtained. The specific steps for extracting the fabric structure shape include: generating a binarized edge image using an edge detection operator; performing connected component analysis on the binarized edge image to label each independent sub-region; extracting the contour point sequence of the independent sub-region using a neighborhood tracing algorithm; performing a closure test on the contour point sequence, and when the contour is not closed, interpolating through curve fitting to obtain a set of closed contour curves; and optimizing each closed contour curve in the set of closed contour curves to obtain the fabric structure shape. The square root velocity function is used to represent the shape of the fabric structure. Specifically, this includes: normalizing the optimized closed contour curve into a parametric equation; calculating the velocity vector and velocity vector magnitude of the closed contour curve based on the parametric equation to obtain the square root velocity function of the fabric structure shape, as shown in the following formula: Where β′(t) represents the derivative of the parametric equation of the closed contour curve, i.e. the velocity vector of the curve at time t; |β′(t)| represents the magnitude of the velocity vector; t∈[0,1].
2. The machine vision-based method for detecting defects in socks according to claim 1, characterized in that, The specific steps of the multi-stage region segmentation algorithm include: Construct an energy function, and obtain an initial region set by minimizing the energy function; Calculate the contour curvature for each initial region in the initial region set; Extract a set of contour feature points for each initial region based on the contour curvature; A spatial constraint function is constructed for each initial region based on the set of contour feature points, and the effective range of the initial region is defined based on the spatial constraint function. Intensity and orientation features are extracted within the effective range of each initial region; A fabric structure similarity function is constructed based on the intensity feature and the orientation feature, and the fabric structure similarity is calculated. Based on the fabric structure similarity, a set of fabric structure consistency regions is obtained through a region adaptive growth method. Regions with the same fabric structure but belonging to different areas are merged, and the region segmentation result is obtained after boundary optimization.
3. The machine vision-based method for detecting defects in socks according to claim 2, characterized in that, The specific steps for extracting the contour feature point set include: constructing a contour curvature sequence based on the contour curvature of the initial region, and processing the contour curvature sequence using Gaussian filtering; detecting local maxima and local minima in the filtered contour curvature sequence; setting a curvature threshold and a minimum spacing threshold, and filtering the local maxima and local minima based on the curvature threshold and the minimum spacing threshold to obtain the contour feature point set.
4. The machine vision-based method for detecting defects in socks according to claim 2, characterized in that, Generating the spatial constraint function and defining the effective range specifically includes: calculating the centroid of the region based on the set of contour feature points of each initial region; constructing the spatial constraint function based on the centroid of the region and the set of contour feature points; setting a constraint threshold and defining the effective range of the initial region; adjusting the effective range of adjacent initial regions and updating the effective range of each initial region.
5. The machine vision-based method for detecting defects in socks according to claim 1, characterized in that, The specific steps of the adaptive growth algorithm based on fabric structure similarity region include: For each initial region, the set of contour feature points is used as the initial seed point set; Pixels satisfying the first constraint condition within the neighborhood of each initial seed point are selected and added to the initial seed point set to obtain a seed point set. The first constraint condition includes: the fabric structure consistency of the pixel is greater than a consistency threshold, the fabric structure consistency and consistency threshold are calculated based on the fabric structure similarity; the pixel is within the effective range of the initial region; the distance between the pixel and existing seed points is greater than a seed point spacing threshold, the seed point spacing threshold is determined by the average distance of adjacent contour feature points; all seed points in the seed point set are added to the unprocessed point queue Q and the segmented point set A; when the unprocessed point queue Q is not empty, the following is executed in a loop: a point p is taken from Q; for each point q in the neighborhood of p, if point q satisfies the second constraint condition, q is added to the segmented point set A and the unprocessed point queue Q; the second constraint condition includes: point q is not in the segmented point set A; point q is within the effective range of the initial region; the growth probability of q is greater than an adaptive threshold, the growth probability and the adaptive threshold are calculated based on the fabric structure similarity; when the unprocessed point queue Q is empty, the region adaptive growth ends.
6. The machine vision-based method for detecting defects in socks according to claim 1, characterized in that, The calculation steps for the shape difference are as follows: calculate the shape distance and phase distance between the shape of the fabric structure to be detected and the standard fabric structure shape model, calculate the total distance based on the shape distance and the phase distance, and obtain the shape difference.
7. The machine vision-based method for detecting defects in socks according to claim 1, characterized in that, The difference threshold is calculated based on the flawless sock image, and the specific steps are: to obtain all the fabric structure shapes in each region; Calculate the shape distance and phase distance between each fabric structure shape and the standard fabric structure shape model; calculate the total distance based on the shape distance and the phase distance to obtain the total distance set; Statistical analysis is performed on the total distance set, and the difference threshold is determined based on the upper limit of the total distance set.
8. A machine vision-based sock defect detection system, characterized in that, include: The image acquisition module acquires images of the socks to be inspected and corresponding images of flawless socks, and performs preprocessing. The region segmentation module constructs a multi-stage region segmentation algorithm to process the sock image to be detected and the flawless sock image respectively to obtain a set of regions to be detected and a set of flawless regions; The multi-stage region segmentation algorithm includes: constructing an energy function to obtain an initial region set; constructing an adaptive growth algorithm based on fabric structure similarity regions according to the initial region set to obtain a set of fabric structure consistent regions; and obtaining the region segmentation result according to the set of fabric structure consistent regions. The shape extraction module extracts the fabric structure shape of each region in the set of regions to be detected, and obtains a set of fabric structure shapes to be detected for each region; it also extracts the fabric structure shape of each region in the set of flawless regions, and calculates the mean value of all the fabric structure shapes in each region to obtain a standard fabric structure shape model for each region. The defect detection module calculates the shape difference between each fabric structure shape to be detected in the set of fabric structure shapes to be detected and the corresponding standard fabric structure shape model for each region in the set of fabric structure shapes to be detected. If the shape difference exceeds the difference threshold, the location of the fabric structure shape to be detected is marked as a defect point. The result integration module integrates the defect detection results of all regions to determine whether there are defect points in the image of the socks to be detected, and obtains the sock defect detection result; The specific steps for extracting the fabric structure shape include: generating a binarized edge image using an edge detection operator; performing connected component analysis on the binarized edge image to label each independent sub-region; extracting the contour point sequence of the independent sub-region using a neighborhood tracing algorithm; performing a closure test on the contour point sequence, and when the contour is not closed, interpolating through curve fitting to obtain a set of closed contour curves; and optimizing each closed contour curve in the set of closed contour curves to obtain the fabric structure shape. The square root velocity function is used to represent the shape of the fabric structure. Specifically, this includes: normalizing the optimized closed contour curve into a parametric equation; calculating the velocity vector and velocity vector magnitude of the closed contour curve based on the parametric equation to obtain the square root velocity function of the fabric structure shape, as shown in the following formula: Where β′(t) represents the derivative of the parametric equation of the closed contour curve, i.e. the velocity vector of the curve at time t; |β′(t)| represents the magnitude of the velocity vector; t∈[0,1].