Method and device for detecting deviation of machined surface based on image semantic segmentation

By generating high-precision image masks through image semantic segmentation technology, the error problem of vehicle deviation detection under the interference of machined surface texture is solved, and the precise separation of machined surfaces and accurate vehicle deviation judgment are achieved.

CN120298712BActive Publication Date: 2025-09-09SHENZHEN XINRUN FULIAN DIGITAL TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510791916.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-13
Publication Date
2025-09-09
Estimated Expiration
2045-06-13

AI Technical Summary

Technical Problem

When there is texture on the machined surface, the traditional edge detection algorithm is prone to distortion in hole position deviation detection due to texture interference, especially in machined surfaces with high roughness or complex texture.

Method used

A method based on image semantic segmentation is adopted to perform pixel-level segmentation on the target image through the trained semantic segmentation model, generate a high-precision image mask, identify the machined surface and background, and fit the geometric parameters to judge the deviation of the vehicle.

Benefits of technology

The precise separation of machined surfaces and accurate fitting of geometric parameters under texture interference are achieved, ensuring the reliability and accuracy of vehicle deviation detection, reducing the interference of texture noise and improving detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120298712B_ABST
    Figure CN120298712B_ABST
Patent Text Reader

Abstract

The present application relates to a method and device for detecting deviation of a machined surface based on image semantic segmentation, the method comprising: obtaining a target image of a machined surface, wherein the machined surface is provided with at least one perforation and the surface of the machined surface has texture interference; performing pixel-level semantic segmentation on the target image using a trained semantic segmentation model, and identifying the machined surface and background in the target image to obtain an output image mask of the machined surface; fitting 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, wherein the contour thickness is the thickness of the machined surface around the hole; and determining whether the machined surface is deviated based on the geometric parameters of the machined surface. The present application can accurately detect whether a machined surface is deviated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a method and device for detecting deviation of a machined surface based on image semantic segmentation. Background Art

[0002] In the field of mechanical processing, machined surfaces often retain various textures (such as turning marks, milling tool marks, etc.) due to the processing technology. These textures will interfere with the edge judgment in the detection of hole deviation. The existing mainstream detection schemes are mostly based on the calculation of the edge degree of pixel points based on local grayscale values. The core principle is to identify edges by analyzing the grayscale differences between adjacent pixels. However, this method has limitations: when there are textures on the machined surface, the traditional edge detection algorithm relies on the local grayscale gradient changes of the pixels, and texture interference (such as grinding marks, periodic stripes) will also produce local grayscale mutations, leading to false detection. For example, the periodic lines produced by turning may form pseudo-edge contours in the grayscale image, causing the algorithm to mistakenly regard the texture fluctuations as characteristics of hole offset, ultimately resulting in distorted detection results.

[0003] This problem is particularly prominent in the inspection of machined surfaces with high roughness or complex textures, causing traditional methods to fail in the detection of off-center machining on textured machined surfaces. Summary of the Invention

[0004] The present application provides a method and device for detecting deviation of a machined surface based on image semantic segmentation, so as to solve the problem of failure in detecting deviation of a machined surface with texture.

[0005] In a first aspect, the present application provides a method for detecting deviation of a machined surface based on image semantic segmentation, the method comprising:

[0006] Acquiring a target image of a machined surface, wherein the machined surface is provided with at least one through-hole and the surface of the machined surface has texture interference;

[0007] Performing pixel-level semantic segmentation on the target image using a trained semantic segmentation model, and identifying the machined surface and background in the target image to obtain an output image mask of the machined surface;

[0008] Fitting geometric parameters of the machined surface in the image mask, wherein the geometric parameters include a center position and a profile thickness of a hole, wherein the profile thickness is a thickness of the machined surface around the hole;

[0009] Whether the machined surface is off-center is determined according to geometric parameters of the machined surface.

[0010] Optionally, performing pixel-level semantic segmentation on the target image using a trained semantic segmentation model, and identifying the machined surface and background in the target image, to obtain an output image mask of the machined surface includes:

[0011] Inputting the target image into a trained semantic segmentation model;

[0012] Extracting semantic features of each pixel in the target image through downsampling of an encoder network, wherein the semantic features are used to determine whether the pixel belongs to the machined surface;

[0013] Restoring the semantic features to the size of the target image through upsampling and skip connections in the decoder network to form a pixel-level probability map, wherein the skip connections are used to compensate for spatial information lost 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;

[0014] Converting 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 the background;

[0015] After superimposing the binary mask and the target image, the machined surface and the background are marked with different colors to obtain the image mask.

[0016] Optionally, fitting the geometric parameters of the machined surface in the image mask comprises:

[0017] determining edge smoothness of the machined surface in the image mask;

[0018] If the edge smoothness is greater than or equal to a set smoothness threshold, the geometric parameters of the machined surface are fitted using a Hough circle search method;

[0019] If the edge smoothness is less than the set smoothness threshold, a moment feature extraction method is used to fit the geometric parameters of the machined surface.

[0020] Optionally, fitting the geometric parameters of the machined surface by using a moment feature extraction method includes:

[0021] Fitting the inner contour of the hole in the machined surface by contour detection to obtain the coordinates of each point on the inner contour;

[0022] Processing the coordinates of each point on the inner contour by image moments to obtain characteristic moments of the inner contour, wherein the characteristic moments are used to indicate geometric features and spatial distribution characteristics of the inner contour;

[0023] Determine a zero-order moment, a first-order moment in the x-direction, and a first-order moment in the y-direction among the characteristic moments, wherein 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;

[0024] determining a center position of the hole based on the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction;

[0025] A ray is drawn from the center of the hole toward the periphery, and the contour thickness is determined according to two intersection points of the ray with the inner and outer contours of the machined surface.

[0026] 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:

[0027] Determining the coordinates of the center of mass of the inner contour in the x-direction according to the quotient of the first-order moment and the zero-order moment in the x-direction;

[0028] Determining the coordinates of the center of mass of the inner contour in the y direction according to the quotient of the first-order moment and the zero-order moment in the y direction;

[0029] The center position of the hole is constructed based on the coordinates of the center of mass of the inner contour in the x direction and the coordinates in the y direction.

[0030] Optionally, the thickness of the profile at each position of the machined surface is not completely the same, and determining whether the machined surface is deflected according to the geometric parameters of the machined surface includes:

[0031] If at least one of the following conditions is met, it is determined that the machined surface is off-center, the conditions including:

[0032] the thinnest profile of the machined surface is below a thinnest threshold, or;

[0033] the deviation of the center position of the hole from the standard center position exceeds a deviation threshold, or;

[0034] A difference between the thickest profile and the thinnest profile of the machined surface exceeds a fixed threshold.

[0035] Optionally, the training process of the semantic segmentation model includes:

[0036] Inputting a sample image and a corresponding true mask into an initial semantic segmentation model to obtain a predicted mask of the sample image, wherein the machined surface in the sample image has texture interference;

[0037] Comparing the predicted mask with the true mask pixel by pixel using a dice loss function to obtain a loss value of the dice loss function, wherein the loss value of the dice loss function is used to indicate the degree of overlap between the predicted mask and the true mask, and the degree of overlap is positively correlated with the completeness of the overall segmentation of the sample image;

[0038] Performing a distance transformation on the true mask using a boundary loss function to generate a boundary distance map, and strengthening the learning weights of edge pixels based on the cross entropy between the predicted mask and the boundary distance map to obtain a loss value of the boundary loss function, wherein the boundary loss function is used to achieve a single-pixel level of model segmentation accuracy;

[0039] Performing a weighted summation of the dice loss function and the boundary loss function to form a total loss function;

[0040] By minimizing the total loss during the back-propagation process, the trained semantic segmentation model is obtained.

[0041] In a second aspect, the present application provides a device for detecting deviation of a machined surface based on image semantic segmentation, the device comprising:

[0042] an acquisition module, configured to acquire a target image of a machined surface, wherein the machined surface is provided with at least one through-hole and has texture interference on its surface;

[0043] a segmentation module, configured to perform pixel-level semantic segmentation on the target image using a trained semantic segmentation model, identify the machined surface and the background in the target image, and output an image mask of the machined surface;

[0044] a fitting module, configured to fit geometric parameters of the machined surface in the image mask, wherein the geometric parameters include a center position and a profile thickness of a hole, wherein the profile thickness is a thickness of the machined surface around the hole;

[0045] The determination module is used to determine whether the machined surface is off-center according to the geometric parameters of the machined surface.

[0046] In a third aspect, the present application provides an electronic device comprising: 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.

[0047] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the machined surface deviation detection method based on image semantic segmentation as described in any one of the above items of the present application.

[0048] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: semantic segmentation technology is used to process images to generate a high-precision image mask, which accurately outlines the contour of the machined surface with pixel-level resolution, thereby achieving accurate separation of the machined surface from the background. By extracting the contour pixel by pixel, 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 based on the image mask fitting are highly accurate, which provides a reliable basis for judging the deviation state of the machined surface and accurately detects whether the machined surface is deviated. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0051] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0052] Figure 1 Schematic diagram of a machined surface deviation detection system based on image semantic segmentation provided in an embodiment of the present application;

[0053] Figure 2 A flow chart of a method for detecting deviation of a machined surface based on image semantic segmentation provided in an embodiment of the present application;

[0054] Figure 3 Provided for the embodiment of the present application is a schematic diagram of a machined surface with texture interference;

[0055] Figure 4 A schematic diagram of an image mask provided in an embodiment of the present application;

[0056] Figure 5 Schematic diagram of the workflow of the semantic segmentation model;

[0057] Figure 6 A schematic diagram of rays emitting outward from the center of a hole provided in an embodiment of the present application;

[0058] Figure 7A schematic diagram of the overall process of machined surface deviation detection based on image semantic segmentation provided in an embodiment of the present application;

[0059] Figure 8 A schematic diagram of the structure of a machined surface deviation detection device based on image semantic segmentation provided in an embodiment of the present application;

[0060] Figure 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0062] The disclosure below provides many different embodiments or examples for implementing different structures of the present application. In order to simplify the disclosure of the present application, the components and settings of specific examples are described below. Of course, these are merely examples and are not intended to limit the present application. In addition, the present application may repeat reference numbers and / or letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or settings discussed.

[0063] In order to solve the problem of failure in detecting deviation of textured machined surfaces mentioned in the background technology, 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 deviated based on the geometric parameters of the machined surface in the image mask.

[0064] Optionally, in the embodiment of the present application, the above-mentioned machined surface deviation detection method based on image semantic segmentation can be applied to Figure 1 In the hardware environment composed of the terminal 101 and the server 103 shown in FIG. Figure 1 As shown, the server 103 is connected to the terminal 101 via a network. The user inputs a target image to be inspected into the terminal 101. The target image can be semantically segmented and geometrically fitted locally on the terminal, and a result indicating whether the machined surface is deviated from the machine can be output. Alternatively, the target image can be uploaded to the server 103, and the result indicating whether the machined surface is deviated from the machine can be output via the server 103. A database 105 can be provided on the server or independently of the server to provide data storage services for the server 103. The aforementioned network includes, but is not limited to, a wide area network, a metropolitan area network, or a local area network. The terminal 101 includes, but is not limited to, a PC, a mobile phone, a tablet computer, etc.

[0065] The following will be combined with specific implementation methods to provide a detailed description of a machined surface deviation detection method based on image semantic segmentation provided by the embodiment of the present application, taking the application in the terminal as an example. Figure 2 The specific steps are as follows:

[0066] Step 201: Acquire a target image of a machined surface, wherein the machined surface is provided with at least one through-hole and has texture interference on the surface of the machined surface;

[0067] Step 202: Perform pixel-level semantic segmentation on the target image using the trained semantic segmentation model, identify the machined surface and background in the target image, and obtain an output image mask of the machined surface;

[0068] Step 203: fitting geometric parameters of the machined surface in the image mask, wherein the geometric parameters include the center position and profile thickness of the hole, wherein the profile thickness is the thickness of the machined surface around the hole;

[0069] Step 204: Determine whether the machined surface is off-center based on the geometric parameters of the machined surface.

[0070] In step 201, during the machining process, the surface formed by cutting, grinding, milling, boring, drilling, etc. is processed by machine tools. The surface of the machined surface processed by lathe usually has texture interference, such as metal casting surface, metal brushing pattern or milling knife marks. Figure 3 The following figure shows a machined surface with texture interference. It can be seen that the machined surface has texture and at least one perforation. To detect whether these machined surfaces have a skew problem, a camera is first used to capture the surface, and then the captured target image is uploaded to the terminal. During the capture process, a ring light source is used to evenly illuminate the machined surface from multiple angles. This prevents shadows caused by uneven lighting, which can affect the subsequent determination of the hole edge.

[0071] In step 202, the terminal inputs the captured target image into the trained semantic segmentation model. The semantic segmentation model can identify which parts of the image are the machined surface itself, which parts are holes on the machined surface, and which parts are the background. Specifically, the semantic segmentation model analyzes the target image pixel by pixel to determine the probability that each pixel belongs to the machined surface. For example, for a certain pixel in the image, after analysis, the model believes that it has a 90% probability of belonging to the edge of a hole, then the pixel will be marked as the edge pixel of the hole. After a series of analysis and processing, the semantic segmentation model finally outputs an image mask. Figure 4 is a schematic diagram of image mask. Figure 4As shown in the figure, the hole area is clearly marked in the image mask, and the accuracy of this outline can reach the pixel level, which can accurately distinguish the real hole edge from the interference caused by surface texture.

[0072] This application uses a semantic segmentation model to analyze image content from a global perspective. By leveraging the deep learning model's ability to deeply understand image semantics, it can finely classify each pixel in the image. Specifically, the model labels each pixel's category, such as holes, machined surfaces, and background, achieving high-precision region segmentation at the pixel level.

[0073] During the processing, the semantic segmentation model will generate a corresponding image mask, in which different categories of areas are distinguished by different grayscale values ​​or colors. This image mask intuitively shows the precise boundary between the machined surface and the background. Even if there are complex textures on the machined surface, the model can effectively distinguish different areas by learning the relationship between texture and semantics. The final image mask clearly outlines the contour of the machined surface with pixel-level accuracy, achieving accurate separation of the machined surface and the background. Compared with traditional edge detection algorithms that only rely on local grayscale changes for judgment, this application grasps the image content as a whole and segments regions at the pixel level. It is not affected by local grayscale mutations or texture interference. Therefore, the accuracy of regional recognition has been improved, providing a reliable foundation for subsequent machined surface deviation detection.

[0074] Figure 5 This is a diagram of the workflow of the semantic segmentation model. As can be seen, after the target image is input into the semantic segmentation model, a segmented image mask is obtained. The thinnest outline marked in the image mask is added additionally and is not generated by the model.

[0075] In step 203, the terminal further analyzes the generated image mask to obtain key geometric parameters. Through a specialized algorithm, the edge contour of the hole can be extracted from the image mask, and then the center position of the hole is calculated based on this contour. At the same time, the contour thickness of the hole is also calculated, that is, the distance from the outer edge around the machined surface 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 consistent; if there is a problem of eccentricity, this distance will be uneven. These geometric parameters will provide an important basis for subsequent judgment of whether the hole is eccentric.

[0076] In step 204, the terminal judges whether there is a problem of eccentricity in the machined surface based on the geometric parameters obtained by calculation. Specifically, the center position of the hole obtained by actual calculation is compared with the design standard position. If the deviation between the two exceeds the preset allowable range, it is explained that there is a center offset in the hole, and there may be a eccentricity problem. In addition, the profile thickness variation of the hole can also be analyzed. If the thickness difference is too large, it also shows that there may be eccentricity in the hole during processing. For example, 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 has reached 0.08 mm, so it can be determined that there is a eccentricity problem in the hole of this machined surface. According to the size of the center hole offset and the thickness difference, the degree of eccentricity can also be divided into different grades, such as qualified, slight eccentricity and severe eccentricity, so that the quality of the machined surface is accurately evaluated and classified. For example, setting the deviation below 0.5mm is slight eccentricity, 0.5-1mm is moderate eccentricity, and exceeding 1mm is severe eccentricity.

[0077] 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 with pixel-level resolution, achieving precise separation of the machined surface from the background. By extracting the contour pixel by pixel, the interference of surface texture noise on the machined surface is effectively suppressed, ensuring the purity of the contour extraction. The geometric parameters of the machined surface based on image mask fitting are highly accurate, providing a reliable basis for judging the deviation state of the machined surface, and accurately detecting whether the machined surface is deviated.

[0078] As an optional implementation, in step 202, pixel-level semantic segmentation is performed on the target image using a trained semantic segmentation model, and the machined surface and background in the target image are identified. The output image mask of the machined surface includes the following content:

[0079] Step S11: input the target image into the trained semantic segmentation model;

[0080] Step S12: extracting semantic features of each pixel in the target image through downsampling of the encoder network, wherein the semantic features are used to determine whether the pixel belongs to the machined surface;

[0081] Step S13: The semantic features are restored to the size of the target image through upsampling and skip connections in the decoder network to form a pixel-level probability map. The skip connections are used to compensate for the spatial information lost during the downsampling process. The two probability values ​​corresponding to each pixel in the pixel-level probability map indicate the probability that the pixel belongs to the machined surface and the background, respectively.

[0082] Step S14: converting 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 the background;

[0083] Step S15: After superimposing the binary mask and the target image, the machined surface and the background are marked with different colors to obtain an image mask.

[0084] In step S11, in the industrial visual inspection process, an industrial camera is used to capture an image of the machined surface as a target image, which is input into the trained semantic segmentation model after preprocessing such as size normalization and grayscale adjustment.

[0085] In step S12, the semantic segmentation model includes an encoder network and a decoder network. The encoder network uses a multi-layer convolution and pooling structure to gradually reduce the image resolution and expand 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 lines and milling marks produced by machining; the deep network focuses on the global semantic features of the machined surface, such as the circular outline of the hole and the overall morphological layout of the machined surface. By learning the differences in shape and spatial distribution between the machined surface and the background, the model associates each pixel with semantic information about whether it belongs to the machined surface.

[0086] During the encoder's downsampling process, the semantic segmentation model learns the essential differences between the machined surface and the background in terms of shape and spatial distribution, preventing interference factors such as machined texture from being misidentified as machined surface boundaries. This semantically informed feature extraction method enables the model to stably and accurately identify machined surface areas despite interference from complex textures, varying lighting, and other factors.

[0087] In step S13, the semantic features output by the encoder are upsampled by the decoder, and the image resolution is gradually restored through the deconvolution layer. During this process, the skip connection mechanism fuses the shallow detail features (such as texture orientation and local edges) of the corresponding level 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, indicating the probability 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 identified as conforming to the circular structure of the hole in the encoder, the decoder will correspondingly increase the probability that they belong to the machined surface.

[0088] This application uses an encoder-decoder structure combined with a jump connection mechanism to achieve multi-level extraction from basic features to advanced semantic features in the semantic segmentation model. While retaining image details, it accurately grasps the overall morphology of the machined surface and realizes semantic segmentation with pixel-level accuracy.

[0089] In step S14, based on the pixel-level probability map, the model determines the probability value of each pixel using a preset threshold (e.g., 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, indicating that the pixel belongs to the background area. This binarization process utilizes the principles of probabilistic statistics to transform the ambiguous 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 the area where it is located, 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 from the background.

[0090] In step S15, the binary mask is spatially aligned and overlaid with the original target image, and the two types of pixels are visually annotated using color mapping rules: typically, machined surface pixels marked as 1 are rendered white, and background pixels marked as 0 are rendered black. This operation not only intuitively displays the contours and positions of the machined surface in the original image but also transforms the abstract segmentation results of deep learning into visual data that facilitates both human identification and algorithmic analysis. For example, quality inspectors can quickly locate defective areas on the machined surface by color differences. Subsequent calculations of geometric parameters based on the image mask (such as hole center coordinates and contour thickness) also improve accuracy due to accurate area demarcation, providing a reliable basis for machined surface quality inspection.

[0091] In this application, the target image is extracted with multi-level semantic features through the encoder network, effectively stripping away 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 jump connection operations, and characterizes the possibility of each pixel belonging to the machined surface or the background in a quantitative form. On this basis, the probability map is binarized using a preset probability threshold to generate an accurate binary mask, and the pixel classification results are converted into clear 0 or 1 labels to achieve pixel-level precise division of the machined surface and the background. Finally, the segmentation result is presented in an intuitive visual form by superimposing the binary mask with the original image and color-labeling, and an accurate image mask is obtained.

[0092] As an optional implementation, in step 203, fitting the geometric parameters of the machined surface in the image mask includes the following:

[0093] Step S21: determining the edge smoothness of the machined surface in the image mask;

[0094] 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 using the Hough circle search method;

[0095] Step S23: If the edge smoothness is less than the set smoothness threshold, the geometric parameters of the machined surface are fitted using a moment feature extraction method.

[0096] In step S21, after obtaining the image mask, the terminal first performs edge detection processing on it, and extracts the contour edge of the machined surface through algorithms such as the Canny operator. In order to quantify the smoothness of the edge, a discrete curvature calculation method is used: 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 the point is calculated. The curvature reflects the degree of curvature of the curve at this point. The larger the curvature value, the more curved the curve and the more uneven the edge. The curvature values ​​of all pixel points on the contour are statistically analyzed, and their average value or variance is calculated as a quantitative indicator of edge smoothness. For example, if the curvature values ​​of the edge pixels are generally small and the fluctuation range is narrow, it means that the edge smoothness is high; conversely, if there are a large number of points with large curvature values ​​and the distribution is discrete, it means that the edge smoothness is low.

[0097] In step S22, when the edge smoothness reaches or exceeds a pre-set threshold, it means that the edge of the hole on the machined surface is relatively regular and approximates a standard circle. At this point, the Hough circle transform algorithm is used to fit the geometric parameters. The specific process of the Hough circle transform algorithm is as follows: the image mask is converted from a Cartesian coordinate system to a polar coordinate system. For each edge pixel in the image, all possible center coordinates and radii are calculated and cumulatively voted in the parameter space. After traversing all edge points, the number of votes is counted in the parameter space. Parameter combinations (center coordinates and radii) with a vote count above a certain threshold are considered to be circular holes in the image. In this way, the geometric parameters of the hole on the machined surface, such as the center position and radius, can be quickly and accurately obtained. At the same time, it is highly robust to edge noise and partially incomplete edges, making it suitable for processing regular holes with relatively smooth edges.

[0098] In step S23, if the edge smoothness is lower than the set threshold, it indicates that the hole edge of the machined surface has a lot of distortion, burrs or irregular deformation, making it difficult to fit using a standard circular model. At this time, the terminal uses 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 hole size is obtained. The moment feature extraction method can effectively handle irregular shapes and has good adaptability to hole edges with defects or deformations. By analyzing the order moment, complex geometric parameters such as the eccentricity of the hole and the ratio of the major and minor axes can be accurately described, ensuring that the geometric information of the machined surface can still be accurately obtained even in the case of irregular edges.

[0099] In this application, an adaptive geometric parameter fitting method is selected according to the edge smoothness, so as to achieve accurate matching between the algorithm and the actual state of the machined surface. 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 responds to various situations that may arise in the production process of machined surfaces. Whether it is a standard machined surface with good processing quality or a machined surface with processing defects and edge deformation, the reliability of parameter extraction can be guaranteed through reasonable algorithm selection. This makes the detection system more adaptable to different production conditions and machined surface quality, and reduces the detection error caused by differences in machined surfaces.

[0100] This application can automatically select the optimal parameter fitting algorithm by quickly determining edge smoothness, avoiding computational redundancy caused by applying complex algorithms to all machined surfaces, reducing unnecessary computing resource consumption and processing time. While ensuring detection accuracy, it also improves overall detection efficiency.

[0101] As an optional implementation, in step S23, fitting the geometric parameters of the machined surface using a moment feature extraction method includes the following:

[0102] Step S231: fitting the inner contour of the hole in the machined surface by contour detection to obtain the coordinates of each point on the inner contour;

[0103] Step S232: Processing the coordinates of each point on the inner contour by image moments to obtain characteristic moments of the inner contour, wherein the characteristic moments are used to indicate the geometric features and spatial distribution characteristics of the inner contour;

[0104] Step S233: determining the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction among the characteristic moments, wherein 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;

[0105] Step S234: determining the center position of the hole based on the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction;

[0106] Step S235: Draw a ray from the center of the hole toward the periphery, and determine the contour thickness based on two intersection points of the ray with the inner and outer contours of the machined surface.

[0107] 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 boundaries of the surrounding area of ​​the machined surface. The specific process involves starting from a starting pixel of the inner contour and traversing adjacent pixels in a clockwise or counterclockwise direction. The contour path is determined by determining whether the pixel value belongs to the machined surface area (for example, pixels with a value of 1 in the binary image). During the tracing process, the horizontal and vertical coordinates of each contour pixel are recorded and stored in an ordered sequence, thus completely fitting the inner contour shape of the machined surface. This step provides basic data for subsequent geometric parameter calculations, and its accuracy directly affects the accuracy of hole center positioning and contour thickness measurement.

[0108] In step S232, based on the contour point coordinates, the terminal uses image moment theory to calculate the characteristic moments of the inner contour. By performing a weighted integral operation on the contour point coordinates, the complex shape information is converted into a set of numerical features. Specifically, for each point on the contour, moment calculation formulas of different orders (such as zero-order moment and first-order moment) are cumulatively summed to obtain moment values ​​of different orders. These moment values ​​reflect basic properties of the inner contour, such as area and center of gravity.

[0109] In step S233, the terminal extracts key moment values ​​from the calculated characteristic moment set for analysis. The zero-order moment m00 is equivalent to the total number of pixels within the area enclosed by the contour and provides a direct reflection of the area of ​​the inner contour. The first-order moment m10 in the x-direction describes the weighted distribution of contour pixels in the horizontal direction, and its value reflects the offset of the contour's center of gravity along the x-axis. The first-order moment m01 in the y-direction corresponds to the vertical area distribution and is used to measure the contour's pixel clustering tendency along the y-axis. These moment values ​​have clear physical meanings and provide core parameters for the subsequent calculation of the hole center position and contour thickness.

[0110] In step S234, based on image moment theory, the center position of the hole (i.e., the contour centroid) can be calculated using the ratio of the first-order moment to the zero-order moment. The specific formula is: the coordinate of the centroid in the x-direction is x = m10 / m00, which represents the horizontal offset of the contour's center of gravity; the coordinate of the centroid in the y-direction is y = m01 / m00, reflecting the vertical offset of the contour's center of gravity. Combining the x and y coordinates yields the coordinates of the hole's center position (m10 / m00, m01 / m00). This application eliminates interference caused by contour irregularities through moment calculations, enabling precise location of the hole's center.

[0111] In step S235, the terminal uses the calculated hole center coordinates (x, y) as the starting point and evenly emits rays in all directions at preset angular intervals (e.g., every 1 degree). Each ray intersects the inner and outer contours of the machined surface at two points, respectively. By calculating the Euclidean distance between these two intersection points, the contour thickness in that direction is obtained. Figure 6 This is a schematic diagram of rays radiating outward from the center of a hole. This application transforms abstract contour features into quantifiable thickness parameters through geometric projection and distance calculation, making it suitable for measuring holes of various complex shapes.

[0112] This application has built 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 coordinates of the inner contour points to the mathematical modeling of the characteristic moments, and then to the quantitative calculation of the hole center and contour thickness, it can effectively meet the measurement needs 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 degree of anti-interference ability against noise and distortion of the contour. Even if there are processing defects or uneven edges on 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 angle interval to adapt to the thickness detection of holes of different shapes, so that the algorithm can maintain reliable measurement performance under complex working conditions.

[0113] As an optional embodiment, the contour thickness at each position of the machined surface is not exactly the same. In step 204, determining whether the machined surface is deviated based on the geometric parameters of the machined surface includes: if at least one of the following conditions is met, the machined surface is determined to be deviated, 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 a fixed threshold.

[0114] In actual industrial production scenarios, due to factors such as processing technology limitations and equipment precision deviations, the profile thickness at each location on the machined surface often varies, presenting non-identical characteristics. Based on the geometric parameters of the machined surface obtained in the previous steps (including profile thickness distribution, hole center position coordinates, etc.), this application has constructed a deviation detection mechanism that includes at least the following content.

[0115] Thinnest Profile Thickness Detection: The profile thicknesses at various locations on the machined surface are sorted and the minimum value is extracted as the thinnest profile thickness. If this value falls below a pre-set thinnest threshold, it indicates that the local wall thickness of the machined surface has exceeded safety or functional limits, posing a risk of insufficient strength or structural failure due to excessive thinness. In this case, the machined surface can be considered to have a skew defect.

[0116] Hole Center Position Deviation Analysis: The calculated actual hole center coordinates are compared with the standard center coordinates in the design drawing, and the Euclidean distance between the two in the x and y directions is calculated as the deviation value. If 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 thus determine that the machined surface has a deviation problem.

[0117] Profile Thickness Difference Assessment: This value is the difference between the thickest and thinnest contours of a machined surface. This value reflects the unevenness of the machined surface wall thickness. If this difference exceeds a fixed threshold, it indicates that the machined surface has significant wall thickness unevenness during machining, which also meets the criteria for a skew turning defect.

[0118] As long as any one of the above three conditions is met, it can be quickly and accurately determined that the machined surface has a skew turning problem.

[0119] This application comprehensively covers geometric parameter anomalies that may be caused by skew defects by constructing multi-dimensional and multi-level judgment criteria. Whether it is localized wall thickness being too thin, hole center offset, or overall uneven wall thickness, these can all be quickly identified through quantitative comparison. Compared to a single judgment criterion, this improves the accuracy and comprehensiveness of defect detection, effectively avoiding missed detections and misjudgments.

[0120] As an optional implementation, the training process of the semantic segmentation model includes:

[0121] Step S31: inputting the sample image and the corresponding true mask into the initial semantic segmentation model to obtain a predicted mask of the sample image, wherein the machined surface in the sample image has texture interference;

[0122] Step S32: Compare the predicted mask with the true mask pixel by pixel using a dice loss function to obtain a loss value of the dice loss function, wherein the loss value of the dice loss function is used to indicate the degree of overlap between the predicted mask and the true mask, and the degree of overlap is positively correlated with the integrity of the overall segmentation of the sample image;

[0123] Step S33: Performing distance transformation on the true mask using a boundary loss function to generate a boundary distance map, and strengthening the learning weights of edge pixels based on 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 achieve a single-pixel level of segmentation accuracy.

[0124] Step S34: performing weighted summation on the dice loss function and the boundary loss function to form a total loss function;

[0125] Step S35: Obtain the trained semantic segmentation model by minimizing the total loss during the back-propagation process.

[0126] In step S31, during the model training phase, a dataset containing a large number of machined surface images is first constructed. These sample images simulate common texture interferences in actual industrial scenarios, such as turning marks produced by machining and uneven surfaces after forging. The sample images and their corresponding true masks are input into an initial semantic segmentation model (e.g., architectures such as U-Net and DeepLab). The semantic segmentation model is based on a convolutional neural network structure. It extracts features from sample images through multi-layer convolution, pooling, and activation operations, gradually learning features such as the edge, shape, and texture distribution of the machined surface from pixel-level data, and outputting a prediction mask consistent with the size of the input image. The prediction mask marks the classification result of each pixel as belonging to the machined surface or background in the form of a probability value or binary value.

[0127] In step S32, the Dice loss function (DICE Loss), a function that measures set similarity, evaluates the segmentation performance by calculating the degree of pixel overlap between the predicted mask and the ground-truth mask. Specifically, the predicted and ground-truth masks are treated as two sets of pixels, and the Dice loss function's loss value is calculated. The Dice loss function's loss value indicates the degree of overlap between the predicted and ground-truth masks. A higher degree of overlap results in a lower loss value, while a lower degree of overlap results in a higher loss value.

[0128] The Dice loss function is sensitive to the overall integrity of the predicted mask. If the model misses machined surface areas or incorrectly segments the background, the Dice loss value will increase. By minimizing the Dice loss function, the model continuously adjusts parameters during training to improve the overlap between the predicted mask and the ground-truth mask, thereby improving the integrity of the overall segmentation.

[0129] In step S33, in order to solve the problem that traditional loss functions do not pay enough attention to edge details, this application introduces a boundary loss function (Boundary Loss) to enhance the model's learning ability for the edges of machined surfaces. First, a distance transformation operation is performed on the true mask to calculate the Euclidean distance from each pixel to the nearest machined surface boundary to generate a boundary distance map. In this map, the closer the pixel value is to the edge of the machined surface, the larger the pixel value is, and the pixel value far away from the edge is close to 0. Subsequently, the predicted mask is combined with the boundary distance map, and the deviation between the predicted result and the true boundary is calculated using the cross entropy loss function. Since the boundary distance map gives higher weights to edge pixels, the model will pay more attention to the prediction error of the edge area during the back propagation process, forcing the learning of accurate machined surface contour details, thereby achieving single-pixel level segmentation accuracy and effectively overcoming the edge blurring problem caused by texture interference.

[0130] In step S34, to balance global segmentation completeness and edge detail accuracy, the dice loss function and the boundary loss function are linearly combined according to preset weights to construct a total loss function. The weights are adjusted based on the characteristics of the dataset and the task requirements (for example, the boundary loss function weight can be appropriately increased in scenes with complex textures). This ensures that the model accurately covers the entire machined surface area while accurately capturing edge details during the learning process.

[0131] In step S35, the terminal uses an optimization algorithm, such as stochastic gradient descent, to continuously propagate the value of the total loss function back to each layer of the model during training. The terminal calculates the gradient of each network parameter and updates the parameter based on the gradient direction, gradually reducing the total loss between the predicted mask and the true mask. After multiple rounds of iterative training, the model gradually learns to accurately distinguish between the machined surface and the background despite texture interference, ultimately outputting a trained semantic segmentation model that meets the required accuracy.

[0132] Optionally, you can also use TensorRT (Tensor Runtime, tensor inference optimizer) to quantize the trained semantic segmentation model to improve the efficiency of semantic segmentation. During the quantization process, you can use the GPU (Graphics Processing Unit, graphics processing unit) to accelerate inference.

[0133] In this application, the dice loss function is used to evaluate the similarity between the model's predictions and the true annotations, thereby completely segmenting the image region as a whole. The boundary loss function strengthens the learning weights of edge pixels through distance transformation, making the model's segmentation of the machined surface contour sharper and avoiding the edge blur or jaggedness common in traditional methods. By combining the dual constraints of the dice loss function and the boundary loss function, the model can not only ensure complete coverage of the machined surface area, but also accurately depict edge details. Compared with a single loss function, it improves pixel-level segmentation accuracy and effectively solves the problem of missegmentation caused by texture interference.

[0134] This application provides a schematic diagram of the overall process of machined surface deviation detection based on image semantic segmentation, such as Figure 7 As shown, the following steps are included.

[0135] Step 701: Sample data collection.

[0136] Collect machined surface images and annotate ground-truth masks.

[0137] Step 702: Train a semantic segmentation model.

[0138] 1) Feature extraction: The initial semantic segmentation model learns the contour and texture features of the machined surface through an encoder-decoder structure.

[0139] 2) Dice loss function calculation: Compare the predicted mask with the true mask pixel by pixel, quantify the overlap to optimize the overall segmentation completeness.

[0140] 3) Boundary loss function enhancement: Enhance edge pixel weights through distance transformation to improve edge segmentation accuracy.

[0141] 4) Total loss optimization: weighted combination of the two loss functions and backpropagation to adjust the parameters.

[0142] Step 703: Acquire a target image of the machined surface.

[0143] Step 704: The trained semantic segmentation model outputs an image mask corresponding to the target image.

[0144] The process of outputting the image mask is as follows: extracting the semantic features of each pixel; forming a pixel-level probability map; converting the probability map into a binary mask; and superimposing the binary mask and the target image to obtain the image mask.

[0145] Step 705: Determine whether the edge smoothness of the machined surface is greater than a 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, proceed to step 706; if the edge smoothness is low, proceed to step 707.

[0146] Step 706: Use the Hough circle search method to fit the geometric parameters of the machined surface.

[0147] Step 707: Use moment feature extraction to fit the geometric parameters of the machined surface.

[0148] Step 708: Determine whether the machined surface is off-center based on the geometric parameters.

[0149] Based on the same technical concept, this application provides a machined surface deviation detection device based on image semantic segmentation, such as Figure 8 As shown, the device includes:

[0150] An acquisition module 801 is configured to acquire a target image of a machined surface, wherein the machined surface has at least one through-hole and has texture interference on its surface;

[0151] The segmentation module 802 is used to perform pixel-level semantic segmentation on the target image using the trained semantic segmentation model, identify the machined surface and the background in the target image, and obtain an output image mask of the machined surface;

[0152] a fitting module 803 for fitting geometric parameters of the machined surface in the image mask, wherein the geometric parameters include the center position and profile thickness of the hole, wherein the profile thickness is the thickness of the machined surface around the hole;

[0153] The determination module 804 is used to determine whether the machined surface is off-center according to the geometric parameters of the machined surface.

[0154] Optionally, the segmentation module 802 is configured to:

[0155] Input the target image into the trained semantic segmentation model;

[0156] Extracting semantic features of each pixel in the target image through downsampling of the encoder network, wherein the semantic features are used to determine whether the pixel belongs to the machined surface;

[0157] The semantic features are restored to the size of the target image through upsampling and skip connections in the decoder network, forming a pixel-level probability map. The skip connection is used to compensate for the spatial information lost during the downsampling process. The two probability values ​​corresponding to each pixel in the pixel-level probability map indicate the probability that the pixel belongs to the machined surface and the background respectively.

[0158] Converting 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 the background;

[0159] After superimposing the binary mask and the target image, the machined surface and background are marked with different colors to obtain the image mask.

[0160] Optionally, the fitting module 803 is used to:

[0161] determining edge smoothness of machined surfaces in an image mask;

[0162] If the edge smoothness is greater than or equal to the set smoothness threshold, the geometric parameters of the machined surface are fitted using the Hough circle search method;

[0163] If the edge smoothness is less than the set smoothness threshold, the geometric parameters of the machined surface are fitted using the moment feature extraction method.

[0164] Optionally, the fitting module 803 is specifically configured to:

[0165] Fitting the inner contour of the hole in the machined surface by contour detection to obtain the coordinates of each point on the inner contour;

[0166] The coordinates of each point on the inner contour are processed by the image moment to obtain the characteristic moment of the inner contour, wherein the characteristic moment is used to indicate the geometric characteristics and spatial distribution characteristics of the inner contour;

[0167] Determine the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction among the characteristic moments, wherein 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;

[0168] Determine the center position of the hole based on the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction;

[0169] A ray is drawn from the center of the hole to the periphery, and the contour thickness is determined based on the two intersection points of the ray with the inner and outer contours of the machined surface.

[0170] Optionally, the fitting module 803 is specifically configured to:

[0171] Determine the coordinates of the center of mass of the inner contour in the x-direction according to the quotient of the first-order moment and the zero-order moment in the x-direction;

[0172] Determine the coordinates of the center of mass of the inner contour in the y direction according to the quotient of the first-order moment and the zero-order moment in the y direction;

[0173] The center position of the hole is constructed based on the coordinates of the center of mass of the inner contour in the x direction and the coordinates in the y direction.

[0174] Optionally, the thickness of the profile at each position of the machined surface is not completely the same, and the determination module 804 is used to:

[0175] If at least one of the following conditions is met, it is determined that the machined surface is off-center, the conditions include:

[0176] The thinnest profile of the machined surface is below the thinnest threshold, or;

[0177] The deviation of the hole center position from the standard center position exceeds the deviation threshold, or;

[0178] The difference between the thickest and thinnest contours of the machined surface exceeds a fixed threshold.

[0179] Optionally, the device is further used to:

[0180] Inputting the sample image and the corresponding true mask into the initial semantic segmentation model to obtain the predicted mask of the sample image, wherein the machined surface in the sample image has texture interference;

[0181] The predicted mask is compared with the true 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 between the predicted mask and the true mask. The overlap is positively correlated with the integrity of the overall segmentation of the sample image.

[0182] The boundary loss function is used to perform distance transformation on the true mask to generate a boundary distance map, and the learning weights of edge pixels are strengthened 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.

[0183] Perform weighted summation of the dice loss function and the boundary loss function to form the total loss function;

[0184] By minimizing the total loss during the back-propagation process, the trained semantic segmentation model is obtained.

[0185] like Figure 9 As 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, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.

[0186] The memory 903 is used to store computer programs.

[0187] In one embodiment of the present application, the processor 901 is configured to implement the machined surface deviation detection method based on image semantic segmentation provided by any one of the aforementioned method embodiments when executing the program stored in the memory 903 .

[0188] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the machined surface deviation detection method based on image semantic segmentation as provided in any of the aforementioned method embodiments are implemented.

[0189] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.

[0190] Through the description of the above embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion 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, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods of each embodiment or certain portions of the embodiments.

[0191] 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 "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "comprise", "include", "contain" and "have" are inclusive and therefore specify the presence of stated features, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the specific order described or illustrated, unless the order of execution is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0192] The foregoing is merely a list of specific embodiments of the present application, intended to enable those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the broadest scope consistent with the principles and novel features of the present application.

Claims

1. A method for detecting deviation of machined surfaces based on image semantic segmentation, characterized in that: The method comprises: Acquiring a target image of a machined surface, wherein the machined surface is provided with at least one through-hole and the surface of the machined surface has texture interference; Performing pixel-level semantic segmentation on the target image using a trained semantic segmentation model, and identifying the machined surface and background in the target image to obtain an output image mask of the machined surface; Fitting geometric parameters of the machined surface in the image mask, wherein the geometric parameters include a center position and a profile thickness of a hole, wherein the profile thickness is a thickness of the machined surface around the hole; determining whether the machined surface is off-center according to geometric parameters of the machined surface; The target image is subjected to pixel-level semantic segmentation by a trained semantic segmentation model, and the machined surface and background in the target image are identified to obtain an output image mask of the machined surface. The 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 an encoder network, wherein 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 in the decoder network to form a pixel-level probability map, wherein the skip connections are used to compensate for spatial information lost 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; Converting 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 the background; After superimposing the binary mask and the target image, the machined surface and the background are marked with different colors to obtain the image mask; Wherein, fitting the geometric parameters of the machined surface in the image mask includes: determining edge smoothness of the machined surface in the image mask; If the edge smoothness is greater than or equal to a set smoothness threshold, the geometric parameters of the machined surface are fitted using a Hough circle search method; If the edge smoothness is less than the set smoothness threshold, a moment feature extraction method is used to fit the geometric parameters of the machined surface.

2. The method according to claim 1, characterized in that The geometric parameters of the machined surface are fitted by moment feature extraction method, including: Fitting the inner contour of the hole in the machined surface by contour detection to obtain the coordinates of each point on the inner contour; Processing the coordinates of each point on the inner contour by image moments to obtain characteristic moments of the inner contour, wherein the characteristic moments are used to indicate geometric features and spatial distribution characteristics of the inner contour; Determine a zero-order moment, a first-order moment in the x-direction, and a first-order moment in the y-direction among the characteristic moments, wherein 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 a center position of the hole based on the zero-order moment, the first-order moment in the x-direction, and the first-order moment in the y-direction; A ray is drawn from the center of the hole toward the periphery, and the contour thickness is determined according to two intersection points of the ray with the inner and outer contours of the machined surface.

3. The method according to claim 2, characterized in that 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 coordinates of the center of mass of the inner contour in the x-direction according to the quotient of the first-order moment and the zero-order moment in the x-direction; Determining the coordinates of the center of mass of the inner contour in the y direction according to the quotient of the first-order moment and the zero-order moment in the y direction; The center position of the hole is constructed based on the coordinates of the center of mass of the inner contour in the x direction and the coordinates in the y direction.

4. The method according to claim 1, wherein The thickness of the profile at each position of the machined surface is not completely the same, and determining whether the machined surface is deflected 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 off-center, the conditions including: the thinnest profile of the machined surface is below a thinnest threshold, or; the deviation of the center position of the hole from the standard center position exceeds a deviation threshold, or; A difference between the thickest profile and the thinnest profile of the machined surface exceeds a fixed threshold.

5. The method according to claim 1, wherein The training process of the semantic segmentation model includes: Inputting a sample image and a corresponding true mask into an initial semantic segmentation model to obtain a predicted mask of the sample image, wherein the machined surface in the sample image has texture interference; Comparing the predicted mask with the true mask pixel by pixel using a dice loss function to obtain a loss value of the dice loss function, wherein the loss value of the dice loss function is used to indicate the degree of overlap between the predicted mask and the true mask, and the degree of overlap is positively correlated with the completeness of the overall segmentation of the sample image; Performing a distance transformation on the true mask using a boundary loss function to generate a boundary distance map, and strengthening the learning weights of edge pixels based on the cross entropy between the predicted mask and the boundary distance map to obtain a loss value of the boundary loss function, wherein the boundary loss function is used to achieve a single-pixel level of model segmentation accuracy; Performing a weighted summation of the dice loss function and the boundary loss function to form a total loss function; By minimizing the total loss during the back-propagation process, a trained semantic segmentation model is obtained.

6. A device for detecting deviation of machined surfaces based on image semantic segmentation, characterized in that: The device comprises: an acquisition module, configured to acquire a target image of a machined surface, wherein the machined surface is provided with at least one through-hole and has texture interference on its surface; a segmentation module, configured to perform pixel-level semantic segmentation on the target image using a trained semantic segmentation model, identify the machined surface and the background in the target image, and output an image mask of the machined surface; a fitting module, configured to fit geometric parameters of the machined surface in the image mask, wherein the geometric parameters include a center position and a profile thickness of a hole, wherein the profile thickness is a thickness of the machined surface around the hole; a determination module, configured to determine whether the machined surface is off-center according to geometric parameters of the machined surface; Wherein, the segmentation module is used for: Inputting the target image into a trained semantic segmentation model; Extracting semantic features of each pixel in the target image through downsampling of an encoder network, wherein 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 in the decoder network to form a pixel-level probability map, wherein the skip connections are used to compensate for spatial information lost 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; Converting 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 the background; After superimposing the binary mask and the target image, the machined surface and the background are marked with different colors to obtain the image mask; Wherein, the fitting module is used for: determining edge smoothness of the machined surface in the image mask; If the edge smoothness is greater than or equal to a set smoothness threshold, the geometric parameters of the machined surface are fitted using a Hough circle search method; If the edge smoothness is less than the set smoothness threshold, a moment feature extraction method is used to fit the geometric parameters of the machined surface.

7. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 5 when executing a program stored in a memory.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Remote sensing image semantic change detection method and system fused with triple attention mechanism

    CN116863468A