High-precision cloth defect visual detection and automatic marking method

Through modular design and high-precision image processing technology, the problems of low efficiency and poor accuracy in fabric defect detection are solved, automatic marking and efficient fabric defect detection are achieved, and the reliability of detection results and production efficiency are improved.

CN120685662APending Publication Date: 2025-09-23YYC IND CO LTD CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510975285.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

Existing fabric defect detection technologies suffer from low efficiency and accuracy, and lack automatic marking capabilities, resulting in high labor costs and inconsistent detection results.

Method used

It adopts a modular design, including the establishment of standard modules, image acquisition modules, processing modules, marking modules and display modules. It uses linear array industrial cameras, industrial lenses and high-brightness industrial light sources for image acquisition, combines the Otsu algorithm and k-means clustering algorithm for image processing and defect detection, and automatically marks defect areas.

Benefits of technology

It achieves high-precision fabric defect detection and automatic marking, improves detection efficiency and accuracy, reduces labor costs, and ensures the consistency and reliability of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120685662A_ABST
    Figure CN120685662A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of cloth defect detection, in particular to a high-precision cloth defect visual detection and automatic marking method, which comprises a standard establishment module, an image acquisition module, a processing module, a marking module and a display module. The system has the advantages of modular design, accurate standard template, high-quality image acquisition, effective preprocessing and accurate detection; the whole detection and marking process is divided into establishment of a standard module, an image acquisition module, a processing module, a marking module and a display module, the modules are clear in division of labor, and different modules can be independently optimized and improved, so that the expandability and flexibility of the system are improved; the standard establishing module performs image acquisition and processing on areas without surface defects, adopts different processing modes for different fabrics (with patterns and without patterns), can establish an accurate standard template, and automatically calculates an optimal gray threshold value by using an Otsu algorithm, so that the accuracy of threshold value setting is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cloth defect detection, and in particular to a high-precision cloth defect visual detection and automatic marking method. Background Art

[0002] Fabric defect detection is a crucial part of the textile production process. Its purpose is to ensure that the quality of the fabric meets the standards and reduce the defective rate.

[0003] For fabric defect detection, most factories use manual inspection, which is repetitive labor and requires a lot of time and manpower. When inspecting large quantities of fabrics, the efficiency is extremely low and cannot meet the rapid needs of modern production. Long-term manual observation can easily lead to eye fatigue, resulting in misjudgment and reduced fabric defect identification rate. In addition, different inspectors may have inconsistent defect judgment standards for a single product, affecting the accuracy and reliability of the inspection results. Secondly, some factories use traditional machine vision inspection systems. Due to insufficient signal-to-noise ratio of the camera and insufficient brightness of the light source, the image quality is poor and the features are not obvious, which affects the accuracy of defect detection. For different types and specifications of fabrics, traditional machine vision inspection systems may lack effective adaptability, making it difficult to establish accurate standard templates and inspection models, resulting in inaccurate inspection results. Some traditional machine vision inspection systems can only detect fabric defects, but lack automatic marking functions and require manual marking, which increases labor costs and the possibility of errors.

[0004] Therefore, there is an urgent need for a high-precision visual detection and automatic marking method for fabric defects to solve the above problems. Summary of the Invention

[0005] The purpose of the present invention is to provide a high-precision visual detection and automatic marking method for fabric defects, which has the advantages of modular design, precise standard templates, high-quality image acquisition, effective preprocessing, and accurate detection, and solves the problems raised by the above-mentioned background technology.

[0006] To achieve the above objectives, the present invention provides the following technical solution: a high-precision visual detection and automatic marking method for fabric defects, comprising a standard establishment module, an image acquisition module, a processing module, a marking module and a display module.

[0007] Establish a standard module and use the modeling module to establish a standard template for the fabric to be inspected.

[0008] The image acquisition module is used to take pictures of the current fabric to be inspected line by line and synthesize images to be inspected.

[0009] The processing module pre-processes each image to be inspected to obtain a final image to be inspected, ensuring that the detection boundary of each final image to be inspected is consistent with the detection boundary of the standard sample image.

[0010] The marking module is used to attach marking labels to the edges of defective areas of the fabric.

[0011] The display module is used to clearly display the fabric surface image and detection results in real time.

[0012] Furthermore, as a preferred embodiment of the present invention, the standard establishment module includes a surface defect area segment selection module, a row image acquisition module, a standard sample image synthesis module, a patternless fabric processing module, a periodically changing patterned fabric processing module, a grayscale threshold setting module and a standard template saving module.

[0013] Furthermore, as a preferred embodiment of the present invention, the image acquisition module includes a linear array industrial camera, an industrial lens, a high-brightness industrial light source and an encoder.

[0014] Furthermore, as a preferred embodiment of the present invention, the processing module includes an illumination normalization module, a brightness compensation module, and an edge detection and cropping module.

[0015] Furthermore, as a preferred embodiment of the present invention, the display module displays the fabric surface image and the detection result through a display screen.

[0016] The present invention provides a high-precision visual inspection and automatic marking method for fabric defects, the method comprising the following steps:

[0017] Step 1: Establishment of standard template: During the fabric conveying process, through manual observation and preliminary image analysis, a fabric area with no surface defects is selected for image acquisition. This area is representative and can reflect the normal texture and characteristics of this batch of fabrics; the image acquisition module is used to take pictures of the fabric area without surface defects line by line to form a series of line images. The exposure parameters of the camera are adjusted according to the material, color and lighting conditions of the fabric to ensure that the collected line images are clear and of moderate brightness. The line images of a set number of lines are synthesized in the acquisition order to form a standard sample image. During the synthesis process, the alignment accuracy between the line images is ensured to avoid image stitching errors; for fabrics without patterns, the edge detection algorithm is used to detect the non-fabric areas and fabric edges on the left and right sides of the standard sample image, and then these areas are removed by cropping to complete the left and right detection edges. The cropped image should only contain the fabric area that needs to be inspected; collect at least two standard sample images and synthesize them into a synthetic sample image containing a repeated pattern. During the synthesis process, ensure the alignment accuracy between the images to avoid pattern dislocation; perform pixel analysis on the synthetic sample image, use a template matching algorithm or a feature extraction algorithm to identify the unit of the repeated pattern, and then, through a cropping operation, crop the image containing only one repeated pattern unit as the standard sample image of the template; perform grayscale statistical analysis on the standard sample image, calculate the grayscale histogram of the image, set the grayscale threshold for defect judgment according to the distribution of the histogram, and use the Otsu algorithm to automatically calculate the optimal grayscale threshold to improve the accuracy of the threshold setting; save the processed standard sample image and the set grayscale threshold in the database as a reference template for subsequent detection;

[0018] Step 2: Use a linear array industrial camera to capture detailed information on the fabric surface, and then use an industrial lens to reproduce the fine structure of the fabric. The high-brightness industrial light source can provide uniform and stable lighting to ensure that the captured image is evenly illuminated, thereby forming a row image containing position information. The encoder uses the number of meters of fabric corresponding to the last row image of the synthesized image to be inspected as the position information of the image to be inspected, and transmits this information together with the row image to the processing module; the row images with the same number of rows as the standard template are synthesized in the acquisition order to form a series of images to be inspected. During the synthesis process, the alignment accuracy between the row images is ensured to avoid image stitching errors;

[0019] Step 3: Perform histogram equalization on the collected image to be inspected, and enhance the contrast of the image by adjusting the grayscale distribution of the image. The specific steps are as follows: calculate the grayscale histogram of the image to be inspected, and count the number of pixels at each grayscale level; calculate the cumulative distribution function based on the histogram; adjust the grayscale value of each pixel of the image based on the cumulative distribution function, and map the original grayscale value to a new grayscale value range; collect a reference image with uniform illumination, calculate the average grayscale value of the reference image, and then adjust the grayscale value of each pixel of the image to keep it consistent with the average grayscale value of the reference image. The specific steps are as follows: collect a reference image R with uniform illumination, and calculate the average grayscale value R avg ; For each pixel I(x, y) of the image to be inspected, calculate its ratio to the average grayscale value of the reference image k(x, y) = R avg / R(x, y); adjust the grayscale value of each pixel of the image to be inspected according to the ratio k(x, y) to obtain the image I after brightness compensation comp (x, y) = I(x, y) * k(x, y); Use an edge detection algorithm to detect the edges of the fabric in the image captured by the camera. By adjusting the parameters of the edge detection algorithm, the image is cropped according to the detected fabric edges, retaining only the fabric image data to be detected, and cropping the background and the raw edges of the fabric boundary. The cropped image should only contain the effective detection area of ​​the fabric;

[0020] Step 4: Perform k-means clustering algorithm on the standard sample image after brightness compensation to divide the pixels in the image into k different categories. The specific steps are as follows:

[0021] a. Initialize k cluster centers C1, C2, ..., C K ;

[0022] b. Calculate the Euclidean distance between each pixel and each cluster center, and assign the pixel to the category of the cluster center closest to it;

[0023] c. Update the center position of each cluster based on the allocation results;

[0024] d. Repeat steps a and b until the cluster center no longer changes or the maximum number of iterations is reached;

[0025] Calculate the average pixel distance, standard deviation, and maximum and minimum pixel distance characteristic parameters in each cluster item, and store these parameters in a computer database as a reference for subsequent comparative testing;

[0026] Compare the preprocessed image to be tested with the standard sample image one by one, calculate the Euclidean distance between the pixel of the image to be tested and the cluster center, and for each pixel point P(x, y) in the image to be tested, calculate its distance to each cluster center C i Euclidean distance

[0027] Among them, (xi, yi) is the cluster center C i The coordinates of the fabric are determined, and a suitable Euclidean distance threshold is set based on the previously calculated feature parameters. If the Euclidean distance between the pixel of the image to be detected and the cluster center is within the set threshold range, the measured fabric image is judged to be qualified; otherwise, it is judged that there are defects in the measured fabric image.

[0028] Step 5: Use a labeling machine to attach a marking label to the edge of the defective area of ​​the fabric, and display the fabric surface image and detection results on the display module so that the operator can accurately observe the defects of the fabric.

[0029] Beneficial effects: The technical solution of this application has the following technical effects: the present invention has the advantages of modular design, precise standard template, high-quality image acquisition, effective preprocessing and accurate detection.

[0030] The entire detection and marking process is divided into a standard establishment module, an image acquisition module, a processing module, a marking module, and a display module. Each module has a clear division of labor, and different modules can be optimized and improved independently, which improves the scalability and flexibility of the system.

[0031] The standard module is established by collecting and processing images of areas without surface defects, adopting different processing methods for different fabrics (with and without patterns), and can establish accurate standard templates. The Otsu algorithm is used to automatically calculate the optimal grayscale threshold, which improves the accuracy of threshold setting and provides a reliable reference for subsequent defect detection.

[0032] The image acquisition module uses a combination of linear array industrial cameras, industrial lenses and high-brightness industrial light sources. It can clearly capture detailed information on the surface of the fabric, provide uniform and stable lighting, and ensure the high quality of the collected images. The use of encoders ensures that the collected line images contain accurate position information, which facilitates subsequent defect location.

[0033] Preprocessing steps in the processing module, such as illumination normalization, brightness compensation, edge detection, and cropping, can effectively eliminate the effects of uneven illumination, inconsistent lens response, and other factors on the image, thereby improving image quality and contrast, highlighting fabric features, and providing clearer image data for subsequent defect detection.

[0034] The k-means clustering algorithm is used for feature extraction and comparative detection. An optional method of unsupervised learning-assisted detection is also provided, which can more accurately detect defects in fabrics. By calculating the Euclidean distance between pixels and cluster centers and setting appropriate thresholds, the accuracy and reliability of defect detection are improved.

[0035] The marking module can label the edges of fabric defects, facilitating subsequent processing and identification. The display module clearly displays the fabric surface image and inspection results in real time, allowing operators to promptly identify and address fabric defects, improving production efficiency and product quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0037] Figure 1 Flow chart of the steps of the present invention;

[0038] Figure 2 This is the grayscale histogram analysis diagram of the fabric image of the present invention. DETAILED DESCRIPTION

[0039] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. In order to better understand the technical content of the present invention, specific embodiments are cited and explained in conjunction with the drawings as follows. Various aspects of the present invention are described in this disclosure with reference to the drawings, which show many illustrative embodiments. It should be understood that the various concepts and embodiments introduced above, as well as those described in more detail below, can be implemented in any of many ways. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0040] As attached Figure 1 To the attached Figure 2 As shown: This embodiment provides a high-precision visual detection and automatic marking method for fabric defects, including a standard establishment module, an image acquisition module, a processing module, a marking module and a display module.

[0041] Establish a standard module and use the modeling module to establish a standard template for the fabric to be inspected.

[0042] The image acquisition module is used to take pictures of the current fabric to be inspected line by line and synthesize images to be inspected.

[0043] The processing module pre-processes each image to be inspected to obtain a final image to be inspected, ensuring that the detection boundary of each final image to be inspected is consistent with the detection boundary of the standard sample image.

[0044] The marking module is used to attach marking labels to the edges of defective areas of the fabric.

[0045] The display module is used to clearly display the fabric surface image and detection results in real time.

[0046] Specifically, the standard module includes a surface defect area segment selection module, a line image acquisition module, a standard sample image synthesis module, a patternless fabric processing module, a periodically changing patterned fabric processing module, a grayscale threshold setting module and a standard template saving module.

[0047] Specifically, the image acquisition module includes a linear array industrial camera, an industrial lens, a high-brightness industrial light source and an encoder.

[0048] Specifically, the processing module includes an illumination normalization module, a brightness compensation module, and an edge detection and cropping module.

[0049] Specifically, the display module displays the fabric surface image and the detection result through the display screen.

[0050] The present invention provides a high-precision visual inspection and automatic marking method for fabric defects, the method comprising the following steps:

[0051] Step 1: Establishment of standard template: During the fabric conveying process, through manual observation and preliminary image analysis, a fabric area with no surface defects is selected for image acquisition. This area is representative and can reflect the normal texture and characteristics of this batch of fabrics; the image acquisition module is used to take pictures of the fabric area without surface defects line by line to form a series of line images. The exposure parameters of the camera are adjusted according to the material, color and lighting conditions of the fabric to ensure that the collected line images are clear and of moderate brightness. The line images of a set number of lines are synthesized in the acquisition order to form a standard sample image. During the synthesis process, the alignment accuracy between the line images is ensured to avoid image stitching errors; for fabrics without patterns, the edge detection algorithm is used to detect the non-fabric areas and fabric edges on the left and right sides of the standard sample image, and then these areas are removed by cropping to complete the left and right detection edges. The cropped image should only contain the fabric area that needs to be inspected; collect at least two standard sample images and synthesize them into a synthetic sample image containing a repeated pattern. During the synthesis process, ensure the alignment accuracy between the images to avoid pattern dislocation; perform pixel analysis on the synthetic sample image, use a template matching algorithm or a feature extraction algorithm to identify the unit of the repeated pattern, and then, through a cropping operation, crop the image containing only one repeated pattern unit as the standard sample image of the template; perform grayscale statistical analysis on the standard sample image, calculate the grayscale histogram of the image, set the grayscale threshold for defect judgment according to the distribution of the histogram, and use the Otsu algorithm to automatically calculate the optimal grayscale threshold to improve the accuracy of the threshold setting; save the processed standard sample image and the set grayscale threshold in the database as a reference template for subsequent detection;

[0052] Step 2: Use a linear array industrial camera to capture detailed information on the fabric surface, and then use an industrial lens to reproduce the fine structure of the fabric. The high-brightness industrial light source can provide uniform and stable lighting to ensure that the captured image is evenly illuminated, thereby forming a row image containing position information. The encoder uses the number of meters of fabric corresponding to the last row image of the synthesized image to be inspected as the position information of the image to be inspected, and transmits this information together with the row image to the processing module; the row images with the same number of rows as the standard template are synthesized in the acquisition order to form a series of images to be inspected. During the synthesis process, the alignment accuracy between the row images is ensured to avoid image stitching errors;

[0053] Step 3: Perform histogram equalization on the collected image to be inspected, and enhance the contrast of the image by adjusting the grayscale distribution of the image. The specific steps are as follows: calculate the grayscale histogram of the image to be inspected, and count the number of pixels at each grayscale level; calculate the cumulative distribution function (CDF) based on the histogram; adjust the grayscale value of each pixel of the image according to the cumulative distribution function, and map the original grayscale value to a new grayscale value range; collect a reference image with uniform illumination, calculate the average grayscale value of the reference image, and then adjust the grayscale value of each pixel of the image to keep it consistent with the average grayscale value of the reference image. The specific steps are as follows: collect a reference image R with uniform illumination, and calculate the average grayscale value R avg ; For each pixel I(x, y) of the image to be inspected, calculate its ratio to the average grayscale value of the reference image k(x, y) = R avg / R(x, y); adjust the grayscale value of each pixel of the image to be inspected according to the ratio k(x, y) to obtain the image I after brightness compensation comp (x, y) = I(x, y) * k(x, y); Use an edge detection algorithm to detect the edges of the fabric in the image captured by the camera. By adjusting the parameters of the edge detection algorithm, the image is cropped according to the detected fabric edges, retaining only the fabric image data to be detected, and cropping the background and the raw edges of the fabric boundary. The cropped image should only contain the effective detection area of ​​the fabric;

[0054] Step 4: Perform k-means clustering algorithm on the standard sample image after brightness compensation to divide the pixels in the image into k different categories. The specific steps are as follows:

[0055] a. Initialize k cluster centers C1, C2, ..., C K ;

[0056] b. Calculate the Euclidean distance between each pixel and each cluster center, and assign the pixel to the category of the cluster center closest to it;

[0057] c. Update the center position of each cluster based on the allocation results;

[0058] d. Repeat steps a and b until the cluster center no longer changes or the maximum number of iterations is reached;

[0059] Calculate the average pixel distance, standard deviation, and maximum and minimum pixel distance characteristic parameters in each cluster item, and store these parameters in a computer database as a reference for subsequent comparative testing;

[0060] Compare the preprocessed image to be tested with the standard sample image one by one, calculate the Euclidean distance between the pixel of the image to be tested and the cluster center, and for each pixel point P(x, y) in the image to be tested, calculate its distance to each cluster center C i Euclidean distance

[0061] Among them, (xi, yi) is the cluster center C i The coordinates of the fabric are determined, and a suitable Euclidean distance threshold is set based on the previously calculated feature parameters. If the Euclidean distance between the pixel of the image to be detected and the cluster center is within the set threshold range, the measured fabric image is judged to be qualified; otherwise, it is judged that there are defects in the measured fabric image.

[0062] Step 5: Use a labeling machine to attach a marking label to the edge of the defective area of ​​the fabric, and display the fabric surface image and detection results on the display module so that the operator can accurately observe the defects of the fabric.

[0063] It should be noted that, in this document, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.

[0064] While the present invention has been disclosed above with reference to preferred embodiments, this is not intended to limit the present invention. Persons skilled in the art will readily appreciate that various modifications and variations can be made without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be determined by the claims.

Claims

1. A high-precision visual inspection and automatic marking method for fabric defects, characterized by: Including building standard module, image acquisition module, processing module, marking module and display module; Establish a standard module and use the modeling module to establish a standard template for the fabric to be inspected; Image acquisition module, using the image acquisition module to take pictures of the current fabric to be inspected line by line, and synthesize images to be inspected; A processing module is used to pre-process each image to be inspected to obtain a final image to be inspected, and ensure that the detection boundary of each final image to be inspected is consistent with the detection boundary of the standard sample image; A marking module, used for attaching a marking label to the edge of the defective area of ​​the fabric; The display module is used to clearly display the fabric surface image and detection results in real time.

2. The high-precision visual inspection and automatic marking method for fabric defects according to claim 1, characterized in that: The standard establishment module includes a surface defect area segment selection module, a line image acquisition module, a standard sample image synthesis module, a patternless fabric processing module, a periodically changing patterned fabric processing module, a grayscale threshold setting module and a standard template storage module.

3. The high-precision visual inspection and automatic marking method for fabric defects according to claim 1, characterized in that: The image acquisition module includes a linear array industrial camera, an industrial lens, a high-brightness industrial light source and an encoder.

4. The high-precision visual inspection and automatic marking method for fabric defects according to claim 1, characterized in that: The processing module includes an illumination normalization module, a brightness compensation module, and an edge detection and cropping module.

5. The high-precision visual inspection and automatic marking method for fabric defects according to claim 1, characterized in that: The display module displays the cloth surface image and the detection result through a display screen.

6. A high-precision visual inspection and automatic marking method for fabric defects, characterized by: The method comprises the following steps: Step 1: Establishment of standard template: During the fabric conveying process, through manual observation and preliminary image analysis, a fabric area with no surface defects is selected for image acquisition. This area is representative and can reflect the normal texture and characteristics of this batch of fabrics; the image acquisition module is used to take pictures of the fabric area without surface defects line by line to form a series of line images. The exposure parameters of the camera are adjusted according to the material, color and lighting conditions of the fabric to ensure that the collected line images are clear and of moderate brightness. The line images of a set number of lines are synthesized in the acquisition order to form a standard sample image. During the synthesis process, the alignment accuracy between the line images is ensured to avoid image stitching errors; for fabrics without patterns, the edge detection algorithm is used to detect the non-fabric areas and fabric edges on the left and right sides of the standard sample image, and then these areas are removed by cropping to complete the left and right detection edges. The cropped image should only contain the fabric area that needs to be inspected; collect at least two standard sample images and synthesize them into a synthetic sample image containing a repeated pattern. During the synthesis process, ensure the alignment accuracy between the images to avoid pattern dislocation; perform pixel analysis on the synthetic sample image, use a template matching algorithm or a feature extraction algorithm to identify the unit of the repeated pattern, and then, through a cropping operation, crop the image containing only one repeated pattern unit as the standard sample image of the template; perform grayscale statistical analysis on the standard sample image, calculate the grayscale histogram of the image, set the grayscale threshold for defect judgment according to the distribution of the histogram, and use the Otsu algorithm to automatically calculate the optimal grayscale threshold to improve the accuracy of the threshold setting; save the processed standard sample image and the set grayscale threshold in the database as a reference template for subsequent detection; Step 2: Use a linear array industrial camera to capture detailed information on the fabric surface, and then use an industrial lens to reproduce the fine structure of the fabric. The high-brightness industrial light source can provide uniform and stable lighting to ensure that the captured image is evenly illuminated, thereby forming a row image containing position information. The encoder uses the number of meters of fabric corresponding to the last row image of the synthesized image to be inspected as the position information of the image to be inspected, and transmits this information together with the row image to the processing module; the row images with the same number of rows as the standard template are synthesized in the acquisition order to form a series of images to be inspected. During the synthesis process, the alignment accuracy between the row images is ensured to avoid image stitching errors; Step 3: Perform histogram equalization on the collected image to be inspected, and enhance the contrast of the image by adjusting the grayscale distribution of the image. The specific steps are as follows: calculate the grayscale histogram of the image to be inspected, and count the number of pixels at each grayscale level; calculate the cumulative distribution function based on the histogram; adjust the grayscale value of each pixel of the image based on the cumulative distribution function, and map the original grayscale value to a new grayscale value range; collect a reference image with uniform illumination, calculate the average grayscale value of the reference image, and then adjust the grayscale value of each pixel of the image to keep it consistent with the average grayscale value of the reference image. The specific steps are as follows: collect a reference image R with uniform illumination, and calculate the average grayscale value R avg ; For each pixel I(x, y) of the image to be inspected, calculate its ratio to the average grayscale value of the reference image k(x, y) = R avg / R(x, y); adjust the grayscale value of each pixel of the image to be inspected according to the ratio k(x, y) to obtain the image I after brightness compensation comp (x, y) = I(x, y) * k(x, y); Use an edge detection algorithm to detect the edges of the fabric in the image captured by the camera. By adjusting the parameters of the edge detection algorithm, the image is cropped according to the detected fabric edges, retaining only the fabric image data to be detected, and cropping the background and the raw edges of the fabric boundary. The cropped image should only contain the effective detection area of ​​the fabric; Step 4: Perform k-means clustering algorithm on the standard sample image after brightness compensation to divide the pixels in the image into k different categories. The specific steps are as follows: a. Initialize k cluster centers C1, C2, ..., C K ; b. Calculate the Euclidean distance between each pixel and each cluster center, and assign the pixel to the category of the cluster center closest to it; c. Update the center position of each cluster based on the allocation results; d. Repeat steps a and b until the cluster center no longer changes or the maximum number of iterations is reached; Calculate the average pixel distance, standard deviation, and maximum and minimum pixel distance characteristic parameters in each cluster item, and store these parameters in a computer database as a reference for subsequent comparative testing; Compare the preprocessed image to be tested with the standard sample image one by one, calculate the Euclidean distance between the pixel of the image to be tested and the cluster center, and for each pixel point P(x, y) in the image to be tested, calculate its distance to each cluster center C i Euclidean distance Among them, (xi, yi) is the cluster center C i The coordinates of the fabric are determined, and a suitable Euclidean distance threshold is set based on the previously calculated feature parameters. If the Euclidean distance between the pixel of the image to be detected and the cluster center is within the set threshold range, the measured fabric image is judged to be qualified; otherwise, it is judged that there are defects in the measured fabric image. Step 5: Use a labeling machine to attach a marking label to the edge of the defective area of ​​the fabric, and display the fabric surface image and detection results on the display module so that the operator can accurately observe the defects of the fabric.