Sewing stitch length detection method and system based on machine vision

Through the sewing stitch spacing detection method based on machine vision, the shortcomings of manual detection are solved, efficient and accurate automatic spacing detection is achieved, and the quality and production efficiency of textiles are improved.

CN120259236APending Publication Date: 2025-07-04DONGHUA UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510334017.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-20
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The needle distance detection in existing textile production lines relies on manual methods, resulting in high labor costs, large inspection errors and inaccurateness, making it difficult to meet the strict quality requirements of high-end clothing brands.

Method used

The sewing stitch distance detection method based on machine vision is adopted, including image acquisition and preprocessing, image enhancement, semantic segmentation network model, loss function and single-hot encoding training, opening and closing operation denoising and needle distance calculation, to realize automated detection.

Benefits of technology

It improves the accuracy and consistency of needle distance detection, reduces artificial errors, and improves the production efficiency and clothing quality of the textile manufacturing industry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120259236A_ABST
    Figure CN120259236A_ABST
Patent Text Reader

Abstract

The invention discloses a sewing stitch stitch length detection method based on machine vision. The method comprises eight key modules including image acquisition and preprocessing, image enhancement, loss function and one-hot coding training, semantic segmentation network model (based on a U-net framework), detection, open operation denoising, point-line connection algorithm and stitch length calculation. Compared with a traditional target detection method based on YOLO, the method has remarkable advantages for detection of the stitch length of the sewing stitches. The method can be used for sewing stitch recognition, denoising, stitch positioning and stitch length measurement, recognition and positioning are carried out in a semantic segmentation mode, and automatic detection of textile sewing quality is achieved. After the method disclosed by the invention is adopted, the detection accuracy and consistency can be improved, and the product quality and the production efficiency of the textile manufacturing industry are improved. According to the automatic stitch length detection technology, personal errors can be reduced, the production efficiency is improved, the cost is reduced, and the overall quality of clothes is finally improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for detecting the stitch density of sewing thread based on machine vision, belonging to the technical field of sewing detection. Background Art

[0002] The stitch density, that is, the interval between sewing needles during the sewing process, has a direct impact on the durability, appearance, and comfort of clothing. However, the problems of uneven or non-standard stitch density often occur during the production process, which may lead to insecure stitching, unappealing appearance of clothing, and even affect the wearing comfort. High-end clothing brands have stricter quality control over clothing, and the stitch density of clothing directly affects the company's sales profit.

[0003] Although the stitch density problem is crucial for product quality, most current textile production lines rely on manual inspection methods. Workers need to visually observe to identify whether the stitch density meets the requirements. This method not only increases labor costs and work burdens, but also is prone to detection errors due to human factors, such as deviations in subjective judgment and visual fatigue caused by long working hours. Summary of the Invention

[0004] The objective of the present invention is to develop an automated and efficient stitch density detection technology to reduce the dependence on manual inspection.

[0005] To achieve the above objective, the technical solution of the present invention discloses a method for detecting the stitch density of sewing thread based on machine vision, which is characterized by including the following steps:

[0006] Step 1: Collect sewing thread stitch images, collect images classified by the color of the sewing thread stitch and the material of the base fabric, label the sewing thread stitch images, and then construct a training set and a test set. Among them, the training set consists of sewing thread stitch images of each category and their corresponding true label maps;

[0007] Step 2: Perform training preprocessing operations on the sewing thread stitch images and their corresponding true label maps in the training set, splice the sewing thread stitch images and their corresponding true label maps into multi-channel images, and perform data augmentation operations on the multi-channel images;

[0008] Step 3: Use the training set obtained in Step 2 to train a semantic segmentation network, and use the test set to test the trained semantic segmentation network. During training:

[0009] Use one-hot encoding to convert the two-dimensional category label array into a three-dimensional one-hot encoding array;

[0010] Design a loss function based on the cross-entropy loss principle, calculate the loss by comparing pixel by pixel, and update the network parameters through backpropagation, where:

[0011] Process the task when the background color is different from the stitch color, and select the cross-entropy loss L C" ;

[0012] Process the task when the background color is the same as the stitch color, and select the Combined Loss2 loss L Co$ %i n ( dL o++ ,:

[0013]

[0014] In the formula, β is the weight hyperparameter, CrossEntropyLoss is the cross-entropy loss for each pixel classification, and DiceLoss is the loss based on the Dice coefficient:

[0015]

[0016] where y i-. / ( is the true label, and y i0.(d is the predicted value;

[0017] By adjusting the weight hyperparameter β and adding additional loss items, the segmentation accuracy is improved;

[0018] Step 4: Use the trained semantic segmentation network to generate pixel-level stitch and background segmentation images, and then use the opening and closing operation method provided by the cv2 module in the OpenCV library to denoise the white noise points in the background segmentation image obtained after segmentation to obtain the stitch pitch detection background image;

[0019] Step 5: Based on the stitch pitch detection background image denoised by the opening and closing operation method, calculate the stitch pitch by constructing a stitch point set class and point objects.

[0020] Preferably, in step 1, when collecting the sewing stitch image, install a high-resolution camera and an adjustable-brightness ring light source at an appropriate position on the sewing trajectory. Among them, the ring light source is used to provide different brightnesses for different colors of sewing stitches; when collecting sewing stitch images of the same category, the industrial control computer controls the high-resolution camera and the ring light source to collect sewing stitch data under a set of fixed camera parameters and given constant light source conditions.

[0021] Preferably, in step 1, uniformly crop the sewing stitch image and its corresponding true label image, and modify the image format.

[0022] Preferably, in step 2, when performing data augmentation operations, perform rotation and stretching processing on multi-channel images, specifically including the following steps:

[0023] Generate multiple iterable enhanced data graph objects using the product method in the itertools library. Under a certain rotation angle and stretching degree, use the cv2 module in OpenCV to stretch and rotate a single image.

[0024] Preferably, in step 3, the semantic segmentation network is a U-net network. Based on the principle of the U-Net network framework, by performing upsampling to restore pixel processing and downsampling feature extraction processing on the image, an asymmetric network with 4 encoding layers and 3 decoding layers is designed to balance speed and accuracy in segmenting sewing thread traces.

[0025] Preferably, in step 3, the cross-entropy loss L C" is expressed as:

[0026]

[0027] In the formula, N represents the number of samples, C represents the number of categories, i represents the i-th sample, and y i,5 represents the label of the true category c of sample i, and p i ,c represents the predicted probability that the model assigns sample i to category c.

[0028] Preferably, when testing the semantic segmentation network in step 3:

[0029] Use the sliding window algorithm to gradually scan the image and extract a sub-image patch at each position to solve the specific reason for the large image calculation bottleneck;

[0030] Use the overlapping region and cropping technology to ensure that the predictions of each sub-image patch can be smoothly merged into the original image. Feed the sub-image patches into the semantic segmentation network one by one for prediction.

[0031] Preferably, step 5 includes the following steps:

[0032] Construct a floatPointsList point set, find the left and right neighbor points, extract the centroid coordinates of the white thread trace region, calculate the Euclidean distance between adjacent centroids as the stitch length, and connect adjacent points in pairs through the plot method in matplotlib.pyplot;

[0033] Output the stitch point distances obtained from the loop judgment for the first time in the custom minimum value algorithm, and save them to the right adjacent point distance attribute of each point through the distance calculation method for subsequent correction of the mechanical device according to the stitch length on the hardware side.

[0034] Another technical solution of the present invention discloses a sewing thread trace stitch length detection system based on machine vision, which is characterized by including:

[0035] The image acquisition and preprocessing module is used to acquire sewing thread trace images. Based on the idea of forming a multi-channel image with a frontlight image and a true label image, the acquired and preliminarily processed images are uniformly sized and cropped, and the image format is modified; the training images are input into the segmentation network to generate corresponding semantic segmentation images;

[0036] The image enhancement module is used for image data enhancement. Through data enhancement methods, rotation and stretching processing are performed to increase the richness of the dataset. The enhanced data is used as the training basis to train the semantic segmentation network, obtaining a richer training set with fewer initial samples and enhancing the generalization ability;

[0037] The loss function and one-hot encoding training module is used to design a pixel-by-pixel comparison training strategy; the one-hot encoding idea is introduced to convert a two-dimensional category label array into a three-dimensional one-hot encoding array. Based on the cross-entropy loss principle, a loss function is designed to calculate the loss by pixel-by-pixel comparison and update the network parameters through backpropagation;

[0038] The semantic segmentation network model module is used to segment the acquired image into thread traces and background images. Based on networks such as U-Net, U-net++, U-net++(L3), or SegNet, and based on the properties of the encoder and decoder, through upsampling to restore pixel processing and downsampling feature extraction processing of the image, a pixel-level segmented thread trace effect diagram is obtained;

[0039] The detection module is used to input the test image into the trained segmentation network to obtain a preliminary segmented result image, and perform denoising operations on the obtained image to better determine the specific position of the sewing thread trace part of the sewing image.

[0040] Compared with traditional methods based on object detection algorithms such as YOLO, the present invention has significant advantages for the sewing thread trace stitch detection task. The image acquisition and preprocessing module and the image enhancement module can effectively improve the quality of training data; the loss function and one-hot encoding training module and the semantic segmentation network model module are designed specifically for pixel-level precise segmentation of sewing thread traces and can locate the thread traces more accurately, which is difficult to achieve by the YOLO algorithm because YOLO mainly focuses on object bounding box detection rather than pixel-level segmentation. The detection and opening operation denoising module can accurately process the test image and remove noise interference. The combination of the point-line connection algorithm module and the stitch calculation module can not only accurately calculate the stitch, but also visually present the result with a point-line connection diagram, facilitating the inspection of connection correctness, while YOLO has deficiencies in result visualization and thread trace detail presentation.

[0041] In summary, the present invention can achieve high-precision positioning and stitch detection of sewing thread trace segments in an industrial production environment, effectively ensuring the accuracy and reliability of automated detection of sewing thread trace quality, and is more suitable for sewing production scenarios with high requirements for stitch accuracy. Description of the Drawings

[0042] Figure 1 is a flowchart of a sewing stitch distance detection method based on machine vision provided by an embodiment of this specification;

[0043] Figure 2 is a schematic diagram of the principle of denoising operation provided by an embodiment of this specification;

[0044] Figure 3 is a flowchart of training and testing based on the U-net model provided by an embodiment of this specification;

[0045] Figure 4 is a U-net framework diagram for testing provided by an embodiment of this specification;

[0046] Figure 5 is a stitch punctuation and stitch distance calculation diagram provided by an embodiment of this specification. Detailed Description of the Invention

[0047] The following further elaborates the present invention in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and not to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms also fall within the scope defined by the appended claims of this application.

[0048] The technical solutions disclosed by the present invention include:

[0049] Install a high-resolution camera at an appropriate position on the sewing trajectory to collect the front-light image information of the sewing stitch;

[0050] Install an adjustable-brightness annular light source at an appropriate position on the sewing trajectory to provide different brightnesses for different-color sewing stitches;

[0051] Receive the on-site stitch distance detection task instruction through an industrial control computer, control the camera to collect the sewing stitch data under certain parameters, and use the U-net model framework to segment the collected sewing image.

[0052] Send an instruction through the industrial control computer to control the camera to collect the front-light image data of the sewing stitch.

[0053] For the preliminarily collected front-light image data, based on the idea of the image acquisition and preprocessing module to form a multi-channel image from the front-light image and the real label image, uniformly crop the collected and preliminarily processed images to a size of 256×256, and uniformly modify the image format to "PNG".

[0054] For the preprocessed image data, import the image enhancement module to perform rotation and stretching processing, increase the richness of the dataset, use the enhanced data as the training basis, and train the semantic segmentation network to obtain a richer training set with fewer initial samples and enhance the generalization ability.

[0055] Use the product method in the itertools library to generate multiple iterable enhanced data graph objects. Under a certain rotation angle and stretching degree, use the cv2 module in OpenCV to stretch and rotate a single preprocessed image.

[0056] Use the cv2 module to split the training data and labels of multi-channel images to match the input and output settings of the U-net model.

[0057] For the basic settings of the network before training, adopt the training strategy of pixel-by-pixel comparison using the loss function and one-hot encoding training module.

[0058] Use one-hot encoding to convert the two-dimensional category label array into a three-dimensional one-hot encoding array. Design the loss function based on the principle of cross-entropy loss, calculate the loss by pixel-by-pixel comparison, and update the network parameters through backpropagation.

[0059] For the framework of the segmentation network model, adopt the semantic segmentation network model module to segment the stitch and background images of the collected images.

[0060] Use the asymmetric U-net network (4 encoding layers, 3 decoding layers) to reduce the computational complexity by reducing the depth of the decoding layer, while retaining sufficient feature extraction ability, balancing speed and accuracy, and can quickly construct the pixel-level stitch segmentation result map and calculate the stitch pitch, which is especially suitable for real-time stitch pitch detection in industrial scenarios.

[0061] For the trained U-net model, enter the detection module, set the model to "test mode", and detect the sewing stitch image collected by the camera.

[0062] Use the sliding window algorithm to gradually scan the image and extract a sub-image block at each position.

[0063] Use the overlapping area and cropping technology to ensure that the predictions of each small block can be smoothly merged into the original image. By feeding each block into the model for prediction one by one, the computational bottleneck of directly inputting the entire image into the model is avoided.

[0064] For the binary image data obtained from the preliminary segmentation of the U-net model framework, import the binary operation denoising module, adjust the size of the opening operation convolution kernel, introduce the denoising algorithm, and reprocess the intermediate result image to obtain the stitch pitch detection background image.

[0065] Use the opening and closing operation method provided by the cv2 module in the OpenCV library to denoise the segmented white noise points, avoiding incorrect stitch weft floating points caused by inaccurate segmentation results due to conditions such as lighting.

[0066] For the denoised stitch background image data, use the point-line connection algorithm module to punctuate the white blocks for calculating the stitch distance between points. Based on the point set class point object, pack all the mass points into a list and output the quantity to intuitively check whether the segmented stitch segments are accurate.

[0067] Use floatPointsList to construct a point set, randomly initialize a starting detection point, use a loop to judge and find the left and right neighbor points, and mark the points to the centroid of the corresponding white block. Finally, connect the adjacent points pairwise through the plot method in matplotlib.pyplot.

[0068] For the image data after point-line connection, calculate the distance between points after finding adjacent points in a loop through the stitch distance calculation module, and save it to the right adjacent point distance attribute of each point through a custom distance calculation method.

[0069] As Figure 1 shown, a machine vision-based sewing stitch distance detection method provided by an embodiment of the present invention specifically includes:

[0070] Step S101, collect sewing stitch images, perform preprocessing, and use them as input data for the segmentation network. Through image enhancement methods, enrich the data set and improve the generalization ability of the model.

[0071] Specifically, collect sewing images, collect various color stitch images based on the way of flatbed sewing, classify different color sewing stitches and different material sewing substrates, and batch process the sewing stitch images of each category. The specific steps can be divided into:

[0072] Fix the sensor parameters to collect the front light image: Install a high-resolution camera at an appropriate position on the sewing trajectory to collect the front light image information of the sewing stitches; install an adjustable brightness ring light at an appropriate position on the sewing trajectory to provide different brightness for different color sewing stitches; receive the on-site stitch distance detection task instruction through the industrial computer, and control the camera to collect the sewing stitch data under a set of fixed camera parameters and given constant light source conditions, and collect the front light images of the sewing stitches of different types of fabrics;

[0073] Divide the training set and test set for the front light image: Divide all the collected front light images of the sewing stitches into a training set and a test set. Among them, the training set consists of each category of front light image and its corresponding true label image;

[0074] Data annotation: Label the collected original images;

[0075] File type conversion: Unify the image format and adjust the size label: The original pictures and the true label pictures are processed by the algorithm to be uniformly numbered and sized. In the embodiments of the present invention, the cropping size is 256×256, and the image format is uniformly modified to "PNG".

[0076] Before formal training, it should be checked whether there are overly blurred images or repeated images in the training set images due to shooting problems. Manual data screening should be performed before training so that the model can better capture the trace features.

[0077] Step S102, design a pixel-by-pixel training strategy based on cross-entropy loss, introduce the one-hot encoding idea, and optimize label processing and loss calculation.

[0078] Specifically, perform training preprocessing operations on the positive light images and their corresponding true label images in the training set. The training preprocessing operations can include multi-channel image synthesis, image enhancement, and one-hot encoding conversion. The selection of the loss function designed for one-hot encoding is specifically summarized as:

[0079] By reading the corresponding serial numbers of the positive light images and the true label images in the file and combining the custom data channel merging method, the purpose of splicing and fusing the information of the positive light images and their corresponding label images is achieved, and the true label images and the positive light images are spliced into multi-channel images. Even if the number of initially collected training samples is not rich enough, the method of splicing into multi-channel images can make data augmentation more convenient. Specifically, the spliced multi-channel images can be stretched and rotated using the custom data augmentation method to generate a batch of new training data. By creating variants of the images to increase the diversity of the training data, the generalization ability of the model is improved. The image stretching and rotation formulas include:

[0080] W' = W×s x

[0081] H' = H×s y

[0082]

[0083] 6 ×H 6 where θ is the angle of counterclockwise rotation.

[0084] Since using one-hot encoding can more clearly represent the classification labels and helps the model learn the classification boundaries, the formula is as follows:

[0085]

[0086] ​Among them, the label is y, which belongs to one of the C categories. One-hot encoding can convert y into a vector y of length C on(9:o- , obtaining the label converted into the one-hot encoding form. Finally, the loss function is designed based on the particularity of the training samples and their corresponding labels.

[0087] Meanwhile, the present invention proposes another loss function formula "Combined Loss2" for training use. The formulas of the two loss functions are respectively:

[0088] (1) Cross-entropy loss

[0089]

[0090] (2) Combined Loss2:

[0091]

[0092] In the formula, N represents the number of samples, C represents the number of categories, i represents the i-th sample, y i,5 represents the label of the true category c of sample i, p i ,c represents the predicted probability that the model assigns sample i to category c, β is the weight hyperparameter. CrossEntropyLoss is the cross-entropy loss for each pixel classification. DiceLoss is the loss based on the Dice coefficient, and the formula is as follows:

[0093]

[0094] Among them, y i-. / ( is the true label, and y i0.(d is the predicted value.

[0095] For the two different loss functions, they can be selected according to the needs based on the different processing tasks. For the task where the background color and the thread trace color are different, the ordinary cross-entropy loss function can be selected; for the task where the background color and the thread trace color are the same, Combined Loss2 can be selected. By adjusting the weight hyperparameter and adding additional loss items, the segmentation accuracy can be improved.

[0096] Regarding the difference between the background color and the sewing thread trace color, an appropriate loss function can be selected to help the model update parameters better and converge faster.

[0097] Step S103, based on the U-Net network framework, generate a pixel-level thread trace and background segmentation image through the semantic segmentation model.

[0098] In this embodiment, the U-net model framework is used to segment the collected sewing images. Specifically, a loss function suitable for a specific task is selected and designed, and the segmentation of the sewing fabric stitches and the background is achieved through a common semantic segmentation network. Under the U-net framework network provided by the present invention, the general processes of training and testing may include:

[0099] Step S301: Perform data augmentation on the training data to provide richer data for the training set;

[0100] Based on a custom data augmentation method, operations such as stretching and rotating the original training set images are performed to complete data augmentation. By expanding the diversity of the training set, the model can learn a wider data distribution, thereby improving the model's performance on unseen data and reducing overfitting.

[0101] Even if the original training images collected in this embodiment are few, data augmentation can effectively generate additional samples, thereby enhancing the data coverage range, providing more learning opportunities for the model, and providing a solution to the small sample problem of certain specific tasks.

[0102] Step S302: Import the training data into a data loader, and configure the loss function and the optimizer.

[0103] Select a network framework that meets the task, such as the U-net network model proposed in this embodiment, set the corresponding loss function, adopt the Adam optimizer, import the training set and its corresponding labels into the data loader, and adjust the model to the training mode.

[0104] Step S303: Train the selected U-Net network. After sampling and repairing by the encoder and decoder, use the designed loss function to update the parameters.

[0105] Specifically, the encoding part gradually compresses the high-resolution features of the input image into a low-resolution, high-channel representation, extracts features through convolution and pooling operations, and at the same time retains the key spatial information. The decoding part gradually restores the low-resolution, high-channel features compressed by the encoding part to a high-resolution, low-channel output. The purpose is to reconstruct a feature map consistent with the input resolution, and at the same time map the prediction result to the semantic category.

[0106] Step S304: Prepare the test data set, perform the preprocessing process, and apply the trained model to the test data set to generate the segmentation result.

[0107] Specifically, the real label images are not included in the test set, and the test set images are not processed by the custom data augmentation method because it is meaningless to perform data augmentation at this step. Set the model to test mode, including: initializing the result array, converting the image to a tensor, processing block by block, model inference, removing overlapping regions, and finally saving the corresponding test segmentation result map. For specific test steps, please refer to Figure 4 。

[0108] Step S104: Denoise the segmentation result map using binary operation, further optimize the segmented background map, and obtain a clear image of the stitch area.

[0109] Specifically, load the grayscale image of the test result map, set the threshold, and convert the grayscale image to a binary image. Define the structural element and create a morphological matrix of appropriate size. Perform opening operation denoising on the binary image.

[0110] In addition, the principle and result of binary processing and opening operation can be as Figure 2 shown. In Figure 2 , the binary operation result and the corresponding opening operation result based on the sewing stitch task are shown.

[0111] Step S105: Mark the centroid based on the segmentation result and connect the points. Draw a point-line connection diagram through the adjacent point search algorithm to judge the accuracy of the stitch segment.

[0112] Specifically, obtain the opening operation result map as the background map for stitch pitch annotation. The stitch map in the opening operation result map is composed of white pixel blocks and the sewing fabric map is composed of black pixel blocks. Each white area can be regarded as a stitch segment. For each stitch segment, obtain the centroid information and extract the centroid coordinates as (x ; , y ; ). The distance between centroid points is defined as the stitch pitch. Traverse and collect all such centroid points and pack them into a point set list, and judge adjacent points while calculating the stitch pitch size. Use the print method to output the stitch pitch size of each segment according to the traversal order to visually see the distance between each point. When outside the threshold, it means that no qualified points are found. In a specific task, an error reporting program can be set in this step to adjust the sewing equipment. Finally, connect the mass points through the method in the matplotlib library to form a point-line connection diagram.

[0113] Step S106: Calculate the distance between points and output the final stitch pitch detection image to visually present the detection result.

[0114] Specifically, a custom distance calculation method can be used to output the right neighbor distance attribute of each point, i.e., the distance to the right neighboring point. The drawing method is used to output the point-line connection result of the previous step and the segmented background image after the opening operation before, so as to obtain an intuitive stitch length diagram. The stitch length diagram is output as Figure 5 shown.

[0115] In addition, the obtained stitch length diagram can be used to evaluate whether the quality of the sewing stitch is qualified, and relevant performance indicators are used for evaluation, so as to achieve the purpose of sewing stitch length detection based on machine vision.

[0116] The present invention can be used for sewing stitch recognition, denoising, stitch positioning, and stitch length measurement. It uses semantic segmentation to perform recognition and positioning, realizing the automatic detection of textile sewing quality. After adopting the method disclosed by the present invention, the accuracy and consistency of detection can be improved, and the product quality and production efficiency of the textile manufacturing industry can be enhanced. The automatic stitch length detection technology provided by the present invention can reduce human errors, improve production efficiency, reduce costs, and ultimately improve the overall quality of clothing.

Claims

1. A method for detecting the stitch density of sewing thread based on machine vision, characterized in that, It includes the following steps: Step 1: Collect sewing thread trace images. Collect images by classifying them according to the color of the sewing thread trace and the material of the base fabric. After tagging the sewing thread trace images, construct a training set and a test set. Among them, the training set consists of sewing thread trace images of each category and their corresponding ground truth label maps; Step 2: Perform training preprocessing operations on the sewing thread trace images and their corresponding ground truth label maps in the training set. Concatenate the sewing thread trace images and their corresponding ground truth label maps into multi-channel images, and perform data augmentation operations on the multi-channel images; Step 3: Use the training set obtained in Step 2 to train a semantic segmentation network, and use the test set to test the trained semantic segmentation network. During training: Use one-hot encoding to convert the two-dimensional category label array into a three-dimensional one-hot encoding array; Design a loss function based on the principle of cross-entropy loss, calculate the loss by pixel-by-pixel comparison, and update the network parameters through backpropagation, where: Handle the task when the background color is different from the stitch color, and select the cross-entropy loss L C" ; Handle the task when the background color is the same as the stitch color, and select the Combined Loss2 loss L Co$ %i n( dL o++ ,: In the formula, β is the weight hyperparameter, CrossEntropyLoss is the cross-entropy loss for each pixel classification, and DiceLoss is the loss based on the Dice coefficient: where y i-. / ( is the true label, and y i0.(d is the predicted value; By adjusting the weight hyperparameter β, adding additional loss terms to improve the segmentation accuracy; Step 4: Use the trained semantic segmentation network to generate pixel-level stitch and background segmentation images. Then, use the opening and closing operation method provided by the cv2 module in the OpenCV library to denoise the white noise points in the background segmentation image obtained after segmentation to obtain a stitch distance detection background image; Step 5: Based on the stitch distance detection background image denoised by the opening and closing operation method, calculate the stitch distance by constructing a stitch point set class and point objects.

2. The method for detecting the stitch pitch of a sewing thread based on machine vision according to claim 1, wherein In Step 1, when collecting sewing thread trace images, install a high-resolution camera and an adjustable-brightness ring light source at an appropriate position on the sewing trajectory. Among them, the ring light source is used to provide different brightnesses for sewing thread traces of different colors; when collecting sewing thread trace images of the same category, the industrial computer controls the high-resolution camera and the ring light source to collect sewing thread trace data under a set of fixed camera parameters and given unchanging light source conditions.

3. The method for detecting the stitch pitch of a sewing thread based on machine vision according to claim 1, characterized in that, In Step 1, perform unified size cropping and image format modification on the sewing thread trace images and their corresponding ground truth label maps.

4. The method for detecting the stitch pitch of a sewing thread based on machine vision according to claim 1, characterized in that, In Step 2, when performing data augmentation operations, perform rotation and stretching processing on the multi-channel images, which specifically includes the following steps: Use the product method in the itertools library to generate multiple iterable enhanced data map objects. Under a certain rotation angle and stretching degree, use the cv2 module in OpenCV to stretch and rotate a single image.

5. The method for detecting the stitch pitch of sewing thread based on machine vision according to claim 1, wherein, In Step 3, the semantic segmentation network is a U-net network. Based on the U-Net network framework principle, design an asymmetric network with 4 encoding layers and 3 decoding layers by performing upsampling to restore pixel processing and downsampling feature extraction processing on the image, taking into account both speed and accuracy for segmenting sewing thread traces.

6. The method for detecting the stitch density of sewing thread based on machine vision according to claim 1, characterized in that, In step 3, the cross-entropy loss L C" is expressed as: Where N represents the number of samples, C represents the number of categories, i represents the i-th sample, and y i,5 represents the label of the true category c of sample i, and p i ,c represents the predicted probability that the model assigns sample i to category c.

7. The method for detecting the stitch pitch of sewing thread based on machine vision according to claim 1, wherein In Step 3, when testing the semantic segmentation network: Use the sliding window algorithm to gradually scan the image and extract a sub-image patch at each position; Use the overlapping region and cropping technique to ensure that the prediction of each sub-image patch can be smoothly merged into the original image, and send the sub-image patches into the semantic segmentation network one by one for prediction.

8. The method for detecting the stitch pitch of sewing thread based on machine vision according to claim 1, characterized in that The said Step 5 includes the following steps: Construct a point set of floatPointsList, find the left and right neighbor points, and connect adjacent points in pairs through the plot method in matplotlib.pyplot; The distance of the trace points obtained by loop judgment is first output in the custom minimum value algorithm, and is saved to the right adjacent point distance attribute of each point through the distance calculation method, so as to correct the mechanical device according to the stitch pitch size in the subsequent hardware aspect.

9. A sewing stitch stitch length detection system based on machine vision, characterized in that, Including: An image acquisition and preprocessing module, which is used to acquire a sewing thread trace image. Based on the idea of composing a multi-channel image from a front light image and a true label image, the acquired and preliminarily processed image is uniformly cropped in size and the image format is modified; the training image is input into the segmentation network to generate a corresponding semantic segmentation image; An image enhancement module, which is used for image data enhancement. Through data enhancement methods, rotation and stretching processing are performed to increase the richness of the data set. The enhanced data is used as the training basis to train the semantic segmentation network, obtain a richer training set under the condition of fewer initial samples, and enhance the generalization ability; A loss function and one-hot encoding training module, which is used to design a pixel-by-pixel comparison training strategy; introduce the one-hot encoding idea, convert the two-dimensional category label array into a three-dimensional one-hot encoding array, design a loss function based on the cross-entropy loss principle, calculate the loss by pixel-by-pixel comparison, and update the network parameters by backpropagation; A semantic segmentation network model module, which is used to segment the stitch and background image of the acquired image. Based on networks such as U-Net, U-net++, U-net++(L3) or SegNet, and based on the properties of the encoder and decoder, through upsampling to restore pixel processing and downsampling feature extraction processing of the image, a pixel-level segmented stitch effect diagram is obtained; A detection module, which is used to input the test image into the trained segmentation network to obtain a preliminary segmentation result image, and perform denoising operation on the obtained image, so as to better judge the specific position of the sewing thread trace part of the sewing image.