Machining surface deviation detection method and device based on image semantic segmentation
Through image semantic segmentation technology, the machining surface is performed on pixel-level segmentation and geometric parameter fitting, which solves the problem of misjudgment of traditional edge detection algorithms under texture interference, and realizes high accuracy and reliability of machining surface bias detection.
Patent Information
- Application Number
- CN202510791916.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-13
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2045-06-13
AI Technical Summary
In the prior art, when there is texture in the machining surface, traditional edge detection algorithms are prone to misjudgment, resulting in distortion of the hole-off detection result, especially in machining surfaces with high roughness or complex texture.
Using a method based on image semantic segmentation, the target image is segmented at pixel level through the trained semantic segmentation model, the machining surface and background are identified, the high-precision image mask is generated, and the geometric parameters of the machining surface are fitted, such as the center position of the hole and the contour thickness, to determine whether there is a carriage deviation.
The precise separation of the machining surface and the accurate fit of geometric parameters under texture interference are achieved, ensuring the accuracy and reliability of hole-off-car detection, effectively suppressing the interference of texture noise, and improving the purity and accuracy of detection.
Smart Images

Figure CN120298712A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular, to a method and device for detecting the offset turning of machined surfaces based on image semantic segmentation. Background Art
[0002] In the field of mechanical processing, machined surfaces often have various types of textures remaining due to processing techniques (such as turning marks, milling tool marks, etc.). These textures can interfere with edge judgment in hole offset turning detection. Existing mainstream detection schemes mostly calculate the edge degree of pixel points based on local gray values. The core principle is to identify edges by analyzing the gray difference between adjacent pixels. However, this method has limitations: when there are textures on the machined surface, traditional edge detection algorithms rely on the local gray gradient change of pixels, and texture interference (such as grinding marks, periodic stripes) can also cause local gray mutations, resulting in false detections. For example, the periodic patterns generated by turning may form pseudo-edge contours in the gray-scale image, causing the algorithm to misinterpret the texture undulations as features of hole position offset, ultimately leading to distorted detection results.
[0003] This problem is particularly prominent in the detection of machined surfaces with high roughness or complex textures, causing the traditional method to fail in offset turning detection of machined surfaces with textures. Summary of the Invention
[0004] This application provides a method and device for detecting the offset turning of machined surfaces based on image semantic segmentation to solve the problem of the failure of offset turning detection for machined surfaces with textures.
[0005] In a first aspect, this application provides a method for detecting the offset turning of machined surfaces based on image semantic segmentation, the method comprising: Obtain a target image of a machined surface, wherein at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; Perform pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identify the machined surface and the background in the target image to obtain the image mask of the machined surface as output; Fit the geometric parameters of the machined surface in the image mask, wherein the geometric parameters include the center position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; Determine whether the machined surface is offset turned according to the geometric parameters of the machined surface.
[0006] Optionally, performing pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identifying the machined surface and the background in the target image to obtain the image mask of the machined surface as output includes: Input the target image into the trained semantic segmentation model; Extract the semantic features of each pixel in the target image through downsampling of the encoder network, where the semantic features are used to determine whether the pixel belongs to the machined surface; Through upsampling of the decoder network and skip connections, restore the semantic features to the size of the target image to form a pixel-level probability map, where the skip connections are used to compensate for the lost spatial information during downsampling, and the two probability values corresponding to each pixel in the pixel-level probability map respectively indicate the probabilities that the pixel belongs to the machined surface and the background; Convert the pixel-level probability map into a binary mask according to a set probability threshold, where the binary mask is used to indicate whether each pixel belongs to the machined surface or the background; After superimposing the binary mask and the target image, mark the machined surface and the background with different colors to obtain the image mask.
[0007] Optionally, fitting the geometric parameters of the machined surface in the image mask includes: Determine the edge smoothness of the machined surface in the image mask; If the edge smoothness is greater than or equal to the set smoothness threshold, use the Hough circle search method to fit the geometric parameters of the machined surface; If the edge smoothness is less than the set smoothness threshold, use the moment feature extraction method to fit the geometric parameters of the machined surface.
[0008] Optionally, using the moment feature extraction method to fit the geometric parameters of the machined surface includes: Fit the inner contour of the hole in the machined surface through contour detection to obtain the coordinates of each point on the inner contour; Process the coordinates of each point on the inner contour through image moments to obtain the characteristic moments of the inner contour, where the characteristic moments are used to indicate the geometric features and spatial distribution characteristics of the inner contour; Determine the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction in the characteristic moments, where the zero-order moment is used to indicate the area of the inner contour, the first-order moment in the x direction is used to indicate the area distribution of the inner contour in the x direction, and the first-order moment in the y direction is used to indicate the area distribution of the inner contour in the y direction; Determine the center position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction; Draw rays from the center position of the hole to the periphery, and determine the contour thickness according to the two intersection points of the rays and the inner and outer contours of the machined surface.
[0009] Optionally, determining the center position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction includes: Determining the coordinate of the centroid of the inner contour in the x direction according to the quotient of the first-order moment in the x direction and the zero-order moment; Determining the coordinate of the centroid of the inner contour in the y direction according to the quotient of the first-order moment in the y direction and the zero-order moment; Constructing the center position of the hole according to the coordinate of the centroid of the inner contour in the x direction and the coordinate in the y direction.
[0010] Optionally, the contour thickness at each position of the machined surface is not completely the same. Determining whether the machined surface is off-turning according to the geometric parameters of the machined surface includes: If at least one of the following conditions is satisfied, it is determined that the machined surface is off-turning, and the conditions include: The thinnest contour of the machined surface is lower than the thinnest threshold, or; The deviation between the center position of the hole and the standard center position exceeds the deviation threshold, or; The difference between the thickest contour and the thinnest contour of the machined surface exceeds the fixed threshold.
[0011] Optionally, the training process of the semantic segmentation model includes: Inputting a sample image and a corresponding ground truth mask into an initial semantic segmentation model to obtain a predicted mask of the sample image, where the machined surface in the sample image has texture interference; Comparing the predicted mask with the ground truth mask pixel by pixel through a dice loss function to obtain the loss value of the dice loss function, where the loss value of the dice loss function is used to indicate the overlap degree between the predicted mask and the ground truth mask, and the overlap degree has a positive relationship with the integrity of the overall segmentation of the sample image; Generating a boundary distance map by performing a distance transform on the ground truth mask through a boundary loss function, and strengthening the learning weight of edge pixels according to the cross entropy between the predicted mask and the boundary distance map to obtain the loss value of the boundary loss function, where the boundary loss function is used to make the model segmentation accuracy reach the single-pixel level; Performing a weighted sum of the dice loss function and the boundary loss function to form a total loss function; Obtaining a trained semantic segmentation model by minimizing the total loss in the backpropagation process.
[0012] In a second aspect, the present application provides a machined surface off-turning detection device based on image semantic segmentation. The device includes: An acquisition module for acquiring a target image of a machined surface, wherein at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; A segmentation module for performing pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identifying the machined surface and the background in the target image to obtain an image mask of the machined surface as output; A fitting module for fitting geometric parameters of the machined surface in the image mask, wherein the geometric parameters include the center position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; A determination module for determining whether the machined surface is off-turning according to the geometric parameters of the machined surface.
[0013] In a third aspect, the present application provides an electronic device, including: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus.
[0014] In a fourth aspect, the present application further provides a computer storage medium storing computer-executable instructions for executing the method for detecting off-turning of a machined surface based on image semantic segmentation according to any one of the above of the present application.
[0015] The above technical solutions provided by the embodiments of the present application have the following advantages compared with the prior art: The semantic segmentation technology is used to process the image to generate a high-precision image mask, which accurately outlines the contour of the machined surface at the pixel-level resolution, realizing the accurate separation of the machined surface and the background. Through pixel-by-pixel contour extraction, the interference of the surface texture noise of the machined surface is effectively suppressed, ensuring the purity of the contour extraction. The geometric parameters of the machined surface fitted based on the image mask are highly accurate, thereby providing a reliable basis for judging the off-turning state of the machined surface and realizing accurate detection of whether the machined surface is off-turning. Description of the Drawings
[0016] The drawings here are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application and used together with the specification to explain the principles of the present application.
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0018] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplary illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements, unless otherwise stated. The drawings in the figures do not constitute a scale limitation.
[0019] Figure 1 Schematic diagram of a machining surface offset turning detection system based on image semantic segmentation provided by an embodiment of the present application; Figure 2 Flowchart of a machining surface offset turning detection method based on image semantic segmentation provided by an embodiment of the present application; Figure 3 Schematic diagram of a machining surface with texture interference provided by an embodiment of the present application; Figure 4 Schematic diagram of an image mask provided by an embodiment of the present application; Figure 5 Schematic diagram of the working process of a semantic segmentation model; Figure 6 Schematic diagram of rays emitted outward from the hole center provided by an embodiment of the present application; Figure 7 Schematic diagram of the overall process of machining surface offset turning detection based on image semantic segmentation provided by an embodiment of the present application; Figure 8 Schematic diagram of the structure of a machining surface offset turning detection device based on image semantic segmentation provided by an embodiment of the present application; Figure 9 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the scope of protection of the present application.
[0021] The following disclosure provides many different embodiments or examples for implementing different structures of the present application. To simplify the disclosure of the present application, components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit the present application. In addition, the present application may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0022] To solve the problem of the failure of the offset turning detection of the machined surface with texture mentioned in the background art, the embodiment of the present application obtains an accurate image mask by pixel-level segmentation of the image, and then determines whether the machined surface is offset turned according to the geometric parameters of the machined surface in the image mask.
[0023] Optionally, in the embodiment of the present application, the above-mentioned offset turning detection method of the machined surface based on image semantic segmentation can be applied to the Figure 1 hardware environment composed of the terminal 101 and the server 103 as shown. As Figure 1 shown, the server 103 is connected to the terminal 101 through the network. The user inputs the target image to be detected in the terminal 101. The target image can be semantically segmented and the geometric parameters can be fitted locally in the terminal to output the result of whether the machined surface is offset turned, or the target image can be uploaded to the server 103 to output the result of whether the machined surface is offset turned through the server 103. The database 105 can be set on the server or independently of the server to provide data storage services for the server 103. The above network includes but is not limited to: wide area network, metropolitan area network or local area network. The terminal 101 includes but is not limited to PC, mobile phone, tablet computer, etc.
[0024] Next, in combination with the specific implementation manners, a method for detecting the offset turning of the machined surface based on image semantic segmentation provided by the embodiment of the present application will be described in detail. Taking the application to the terminal as an example, as Figure 2 shown, the specific steps are as follows: Step 201: Obtain the target image of the machined surface, where at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; Step 202: Perform pixel-level semantic segmentation on the target image through the trained semantic segmentation model, and identify the machined surface and the background in the target image to obtain the image mask of the output machined surface; Step 203: Fit the geometric parameters of the machined surface in the image mask, where the geometric parameters include the center position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; Step 204: Determine whether the machined surface is offset turned according to the geometric parameters of the machined surface.
[0025] In step 201, during the machining process, the surface formed after machining operations such as cutting, grinding, milling, boring, drilling, etc. on the surface of the machined surface by machine tool equipment is called the machined surface. The surface of the machined surface after being processed by a lathe usually has texture interference, such as metal casting surface, metal wire drawing pattern or milling tool marks, etc. Figure 3It is a schematic diagram of a machined surface with texture interference. It can be seen that the machined surface has texture and at least one perforation. In order to detect whether there is a problem of off-turning on these machined surfaces, first, a shooting tool is needed to shoot the machined surface, and then the captured target image is uploaded to the terminal. Among them, when shooting, an annular light source is used to evenly irradiate the machined surface from multiple angles, which can avoid the generation of shadows due to uneven illumination and affect the subsequent judgment of the hole edge.
[0026] In step 202, the terminal inputs the captured target image into a pre-trained semantic segmentation model. The semantic segmentation model can identify which parts of the image are the machined surface itself, which parts are the holes on the machined surface, and which parts are the background. Specifically, the semantic segmentation model analyzes the target image pixel by pixel and judges the probability that each pixel belongs to the machined surface. For example, for a certain pixel point in the image, after analysis, the model believes that it has a 90% probability of belonging to the edge of the hole, then this pixel will be marked as an edge pixel of the hole. After a series of analyses and processes, the semantic segmentation model finally outputs an image mask. Figure 4 It is a schematic diagram of the image mask. As Figure 4 shown, in the image mask, the area of the hole will be clearly marked, and the accuracy of this contour can reach the pixel level, which can accurately distinguish the real hole edge from the interference caused by the surface texture.
[0027] This application deeply analyzes the image content from a global perspective through a semantic segmentation model. Through the deep understanding ability of the image semantics of the deep learning model, each pixel in the image is finely classified. Specifically, the model will label the category to which each pixel belongs, such as classifying the pixel as a hole, the main body of the machined surface, the background, etc., so as to achieve high-precision region segmentation at the pixel level.
[0028] During the processing, the semantic segmentation model will generate a corresponding image mask, in which different regions of different classes are distinguished by different gray values or colors. This image mask intuitively shows the exact boundary between the machined surface and the background. Even if there are complex textures on the surface of the machined surface, the model can effectively distinguish different regions by learning the association between the texture and the semantics. The finally obtained image mask clearly outlines the contour of the machined surface with pixel-level accuracy, realizing the precise separation of the machined surface and the background. Compared with the traditional edge detection algorithm that only relies on local gray value changes for judgment, this application grasps the overall image content, segments regions at the pixel level, and is not affected by local gray value mutations or texture interferences. Therefore, the accuracy of region recognition has been improved, providing a reliable basis for the subsequent off-turning detection of the machined surface.
[0029] Figure 5Schematic diagram of the workflow of the semantic segmentation model. It can be seen that after the target image is input into the semantic segmentation model, a segmented image mask can be obtained. Among them, the thinnest contour marked in the image mask is added additionally and is not generated by the model.
[0030] In step 203, the terminal further analyzes the generated image mask to obtain key geometric parameters. Through a special algorithm, the edge contour of the hole can be extracted from the image mask, and then the center position of the hole can be calculated based on this contour. At the same time, the contour thickness of the hole will also be calculated, that is, the distance from the outer edge around the machined surface hole to the corresponding inner edge. For example, for an ideal circular hole, the distance from the outer edge to the inner edge should be basically the same; if there is a problem of turning with offset, this distance will be uneven. These geometric parameters will provide an important basis for judging whether the hole has turning with offset in the subsequent process.
[0031] In step 204, the terminal judges whether there is a problem of turning with offset on the machined surface according to the calculated geometric parameters. Specifically, the actually calculated center position of the hole is compared with the designed standard position. If the deviation between the two exceeds the preset allowable range, it means that the hole has a center offset and there may be a problem of turning with offset. In addition, the change of the contour thickness of the hole can also be analyzed. If the thickness difference is too large, it also indicates that the hole may have turning with offset during the machining process. For example, if the design standard requires that the center offset of the hole cannot exceed 0.05 mm, and the actual detection result shows that the center offset reaches 0.08 mm, then it can be determined that the hole on this machined surface has a problem of turning with offset. According to the magnitude of the center hole offset and the thickness difference, the degree of turning with offset can be divided into different levels, such as qualified, slightly turning with offset, and severely turning with offset, etc., so as to accurately evaluate and classify the quality of the machined surface. For example, it is set that the deviation below 0.5 mm is slightly turning with offset, 0.5 - 1 mm is moderately turning with offset, and more than 1 mm is severely turning with offset.
[0032] This application uses semantic segmentation technology to process images and generate a high-precision image mask. This image mask accurately outlines the contour of the machined surface at the pixel level resolution, realizing the precise separation of the machined surface and the background. Through pixel-by-pixel contour extraction, the interference of the surface texture noise of the machined surface is effectively suppressed, ensuring the purity of contour extraction. The geometric parameters of the machined surface fitted based on the image mask are highly accurate, and thus provide a reliable basis for judging the turning with offset state of the machined surface, realizing the accurate detection of whether the machined surface has turning with offset.
[0033] As an optional implementation manner, in step 202, the trained semantic segmentation model performs pixel-level semantic segmentation on the target image, and identifies the machined surface and the background in the target image. The obtained image mask of the machined surface includes the following content: Step S11: Input the target image into the trained semantic segmentation model; Step S12: Extract the semantic features of each pixel in the target image through the downsampling of the encoder network, where the semantic features are used to determine whether the pixel belongs to the machined surface; Step S13: Through the upsampling and skip connections of the decoder network, restore the semantic features to the size of the target image to form a pixel-level probability map. The skip connections are used to compensate for the lost spatial information during the downsampling process. The two probability values corresponding to each pixel in the pixel-level probability map respectively indicate the probabilities of the pixel belonging to the machined surface and the background; Step S14: Convert the pixel-level probability map into a binary mask according to the set probability threshold, where the binary mask is used to indicate whether each pixel belongs to the machined surface or the background; Step S15: After superimposing the binary mask and the target image, mark the machined surface and the background with different colors to obtain an image mask.
[0034] In step S11, in the industrial vision detection process, an industrial camera is used to collect the image of the machined surface as the target image. After preprocessing such as size normalization and gray level adjustment, it is input into the trained semantic segmentation model.
[0035] In step S12, the semantic segmentation model includes an encoder network and a decoder network. The encoder network adopts a multi-layer convolution and pooling structure, and gradually reduces the image resolution and expands the receptive field through downsampling operations. During the convolution process, the shallow network captures basic features such as edges and textures in the image, such as turning patterns and milling marks generated by machining; the deep network focuses on the global semantic features of the machined surface, such as the circular contour of the hole and the overall morphological layout of the machined surface. The model associates each pixel with the semantic information of whether it belongs to the machined surface by learning the differences in shape and spatial distribution between the machined surface and the background.
[0036] During the downsampling process of the encoder, the semantic segmentation model learns the essential differences in shape, spatial distribution, etc. between the machined surface and the background, and avoids misjudging interference factors such as machining textures as the boundaries of the machined surface. This feature extraction method based on semantic understanding enables the model to still stably and accurately identify the machined surface area under interference conditions such as complex textures and lighting changes.
[0037] In step S13, the semantic features output by the encoder are upsampled by the decoder, and the image resolution is gradually restored through the transposed convolution layer. During this process, the skip connection mechanism fuses the shallow detail features (such as texture orientation and local edges) at the corresponding levels in the encoder with the deep semantic features, compensating for the spatial information lost during the downsampling process. Through multi-layer upsampling and feature fusion, the model outputs two probability values for each pixel in the image, representing the likelihood of it belonging to the machined surface and the background, respectively. This process is based on the model's comprehensive understanding of the semantic features of the machined surface and the background, ensuring the accuracy of the probability values. For example, if the pixels in a certain area are recognized as conforming to the circular structure of the hole in the encoder, the decoder will correspondingly increase the probability of it belonging to the machined surface.
[0038] Through the encoder-decoder structure combined with the skip connection mechanism, the semantic segmentation model of the present application realizes multi-level extraction from basic features to advanced semantic features. While retaining the image details, it accurately grasps the overall shape of the machined surface and achieves semantic segmentation with pixel-level accuracy.
[0039] In step S14, based on the pixel-level probability map, the model determines the probability value of each pixel through a preset threshold (such as 0.5). When the probability of a pixel belonging to the machined surface is greater than the threshold, it is marked as 1, indicating that the pixel belongs to the machined surface area; otherwise, it is marked as 0 and classified into the background area. This binarization process uses the principle of probability statistics to convert the fuzzy probability judgment into a clear pixel classification, forming a binary mask containing only 0 and 1. For example, for a pixel with a probability value of 0.6, even if there is texture interference in its area, it will be accurately marked as a machined surface pixel because it is higher than the threshold, thus achieving precise separation of the machined surface and the background.
[0040] In step S15, the binary mask is spatially aligned and superimposed with the original target image, and the two types of pixels are visually annotated through color mapping rules: usually, the machined surface pixels marked as 1 are rendered white, and the background pixels marked as 0 are rendered black. This operation not only intuitively presents the contour and position of the machined surface in the original image but also converts the abstract segmentation result of deep learning into visual data that is convenient for manual recognition and algorithm analysis. For example, quality inspection personnel can quickly locate the defective areas of the machined surface through the color difference, and the subsequent calculation of geometric parameters based on the image mask (such as the center coordinates of the hole and the contour thickness) also improves the accuracy due to the accurate area division, providing a reliable basis for the quality inspection of the machined surface.
[0041] In this application, the target image extracts multi-level semantic features through the encoder network, effectively stripping interference information such as machining textures and accurately capturing core features such as the shape and contour of the machined surface. The decoder restores the abstract features to a pixel-level probability map through upsampling and skip connection operations, and quantitatively represents the possibility that each pixel belongs to the machined surface or the background. On this basis, a preset probability threshold is used to binarize the probability map to generate an accurate binary mask, converting the pixel classification result into a clear 0 or 1 label to achieve pixel-level accurate division of the machined surface and the background. Finally, the segmentation result is presented in an intuitive visual form by overlaying the binary mask and the original image and color annotation to obtain an accurate image mask.
[0042] As an optional implementation manner, in step 203, the geometric parameters of the machined surface in the fitted image mask include the following: Step S21: Determine the edge smoothness of the machined surface in the image mask; Step S22: If the edge smoothness is greater than or equal to the set smoothness threshold, the geometric parameters of the machined surface are fitted by using the Hough circle search method; Step S23: If the edge smoothness is less than the set smoothness threshold, the geometric parameters of the machined surface are fitted by using the moment feature extraction method.
[0043] In step S21, after the terminal obtains the image mask, it first performs edge detection processing on it, and extracts the contour edge of the machined surface through algorithms such as the Canny operator. To quantify the smoothness of the edge, a discrete curvature calculation method is adopted: for each pixel point on the contour, a quadratic curve is constructed by fitting the pixel coordinates in the local neighborhood, and the curvature value of this point is calculated. The curvature reflects the degree of bending of the curve at this point. The larger the curvature value, the more curved the curve and the less flat the edge. The curvature values of all pixel points on the contour are statistically analyzed, and their average value or variance is calculated to be used as a quantization index of the edge smoothness. For example, if the curvature values of the edge pixel points are generally small and the fluctuation range is narrow, it indicates that the edge smoothness is high; on the contrary, if there are a large number of points with large curvature values and the distribution is discrete, it indicates that the edge smoothness is low.
[0044] In step S22, when the edge smoothness reaches or exceeds a preset threshold, it means that the edges of the holes on the machined surface are relatively regular and approximate to a standard circle. At this time, the Hough circle transform algorithm is used for geometric parameter fitting. The specific process of the Hough circle transform algorithm is as follows: The image mask is transformed from the Cartesian coordinate system to the polar coordinate system. For each edge pixel point in the image, all possible center coordinates and radii are calculated and cumulative voting is performed in the parameter space. After traversing all the edge points, the voting numbers are counted in the parameter space. The parameter combinations (center coordinates and radii) with voting numbers higher than a certain threshold are considered to be the circular holes existing in the image. In this way, the geometric parameters such as the center position and radius of the holes on the machined surface can be obtained quickly and accurately, and it has strong robustness to edge noise and some incomplete edges, and is suitable for processing regular holes with relatively smooth edges.
[0045] In step S23, if the edge smoothness is lower than the set threshold, it indicates that there are many distortions, burrs or irregular deformations on the edges of the holes on the machined surface, and it is difficult to fit with a standard circular model. At this time, the terminal adopts the moment feature extraction method: by calculating the zero-order moment, first-order moment and second-order moment of the image, basic information such as the center coordinates of the hole area and the size of the hole is obtained. The moment feature extraction method can effectively process irregular shapes and has good adaptability to the edges of holes with defects or deformations. By analyzing the order moments, complex geometric parameters such as the eccentricity and the ratio of the major axis to the minor axis of the holes can be accurately described, ensuring that the geometric information of the machined surface can still be accurately obtained when the edges are irregular.
[0046] In this application, by selecting an appropriate geometric parameter fitting method according to the edge smoothness, the accurate matching between the algorithm and the actual state of the machined surface is realized. For regular holes with smooth edges, the Hough circle search method can quickly locate the center and radius; for holes with distorted edges, the moment feature extraction method can improve the parameter calculation accuracy through complex shape fitting, avoiding the limitations of a single algorithm under different working conditions and improving the overall accuracy of geometric parameter fitting. This method effectively deals with various situations that may occur during the production process of the machined surface. Whether it is a standard machined surface with good processing quality or a machined surface with processing defects and edge deformations, the reliability of parameter extraction can be ensured through reasonable algorithm selection. This makes the detection system have stronger adaptability to different production conditions and the quality of the machined surface, and reduces the detection error caused by the differences in the machined surface.
[0047] In this application, through the rapid judgment of the edge smoothness, the optimal parameter fitting algorithm can be automatically selected, avoiding the calculation redundancy caused by using complex algorithms for all machined surfaces, reducing unnecessary consumption of computing resources and processing time. While ensuring the detection accuracy, the overall detection efficiency is improved.
[0048] As an alternative implementation, in step S23, the geometric parameters of the machined surface are fitted by using the moment feature extraction method, including the following contents: Step S231: Fit the inner contour of the hole in the machined surface by means of contour detection to obtain the coordinates of each point on the inner contour; Step S232: Process the coordinates of each point on the inner contour by using image moments to obtain the characteristic moments of the inner contour, where the characteristic moments are used to indicate the geometric features and spatial distribution characteristics of the inner contour; Step S233: Determine the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction in the characteristic moments, where the zero-order moment is used to indicate the area of the inner contour, the first-order moment in the x direction is used to indicate the area distribution of the inner contour in the x direction, and the first-order moment in the y direction is used to indicate the area distribution of the inner contour in the y direction; Step S234: Determine the center position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction; Step S235: Draw rays from the center position of the hole to the periphery, and determine the contour thickness according to the two intersection points of the rays and the inner and outer contours of the machined surface.
[0049] In step S231, after obtaining the binary image mask, the terminal uses a contour detection algorithm (such as the findContours function in OpenCV) to extract the boundary of the peripheral area of the machined surface hole. The specific process is to start from a certain starting pixel point of the inner contour, traverse adjacent pixels in a clockwise or counterclockwise direction, and determine the contour path by judging whether the pixel value belongs to the machined surface area (such as the pixel with a value of 1 in the binary image). During the tracking process, record the horizontal and vertical coordinates of each contour pixel point and store them in an ordered sequence form, so as to completely fit the shape of the inner contour of the machined surface. This step provides the basic data for subsequent geometric parameter calculation, and its accuracy directly affects the accuracy of hole center positioning and contour thickness measurement.
[0050] In step S232, based on the contour point coordinates, the terminal uses the image moment theory to calculate the characteristic moments of the inner contour. By performing weighted integral operations on the contour point coordinates, complex shape information can be converted into a set of numerical features. When calculating specifically, for each point on the contour, accumulate and sum according to the moment calculation formulas of different orders (such as zero-order moment, first-order moment, etc.) to obtain the moment values of different orders. These moment values reflect the basic attributes such as the area and centroid of the inner contour.
[0051] In step S233, among the calculated set of characteristic moments, the terminal extracts key moment values for analysis. The zero-order moment m00 is equivalent to the total number of pixels within the area enclosed by the contour, which can intuitively reflect the area size of the inner contour; the first-order moment m10 in the x direction describes the weighted distribution of the contour pixels in the horizontal direction, and its numerical value reflects the centroid offset of the contour in the x-axis direction; the first-order moment m01 in the y direction corresponds to the area distribution characteristic in the vertical direction and is used to measure the pixel aggregation trend of the contour in the y-axis direction. The physical meanings of these moment values are clear, providing core parameters for the subsequent calculation of the hole center position and the contour thickness.
[0052] In step S234, according to the image moment theory, the center position of the hole (i.e., the contour centroid) can be calculated by the ratio of the first-order moment to the zero-order moment. The specific formula is: the x coordinate of the centroid is x = m10 / m00, which represents the centroid offset of the contour in the horizontal direction; the y coordinate of the centroid is y = m01 / m00, reflecting the centroid offset of the contour in the vertical direction. Combining the coordinates of x and y, the center position coordinates of the hole (m10 / m00, m01 / m00) can be obtained. This application eliminates the interference caused by the irregular shape of the contour through moment value operations and can accurately locate the hole center.
[0053] In step S235, the terminal evenly emits rays in all directions from the calculated hole center coordinates (x, y) at a preset angular interval (such as every 1 degree). Each ray generates two intersection points with the inner contour and the outer contour of the machined surface respectively. By calculating the Euclidean distance between these two intersection points, the contour thickness in this direction can be obtained. Figure 6 It is a schematic diagram of emitting rays outward from the hole center. This application converts the abstract contour features into quantifiable thickness parameters through geometric projection and distance calculation, which is applicable to the measurement of holes with various complex shapes.
[0054] This application constructs a complete and rigorous geometric parameter calculation system through multi-step processing of contour detection, image moment calculation, and ray projection. From the precise extraction of the inner contour point coordinates to the mathematical modeling of the characteristic moments, and then to the quantitative calculation of the hole center and the contour thickness, it can effectively meet the measurement requirements of irregularly shaped machined surfaces and improve the accuracy of hole center positioning and contour thickness measurement. In addition, the image moment method has a high anti-interference ability against contour noise and distortion. Even if there are processing defects or uneven edges on the surface of the machined surface, stable geometric features can be extracted through statistical characteristics. At the same time, the ray projection measurement method can flexibly adjust the angular interval to adapt to the thickness detection of holes with different shapes, enabling the algorithm to maintain reliable measurement performance under complex working conditions.
[0055] As an optional implementation, the profile thickness at each position of the machined surface is not exactly the same. In step 204, determining whether the machined surface is offset turning according to the geometric parameters of the machined surface includes: if at least one of the following conditions is met, it is determined that the machined surface is offset turning, and the conditions include: the thinnest profile of the machined surface is lower than the thinnest threshold, or; the deviation of the center position of the hole from the standard center position exceeds the deviation threshold, or; the difference between the thickest profile and the thinnest profile of the machined surface exceeds the fixed threshold.
[0056] In the actual industrial production scenario, due to factors such as processing technology limitations and equipment precision deviations, the profile thickness at each position of the machined surface often varies, showing non-identical characteristics. Based on the geometric parameters of the machined surface obtained from the foregoing steps (including profile thickness distribution, hole center position coordinates, etc.), this application constructs a set of offset turning determination mechanisms, including at least the following content.
[0057] Thinnest profile thickness detection: Sort the profile thicknesses at each position of the machined surface, and extract the minimum value as the thinnest profile thickness. If this value is lower than the pre-set thinnest threshold, it indicates that the local wall thickness of the machined surface has breached the safety or functional boundary, and there is a risk of insufficient strength and structural failure due to excessive thinness. At this time, it can be determined that the machined surface has an offset turning defect.
[0058] Hole center position deviation analysis: Compare the calculated actual position coordinates of the hole center with the standard center position coordinates in the design drawing, and calculate the Euclidean distance between the two in the x and y directions as the deviation value. When this deviation exceeds the pre-set deviation threshold, it means that the machining position of the hole deviates from the design requirements, which may affect the assembly accuracy of the machined surface and other components, and then it is determined that there is an offset turning problem with the machined surface.
[0059] Profile thickness difference evaluation: Calculate the difference between the thickest profile and the thinnest profile of the machined surface. This value reflects the unevenness of the wall thickness of the machined surface. If this difference exceeds the fixed threshold, it indicates that there is an obvious wall thickness unevenness phenomenon during the machining process of the machined surface, which also meets the determination conditions of the offset turning defect.
[0060] As long as any one of the above three conditions is met, it can be quickly and accurately determined that there is an offset turning problem with this machined surface.
[0061] This application constructs multi-dimensional and multi-level determination conditions, comprehensively covering the abnormal geometric parameter situations that may be caused by offset turning defects. Whether it is local wall thickness being too thin, hole center offset, or overall wall thickness unevenness, it can be quickly identified through quantitative comparison, improving the accuracy and comprehensiveness of defect detection compared to a single determination standard, and effectively avoiding missed detections and misjudgments.
[0062] As an optional implementation, the training process of the semantic segmentation model includes: Step S31: Input the sample image and the corresponding ground truth mask into the initial semantic segmentation model to obtain the predicted mask of the sample image, where the machined surface in the sample image has texture interference. Step S32: Compare the predicted mask with the ground truth mask pixel by pixel through the Dice loss function to obtain the loss value of the Dice loss function. The loss value of the Dice loss function is used to indicate the overlap degree between the predicted mask and the ground truth mask, and the overlap degree has a positive relationship with the integrity of the overall segmentation of the sample image. Step S33: Generate a boundary distance map by performing a distance transform on the ground truth mask through the boundary loss function, and strengthen the learning weights of the edge pixels according to the cross-entropy between the predicted mask and the boundary distance map to obtain the loss value of the boundary loss function. The boundary loss function is used to make the segmentation accuracy of the model reach the single-pixel level. Step S34: Perform weighted summation on the Dice loss function and the boundary loss function to form the total loss function. Step S35: Obtain the trained semantic segmentation model by minimizing the total loss during the backpropagation process.
[0063] In step S31, during the model training stage, first construct a dataset containing a large number of machined surface images. These sample images simulate the common texture interferences in the actual industrial scenarios, such as the turning lines generated by machining, the concave-convex surfaces after forging, etc. Input the sample image and its corresponding ground truth mask into the initial semantic segmentation model (such as architectures like U-Net, DeepLab, etc.). The semantic segmentation model is based on the convolutional neural network structure. Through multi-layer convolution, pooling, and activation operations, it extracts features from the sample image, gradually learns features such as the edges, shapes, and texture distributions of the machined surface from the pixel-level data, and outputs a predicted mask with the same size as the input image. The predicted mask marks the classification result of each pixel belonging to the machined surface or the background in the form of probability values or binary values.
[0064] In step S32, the Dice loss function, as a function for measuring the similarity of sets, evaluates the segmentation effect by calculating the pixel overlap degree between the predicted mask and the ground truth mask. During specific calculations, the predicted mask and the ground truth mask are regarded as two pixel sets, and the loss value of the Dice loss function is calculated. The loss value of the Dice loss function is used to indicate the overlap degree between the predicted mask and the ground truth mask. Among them, the higher the overlap degree, the lower the loss value; the lower the overlap degree, the higher the loss value.
[0065] The Dice loss function is sensitive to the overall integrity of the predicted mask. If the model misses the machined surface area or misclassifies the background, it will lead to an increase in the Dice loss value. By minimizing the Dice loss function, the model will continuously adjust its parameters during training, striving to improve the overlap between the predicted mask and the ground truth mask, thereby enhancing the overall segmentation integrity.
[0066] In step S33, to address the problem that traditional loss functions pay insufficient attention to edge details, this application introduces the Boundary Loss function to enhance the model's learning ability for the edges of machined surfaces. First, perform a distance transformation operation on the ground truth mask to calculate the Euclidean distance from each pixel to the nearest boundary of the machined surface, generating a boundary distance map. In this map, the pixel values closer to the edge of the machined surface are larger, and the pixel values far from the edge approach 0. Subsequently, combine the predicted mask with the boundary distance map and calculate the deviation between the prediction result and the ground truth boundary through the cross-entropy loss function. Since the boundary distance map assigns higher weights to edge pixels, the model will pay more attention to the prediction errors in the edge region during backpropagation, forcing it to learn the precise details of the machined surface contour, thereby achieving single-pixel-level segmentation accuracy and effectively overcoming the edge blur problem caused by texture interference.
[0067] In step S34, to balance the global segmentation integrity and edge detail accuracy, linearly combine the Dice loss function and the boundary loss function according to a preset weight to construct a total loss function. Among them, the value of the weight is adjusted according to the characteristics of the dataset and the task requirements (for example, the weight of the boundary loss function can be appropriately increased in scenarios with complex textures) to ensure that the model can accurately cover the entire area of the machined surface and precisely capture edge details during the learning process.
[0068] In step S35, the terminal uses optimization algorithms such as stochastic gradient descent to continuously backpropagate the value of the total loss function to each layer of the model during training, calculate the gradient of each network parameter, and update the parameters according to the gradient direction, gradually reducing the total loss between the predicted mask and the ground truth mask. After multiple rounds of iterative training, the model gradually learns the ability to accurately distinguish the machined surface from the background under texture interference and finally outputs a trained semantic segmentation model that meets the accuracy requirements.
[0069] Optionally, TensorRT (Tensor Runtime, tensor inference optimizer) can also be used to quantize the above-trained semantic segmentation model to improve the efficiency of semantic segmentation, and the GPU (Graphics Processing Unit) can be used to accelerate inference during the quantization process.
[0070] In this application, the Dice loss function is used to evaluate the similarity between the model prediction result and the true annotation, and to completely segment the image region as a whole; the boundary loss function strengthens the learning weight of edge pixels through distance transformation, making the segmentation of the machined surface contour by the model sharper and avoiding the common edge blurring or sawtooth phenomena in traditional methods. By combining the dual constraints of the Dice loss function and the boundary loss function, the model can not only ensure the complete coverage of the machined surface region, but also accurately depict the edge details, improving the pixel-level segmentation accuracy compared with a single loss function and effectively solving the problem of missegmentation caused by texture interference.
[0071] This application provides a schematic diagram of the overall process for detecting the offset turning of a machined surface based on image semantic segmentation, as Figure 7 shown, including the following steps.
[0072] Step 701: Sample data collection.
[0073] Collect the machined surface image and annotate the true mask.
[0074] Step 702: Train the semantic segmentation model.
[0075] 1) Feature extraction: The initial semantic segmentation model learns the machined surface contour and texture features through an encoder-decoder structure.
[0076] 2) Dice loss function calculation: Compare the predicted mask and the true mask pixel by pixel, and quantify the overlap degree to optimize the overall segmentation integrity.
[0077] 3) Boundary loss function strengthening: Enhance the edge pixel weights through distance transformation to improve the edge segmentation accuracy.
[0078] 4) Total loss optimization: Combine the two loss functions with weights and adjust the parameters through backpropagation.
[0079] Step 703: Obtain the target image of the machined surface.
[0080] Step 704: The trained semantic segmentation model outputs the image mask corresponding to the target image.
[0081] The process of outputting the image mask is as follows: Extract the semantic features of each pixel; form a pixel-level probability map; convert the probability map into a binary mask; and superimpose the binary mask and the target image to obtain the image mask.
[0082] Step 705: Determine whether the edge smoothness of the machined surface is greater than the set smoothness threshold, and then decide which algorithm to use to fit the geometric parameters of the machined surface. If the edge smoothness is high, go to step 706; if the edge smoothness is low, go to step 707.
[0083] Step 706: Fit the geometric parameters of the machined surface using the Hough circle search method.
[0084] Step 707: Fit the geometric parameters of the machined surface using the moment feature extraction method.
[0085] Step 708: Determine whether the machined surface is offset turning based on the geometric parameters.
[0086] Based on the same technical concept, the present application provides a machined surface offset turning detection device based on image semantic segmentation, as Figure 8 shown, the device includes: An acquisition module 801, configured to acquire a target image of the machined surface, wherein at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; A segmentation module 802, configured to perform pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identify the machined surface and the background in the target image, to obtain an output image mask of the machined surface; A fitting module 803, configured to fit the geometric parameters of the machined surface in the image mask, wherein the geometric parameters include the center position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; A determination module 804, configured to determine whether the machined surface is offset turning according to the geometric parameters of the machined surface.
[0087] Optionally, the segmentation module 802 is configured to: Input the target image into the trained semantic segmentation model; Extract the semantic features of each pixel in the target image through the downsampling of the encoder network, wherein the semantic features are used to determine whether the pixel belongs to the machined surface; Through the upsampling and skip connection of the decoder network, restore the semantic features to the size of the target image to form a pixel-level probability map, wherein the skip connection is used to compensate for the lost spatial information during the downsampling process, and the two probability values corresponding to each pixel in the pixel-level probability map respectively indicate the probability that the pixel belongs to the machined surface and the background; Convert the pixel-level probability map into a binary mask according to a set probability threshold, wherein the binary mask is used to indicate whether each pixel belongs to the machined surface or belongs to the background; After superimposing the binary mask and the target image, mark the machined surface and the background with different colors to obtain an image mask.
[0088] Optionally, the fitting module 803 is configured to: Determine the edge smoothness of the machined surface in the image mask; If the edge smoothness is greater than or equal to the set smoothness threshold, fit the geometric parameters of the machined surface using the Hough circle search method; If the edge smoothness is less than the set smoothness threshold, the moment feature extraction method is used to fit the geometric parameters of the machined surface.
[0089] Optionally, the fitting module 803 is specifically configured to: Fit the inner contour of the hole in the machined surface by contour detection to obtain the coordinates of each point on the inner contour; Process the coordinates of each point on the inner contour through image moments to obtain the characteristic moments of the inner contour, where the characteristic moments are used to indicate the geometric features and spatial distribution characteristics of the inner contour; Determine the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction in the characteristic moments, where the zero-order moment is used to indicate the area of the inner contour, the first-order moment in the x direction is used to indicate the area distribution of the inner contour in the x direction, and the first-order moment in the y direction is used to indicate the area distribution of the inner contour in the y direction; Determine the center position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction; Draw rays from the center position of the hole to the periphery, and determine the contour thickness according to the two intersection points of the rays and the inner and outer contours of the machined surface.
[0090] Optionally, the fitting module 803 is specifically configured to: Determine the coordinate of the centroid of the inner contour in the x direction according to the quotient of the first-order moment in the x direction and the zero-order moment; Determine the coordinate of the centroid of the inner contour in the y direction according to the quotient of the first-order moment in the y direction and the zero-order moment; Construct the center position of the hole according to the coordinate of the centroid of the inner contour in the x direction and the coordinate in the y direction.
[0091] Optionally, the contour thickness at each position of the machined surface is not completely the same, and the determination module 804 is used to: If at least one of the following conditions is met, it is determined that the machined surface is offset turning, and the conditions include: The thinnest contour of the machined surface is lower than the thinnest threshold, or; The deviation of the center position of the hole from the standard center position exceeds the deviation threshold, or; The difference between the thickest contour and the thinnest contour of the machined surface exceeds the fixed threshold.
[0092] Optionally, the device is further configured to: Input the sample image and the corresponding true mask into the initial semantic segmentation model to obtain the predicted mask of the sample image, where the machined surface in the sample image has texture interference; The predicted mask and the ground truth mask are compared pixel by pixel through the Dice loss function to obtain the loss value of the Dice loss function. The loss value of the Dice loss function is used to indicate the overlap degree between the predicted mask and the ground truth mask, and the overlap degree has a positive relationship with the integrity of the overall segmentation of the sample image. The ground truth mask is subjected to distance transformation through the boundary loss function to generate a boundary distance map, and the learning weight of the edge pixels is enhanced according to the cross-entropy between the predicted mask and the boundary distance map to obtain the loss value of the boundary loss function. The boundary loss function is used to make the model segmentation accuracy reach the single-pixel level. The Dice loss function and the boundary loss function are weighted and summed to form a total loss function. By minimizing the total loss during the backpropagation process, a trained semantic segmentation model is obtained.
[0093] As Figure 9 shown, an embodiment of the present application provides an electronic device, including a processor 901, a communication interface 902, a memory 903, and a communication bus 904. Among them, the processor 901, the communication interface 902, and the memory 903 complete communication with each other through the communication bus 904.
[0094] The memory 903 is used to store computer programs.
[0095] In an embodiment of the present application, when the processor 901 is used to execute the program stored on the memory 903, it implements the machining surface turning detection method based on image semantic segmentation provided by any one of the foregoing method embodiments.
[0096] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of the machining surface turning detection method based on image semantic segmentation provided by any one of the foregoing method embodiments.
[0097] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0098] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the relevant technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiments.
[0099] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" as used herein may also include the plural forms. The terms "comprising", "including", "containing", and "having" are inclusive and thus specify the presence of the stated features, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or their combinations. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the particular order described or illustrated, unless the order of performance is explicitly stated. It should also be understood that additional or alternative steps may be used.
[0100] The above are only the specific embodiments of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but will be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A machining surface offset turning detection method based on image semantic segmentation, characterized in that The method includes: Obtaining a target image of a machined surface, where at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; Performing pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identifying the machined surface and the background in the target image to obtain an image mask of the machined surface as output; Fitting geometric parameters of the machined surface in the image mask, where the geometric parameters include the center position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; Determining whether the machined surface is off-turning according to the geometric parameters of the machined surface.
2. The method according to claim 1, wherein Performing pixel-level semantic segmentation on the target image through a trained semantic segmentation model, and identifying the machined surface and the background in the target image to obtain an image mask of the machined surface as output includes: Inputting the target image into a trained semantic segmentation model; Extracting semantic features of each pixel in the target image through downsampling of the encoder network, where the semantic features are used to determine whether the pixel belongs to the machined surface; Restoring the semantic features to the size of the target image through upsampling and skip connections of the decoder network to form a pixel-level probability map, where the skip connections are used to compensate for the lost spatial information during downsampling, and the two probability values corresponding to each pixel in the pixel-level probability map respectively indicate the probabilities that the pixel belongs to the machined surface and the background; Converting the pixel-level probability map into a binary mask according to a set probability threshold, where the binary mask is used to indicate whether each pixel belongs to the machined surface or the background; After superimposing the binary mask and the target image, marking the machined surface and the background with different colors to obtain the image mask.
3. The method according to claim 1, wherein Fitting geometric parameters of the machined surface in the image mask includes: Determining the edge smoothness of the machined surface in the image mask; If the edge smoothness is greater than or equal to a set smoothness threshold, fitting the geometric parameters of the machined surface by using the Hough circle search method; If the edge smoothness is less than the set smoothness threshold, fitting the geometric parameters of the machined surface by using the moment feature extraction method.
4. The method according to claim 3, characterized in that, Fitting geometric parameters of the machined surface by using the moment feature extraction method includes: Fitting the inner contour of the hole in the machined surface by using the contour detection method to obtain the coordinates of each point on the inner contour; Processing the coordinates of each point on the inner contour through image moments to obtain the characteristic moments of the inner contour, where the characteristic moments are used to indicate the geometric features and spatial distribution characteristics of the inner contour; Determining the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction in the characteristic moments, where the zero-order moment is used to indicate the area of the inner contour, the first-order moment in the x direction is used to indicate the area distribution of the inner contour in the x direction, and the first-order moment in the y direction is used to indicate the area distribution of the inner contour in the y direction; Determining the center position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction; Emit rays from the central position of the hole to the periphery, and determine the contour thickness based on the two intersection points of the rays with the inner and outer contours of the machined surface.
5. The method according to claim 4, characterized in that Determining the central position of the hole according to the zero-order moment, the first-order moment in the x direction, and the first-order moment in the y direction includes: Determine the x-coordinate of the centroid of the inner contour in the x direction according to the quotient of the first-order moment in the x direction and the zero-order moment; Determine the y-coordinate of the centroid of the inner contour in the y direction according to the quotient of the first-order moment in the y direction and the zero-order moment; Construct the central position of the hole according to the x-coordinate and the y-coordinate of the centroid of the inner contour in the x and y directions.
6. The method according to claim 1, wherein The contour thickness at each position of the machined surface is not exactly the same. Determining whether the machined surface is off-turning according to the geometric parameters of the machined surface includes: If at least one of the following conditions is satisfied, it is determined that the machined surface is off-turning. The conditions include: The thinnest contour of the machined surface is lower than the thinnest threshold, or; The deviation between the central position of the hole and the standard central position exceeds the deviation threshold, or; The difference between the thickest contour and the thinnest contour of the machined surface exceeds the fixed threshold.
7. The method according to claim 1, wherein The training process of the semantic segmentation model includes: Input the sample image and the corresponding ground truth mask into the initial semantic segmentation model to obtain the predicted mask of the sample image, where the machined surface in the sample image has texture interference; Compare the predicted mask with the ground truth mask pixel by pixel through the dice loss function to obtain the loss value of the dice loss function, where the loss value of the dice loss function is used to indicate the overlap degree between the predicted mask and the ground truth mask, and the overlap degree has a positive relationship with the integrity of the overall segmentation of the sample image; Generate a boundary distance map by performing a distance transformation on the ground truth mask through the boundary loss function, and strengthen the learning weight of the edge pixels according to the cross-entropy of the predicted mask and the boundary distance map to obtain the loss value of the boundary loss function, where the boundary loss function is used to make the model segmentation accuracy reach the single-pixel level; Perform weighted summation on the dice loss function and the boundary loss function to form a total loss function; Obtain the trained semantic segmentation model by minimizing the total loss during the backpropagation process.
8. A machining surface turning deviation detection device based on image semantic segmentation, characterized in that, The device includes: An acquisition module for acquiring a target image of a machined surface, where at least one perforation is provided on the machined surface and the surface of the machined surface has texture interference; A segmentation module for performing pixel-level semantic segmentation on the target image through the trained semantic segmentation model, and identifying the machined surface and the background in the target image to obtain the image mask of the output machined surface; A fitting module for fitting the geometric parameters of the machined surface in the image mask, where the geometric parameters include the central position of the hole and the contour thickness, and the contour thickness is the thickness of the machined surface around the hole; A determination module for determining whether the machined surface is off-turning according to the geometric parameters of the machined surface.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete mutual communication through the communication bus; The memory is used for storing computer programs; The processor is used to implement the method described in any one of claims 1-7 when executing the programs stored on the memory.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer programs, and when the computer programs are executed by the processor, the method described in any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Remote sensing image semantic change detection method and system fused with triple attention mechanism
CN116863468A