Method for detecting surface defects of a workpiece based on DXF and double affine transformation

CN122434926BActive Publication Date: 2026-08-28NINGBO YONGHE ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610884033.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-06-18
Publication Date
2026-08-28
Estimated Expiration
2046-06-18

AI Technical Summary

Technical Problem

[0004]为了解决传统基于DXF的加工件表面缺陷检测精度低的技术问题,本发明的目的在于提供一种基于DXF与双重仿射变换的加工件表面缺陷检测方法,所采用的技术方案具体如下:

Benefits of technology

本发明首先采集待测加工件的表面图像并提取其中的边缘与图像关键点,解析并提取待测加工件的DXF设计文件中的几何图元与DXF关键点,为后续粗匹配提供数据基础;进一步匹配图像关键点与DXF关键点,基于匹配结果求解DXF设计文件映射至表面图像的初次仿射变换矩阵,提供粗配准基础;然后基于待测加工件的尺寸预设采样率范围,然后在每种采样率下,在几何图元上采样,获取图元采样点,为动态分析寻找与表面图像像素分辨率最匹配的最优采样率做准备;然后利用初次仿射变换矩阵对图元采样点进行仿射变换,确定每个图元采样点在表面图像中的图元粗配准点,匹配表面图像中的边缘点与图元粗配准点,并计算匹配率;基于匹配率确定最优采样率;基于最优采样率下的匹配结果求解DXF设计文件映射至表面图像的二次仿射变换矩阵,提供精配准基础;并对最优采样率下采集的图元采样点进行仿射变换,确定每个图元采样点在表面图像中的图元精配准点;匹配表面图像中的边缘点与图元精配准点,度量预期理论与物理现实的重合度,最终基于匹配结果判定缺陷检测结果。本发明利用动态采样和双重仿射机制将DXF设计文件与实拍表面图像进行跨模态高精度配准,克服传统方法易受定位偏差、油污毛刺等干扰导致的漏检误检问题,提升了工件缺陷检测精度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122434926B_ABST
    Figure CN122434926B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of image analysis, and particularly relates to a machining part surface defect detection method based on DXF and double affine transformation. The present application matches image key points with DXF key points, and solves a primary affine transformation matrix from DXF to image based on a matching result; dynamically adjusts a sampling rate, determines a primitive sampling point and performs primary affine transformation, and matches the primitive sampling point with edge points in a surface image to determine an optimal sampling rate; further solves a secondary affine transformation matrix based on a matching result under the optimal sampling rate, performs secondary affine transformation on the primitive sampling point, and matches the primitive sampling point with the edge points in the surface image to determine a defect detection result based on the matching result. The present application uses dynamic sampling and double affine mechanism to perform cross-modal high-precision registration between a DXF design file and a surface image actually taken, overcomes the missed detection and misdetected problems caused by positioning deviation, oil stains and burrs and other interferences in traditional methods, and improves the workpiece defect detection precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image analysis technology, specifically to a method for detecting surface defects in machined parts based on DXF and dual affine transformation. Background Technology

[0002] Surface defect detection of machined parts is an important part of quality control in precision manufacturing and is widely used in fields such as machining, automotive parts, and electronic components. Currently, surface defect detection methods for machined parts usually involve registering a DXF format design model with a surface image of the machined part and then comparing them to detect defects. Registration often uses a single affine transformation algorithm, and the transformation parameters are usually determined by positioning holes or other positioning points.

[0003] However, the results of affine transformation and registration accuracy depend on the rationality of the selection of positioning points and the positioning accuracy. If the number of positioning holes or positioning points is small, their distribution is unreasonable, or their representativeness is insufficient, it will be difficult to accurately determine the rotation, translation, and scaling parameters, resulting in inaccurate registration. At the same time, burrs on the workpiece may change the shape of the positioning points, and surface stains may obscure the positioning points, resulting in positioning point identification deviations. This may lead to the calculation of incorrect affine transformation parameters, resulting in large registration errors. Consequently, the detection of surface defects on the workpiece is prone to missed or false defects, failing to meet the requirements of high-precision detection. Summary of the Invention

[0004] To address the low accuracy of traditional DXF-based surface defect detection methods for machined parts, this invention aims to provide a method for detecting surface defects in machined parts based on DXF and dual affine transformation. The specific technical solution adopted is as follows: Acquire the surface image of the workpiece to be tested and extract its edges and key points; parse and extract the geometric primitives and key points of the DXF design file of the workpiece to be tested; match the key points of the image with the key points of the DXF, and solve the initial affine transformation matrix of the DXF design file to the surface image based on the matching results. The sampling rate range is preset based on the dimensions of the workpiece to be tested; at each sampling rate, sampling is performed on geometric primitives to obtain primitive sampling points; the primitive sampling points are subjected to affine transformation using the initial affine transformation matrix to determine the primitive coarse registration point in the surface image for each primitive sampling point, and the edge points in the surface image are matched with the primitive coarse registration points, and the matching rate is calculated. The optimal sampling rate is determined based on the matching rate; the second affine transformation matrix mapping the DXF design file to the surface image is solved based on the matching results under the optimal sampling rate, and the affine transformation is performed on the primitive sampling points collected under the optimal sampling rate to determine the primitive fine registration point of each primitive sampling point in the surface image; the edge points in the surface image are matched with the primitive fine registration points, and the defect detection results are determined based on the matching results.

[0005] Furthermore, the method for obtaining the key points of the image includes: Corner detection is performed on the surface image to obtain all corner points; the endpoints, midpoints, and corner points of each edge in the surface image are used as image key points.

[0006] Furthermore, the method for obtaining the DXF key points includes: The geometric primitives include at least line segments, arcs, and circles; the endpoints of line segments, the endpoints of arcs, the points where they divide into four equal parts, and the quadrant points of circles are used as DXF key points.

[0007] Furthermore, methods for matching image keypoints with DXF keypoints include: The geometric primitives are discretized into a dense point set using a rendering discrete rate. The dense point set is then rendered onto a blank canvas with the same resolution as the surface image to obtain a primitive binarized image. The edges are rendered onto a blank canvas with the same resolution as the surface image to obtain an edge binarized image. Feature matching is performed between the image keypoints in the edge binarized image and the corresponding pixels of each DXF keypoint in the primitive binarized image to obtain all matching pairs.

[0008] Furthermore, the method for pre-setting a sampling rate range based on the dimensions of the workpiece to be tested includes: When the maximum side length of the workpiece to be tested is less than the preset size, the sampling rate range is set to the preset first range; otherwise, the sampling rate range is set to the preset second range. The lower limit of the preset first range is greater than the upper limit of the preset second range, and the upper limits of both the preset first range and the preset second range are not greater than the reciprocal of the pixel equivalent of the surface image.

[0009] Furthermore, the method for obtaining the primitive sampling points includes: Sampling is performed uniformly at a sampling rate on line segments and arcs, and uniform sampling is performed on circles starting from any point to obtain all primitive sampling points.

[0010] Furthermore, the method for obtaining the matching rate includes: In a surface image, matching point pairs between a primitive coarse registration point and an edge point are determined based on the Euclidean distance between them; the matching rate is determined based on the proportion of the number of these matching point pairs.

[0011] Furthermore, the method for obtaining the optimal sampling rate includes: The sampling rate corresponding to the highest matching rate is taken as the optimal sampling rate.

[0012] Furthermore, based on the matching results of the coarse registration points and edge points of primitives at the optimal sampling rate, the second affine transformation matrix is ​​solved, including: Under the optimal sampling rate, the matching point pairs with Euclidean distance less than a preset distance threshold are taken as fine-matching point pairs. Based on the edge points in the fine-matching point pairs and the corresponding primitive sampling points of the primitive coarse-matching points, the second affine transformation matrix is ​​solved.

[0013] Furthermore, methods for determining defect detection results based on matching results include: In the surface image, matching point pairs between the primitive fine-registration point and the edge point are determined based on the Euclidean distance between the primitive fine-registration point and the edge point; primitive fine-registration points that do not belong to the matching point pairs are regarded as defect pixels, and defect regions are determined based on the defect pixels.

[0014] The present invention has the following beneficial effects: This invention first acquires a surface image of the workpiece under test and extracts its edges and key points. It then analyzes and extracts geometric primitives and DXF key points from the workpiece's DXF design file, providing a data foundation for subsequent coarse matching. Next, it matches the image key points with the DXF key points, and based on the matching results, solves the initial affine transformation matrix mapping the DXF design file to the surface image, providing a basis for coarse registration. Then, based on the dimensions of the workpiece under test, it presets a sampling rate range. At each sampling rate, it samples on the geometric primitives to obtain primitive sampling points, preparing for dynamic analysis to find the optimal sampling rate that best matches the pixel resolution of the surface image. Finally, it utilizes the initial affine transformation... The matrix performs an affine transformation on the primitive sampling points to determine the coarse registration point of each primitive sampling point in the surface image. It then matches edge points in the surface image with the coarse registration points and calculates the matching rate. Based on the matching rate, the optimal sampling rate is determined. Based on the matching results at the optimal sampling rate, the quadratic affine transformation matrix mapping the DXF design file to the surface image is solved, providing the basis for fine registration. An affine transformation is then performed on the primitive sampling points acquired at the optimal sampling rate to determine the fine registration point of each primitive sampling point in the surface image. Finally, edge points in the surface image are matched with the fine registration points to measure the overlap between the expected theory and physical reality. The final defect detection result is determined based on the matching results. This invention utilizes dynamic sampling and a dual affine mechanism to perform cross-modal high-precision registration between the DXF design file and the actual surface image, overcoming the problems of missed and false detections caused by positioning deviations, oil stains, burrs, etc., which are easily affected by traditional methods, thus improving the accuracy of workpiece defect detection. Attached Figure Description

[0015] Figure 1 This is a flowchart of a method for detecting surface defects in machined parts based on DXF and double affine transformation, provided as an embodiment of the present invention. Detailed Implementation

[0016] The following description, in conjunction with the accompanying drawings, details a specific scheme for a method for detecting surface defects in machined parts based on DXF and dual affine transformation, provided by the present invention.

[0017] Please see Figure 1 The diagram illustrates a flowchart of a method for detecting surface defects in machined parts based on DXF and double affine transformation, according to an embodiment of the present invention. The method specifically includes: Step S1: Acquire the surface image of the workpiece to be tested and extract its edges and key points; parse and extract the geometric primitives and key points of the DXF design file of the workpiece to be tested; match the key points of the image with the key points of the DXF, and solve the initial affine transformation matrix of the DXF design file to the surface image based on the matching results.

[0018] The surface image of the workpiece under test contains a large amount of redundant information unrelated to size and structure, such as uneven lighting, surface oil stains, and cluttered background textures. However, the key points that truly characterize the workpiece contour can effectively remove unstructured interference, thereby helping to lock the physical boundary of the workpiece. Based on this, the embodiments of the present invention first acquire the surface image of the workpiece under test and extract the image key points therein. The image key points are the skeleton in the real-shot image, representing the true pose and local shape of the workpiece in physical space.

[0019] Specifically, the first step is to construct a ghost-free, high-contrast image acquisition environment: use an industrial area scan camera with 5 megapixels or higher (resolution requirement not less than 2448×2048), paired with a ring LED light source with brightness uniformity ≥90% to eliminate projection blind spots on the workpiece surface; fix the camera directly above the worktable (e.g., at 30cm), ensuring that the lens optical axis is perpendicular to the worktable surface, and the physical installation angle deviation is limited to ≤5°; set the camera shutter speed to 1 / 200s and ISO to 100 to avoid motion blur caused by slight vibrations; Place the workpiece to be tested in the center of the worktable and place a calibration reference object of known physical size (e.g., a 10cm×10cm calibration square) within the (shooting) field of view; control the camera to trigger shooting and acquire a blur-free, uniformly illuminated original RGB image of the workpiece to be tested; perform grayscale processing on the original RGB image, and then perform Gaussian filtering noise reduction (e.g., using a 5×5 convolution kernel with a standard deviation of 1.0) to smooth the unstructured high-frequency texture noise on the surface and obtain the surface image of the workpiece to be tested.

[0020] It should be noted that the above image processing procedures are all well-known technologies and will not be described in detail here.

[0021] Before preprocessing the original RGB image, it is necessary to determine the image resolution. Based on the pixel span occupied by the calibration square in the original RGB image, the pixel equivalent Rp (unit: mm / pixel) of the current acquisition field of view is calculated. This is a well-known technique and will not be elaborated further. The pixel equivalent provides a benchmark for subsequent calculation of the defect area and constraint sampling rate range.

[0022] Considering that if global key point detection is performed directly, the grid points in the calibration square will be misidentified as key points representing the workpiece contour, affecting the extraction accuracy of key points in the image; therefore, it is also necessary to eliminate grid interference and accurately extract key points in the image.

[0023] Specifically, the region of interest (ROI) of the workpiece under test is segmented from the surface image based on a pre-trained neural network model, and subsequent key point extraction is performed only in the ROI. In other embodiments, a masking method can also be used: the calibration square is usually located at a fixed position on the worktable, and the pixel values ​​of the area where the calibration square is located are forcibly filled with the background color by using a preset coordinate range or specific texture features of the calibration square, and the remaining area is the ROI of the workpiece under test. The above are all well-known technical means and will not be described in detail.

[0024] Further extract all edges and all image key points from the surface image (region of interest of the workpiece under test).

[0025] Specifically, the adaptive Canny edge detection algorithm is used to extract edges from the surface image (the region of interest of the workpiece under test). To avoid the generalization problem caused by manually setting the threshold, the high threshold Th is automatically determined by Otsu thresholding method, and the low threshold is adaptively set to Th / 3. Edge tracing is then performed to obtain all initial edges. Then, morphological optimization is performed on isolated noise points and edge breakage defects in the initial edge. Specifically, a 3×3 rectangular structural element is used to perform opening operation (erosion followed by dilation to remove isolated oil stain reflection noise points) and closing operation (dilation followed by erosion to fill in minor gaps) in sequence, and finally output an edge with connectivity and anti-interference.

[0026] Preferably, in one embodiment of the present invention, considering that the corner points in the surface image (the region of interest of the workpiece under test) correspond to the inflection points and intersections of the workpiece contour, spatial positioning constraints are provided to help lock translation and rotation deviations; while the workpiece in the DXF design file is composed of pure geometric primitives such as line segments and arcs, and the edge endpoints and midpoints correspond to the start, end, and extension features of the line segments or arcs; and for smooth workpieces or long straight line workpieces lacking corner points, the edge endpoints and midpoints can provide constraint anchor points distributed along the contour to prevent sliding misalignment during affine transformation; therefore, the method for obtaining image key points includes: Corner detection is performed on the surface image to obtain all corner points; the endpoints, midpoints, and corner points of each edge in the surface image are used as image key points.

[0027] Harris corner detection is performed on the surface image (the region of interest of the workpiece under test) to extract all corner points that represent the inflection points of the workpiece contour; then the endpoints and midpoints of each edge, as well as all corner points, are used as image key points to represent the real physical contour of the workpiece under test; then an image coordinate system is constructed with the lower left corner of the surface image as the origin to determine the coordinates of each image key point.

[0028] It should be noted that the edge detection, morphological optimization processing and corner detection mentioned above are all well-known technical means. Other processing means may also be used in other embodiments, which will not be elaborated here.

[0029] DXF design files serve as a standard non-destructive data source for the workpiece under test, reflecting its physical dimensions and contour boundaries under ideal conditions. Parsing and extracting geometric primitives from DXF design files can transform abstract vector graphics protocols into quantifiable geometric elements, thereby providing a standard comparison template free from physical wear and machining deviations. By registering and aligning actual captured image features with errors and defects onto this standard template, global interference such as workpiece placement and rotation angles can be effectively eliminated, thus accurately inferring and quantifying the surface defects and deformations of the workpiece under test. Based on this, the embodiments of the present invention further analyze and extract the geometric primitives and DXF key points in the DXF design file of the workpiece under test; the DXF key points represent the absolute spatial anchor points of the workpiece under test without surface defects and ambient light interference, and can be used as a priori reference to establish a cross-modal mapping relationship with the image key points with shooting errors, providing accurate target coordinate constraints for subsequent affine transformations.

[0030] Preferably, in one embodiment of the present invention, considering that line segments, arcs, and circles are the basic constituent primitives in DXF design files, capable of completely representing the geometric contour topology of most workpieces; wherein, the endpoints of line segments can uniquely determine the spatial position, direction, and length boundary of the straight line edge, serving as absolute anchor points for locating the straight line contour; the endpoints of arcs define the start and end range of the curve, and introducing the four equal division points of the arc can effectively anchor the curvature direction and convexity of the arc; since closed circles lack natural start and end boundaries, extracting their quadrant points can construct uniformly distributed spatial anchor points on the contour, providing precise constraints for circular holes or outer circular contours; therefore, the method for obtaining DXF key points includes: Geometric primitives include at least line segments, arcs, and circles; the endpoints of line segments, the endpoints of arcs, the points where they divide into four equal parts, and the quadrant points of circles are used as DXF keypoints.

[0031] It should be noted that the quadrant points of the circle are the four points at 0°, 90°, 180°, and 270° in the orthogonal coordinate system of the DXF design file; the determination of the four division points and quadrant points are all existing technical means and will not be elaborated further.

[0032] Since the actual surface image and the DXF design file are in different coordinate spaces, and there are unavoidable global positional deviations such as translation, rotation and scaling during image acquisition, the two cannot be directly compared in space. Matching image key points and DXF key points can cross pixel mode and vector mode, and establish an accurate spatial isomorphic mapping relationship between actual contour features and ideal design anchor points, which prepares for the subsequent preliminary alignment of the surface image and DXF design file based on the matching results. Furthermore, the parameter calculation of the affine transformation matrix must rely on a set of known, homogeneous spatial coordinate mapping pairs as constraints; the matching results of image key points and DXF key points accurately provide a mapping set between measured pixel coordinates and ideal vector coordinates; solving the initial affine transformation matrix based on the matching results can mathematically and objectively quantify the global pose and scale deviations introduced by the workpiece during the image acquisition stage; using the initial affine transformation matrix to perform affine transformation on the surface image to obtain a coarse registration image can help quickly eliminate misalignment and achieve global coarse positioning between the measured image and the standard template.

[0033] Based on this, the embodiments of the present invention match the key points of the image with the key points of DXF, further solve the initial affine transformation matrix based on the matching results, and perform affine transformation on the surface image to obtain a coarsely registered image; avoiding the huge computational overhead caused by directly performing global pixel comparison, and providing a reliable initial registration benchmark for subsequent introduction of multi-dimensional sampling rate for local fine registration.

[0034] Preferably, in one embodiment of the present invention, considering that the analytical geometry of the DXF design file cannot be directly used in image feature calculation, it is discretized into a dense point set by rendering the discrete rate and rendered to a two-dimensional pixel space with the same resolution as the surface image. This can construct an idealized contour template without background interference. The edge points in the surface image are synchronously rendered to the two-dimensional pixel space, and an edge contour map can be constructed separately. This ensures that the geometric contours in the DFX design file and the edge contours in the surface image are both under a unified mode of binary geometric distribution, so as to facilitate subsequent matching. Therefore, the method for matching image key points and DXF key points includes: Geometric primitives are discretized into dense point sets using a rendering discrete rate. These dense point sets are then rendered onto a blank canvas with the same resolution as the surface image to obtain a primitive binarized image. Edges are rendered onto a blank canvas with the same resolution as the surface image to obtain an edge binarized image. Feature matching is performed between the image keypoints in the edge binarized image and the corresponding pixels of each DXF keypoint in the primitive binarized image to obtain all matching pairs.

[0035] Specifically, firstly, the rendering discrete rate is set: extract the pixel equivalent Rp, set the rendering discrete rate to 1 / Rp, which represents the number of pixels corresponding to each millimeter length; sample at equal intervals on each geometric primitive with the rendering discrete rate (a well-known technical means, which will not be elaborated here), thereby transforming continuous abstract vector primitives into discrete dense point sets; It should be noted that if the dispersion rate is lower than 1 / Rp, when the discrete points on the geometric primitives are mapped to image pixels, gaps larger than one pixel will appear between the points, resulting in broken and discontinuous contour lines in the rendered image. This leads to a loss of local gradient information when extracting SIFT features, affecting the matching effect. If the dispersion rate is higher than 1 / Rp, when the discrete points on the geometric primitives are mapped to image pixels, multiple discrete points may overlap and fall on the same pixel, resulting in data redundancy. Therefore, the rendering dispersion rate is set to 1 / Rp, so that the discrete points on the geometric primitives are continuously adjacent in the rendered image canvas, ensuring complete contour closure while reducing computational overhead.

[0036] Then, create a zero-matrix with the same resolution as the surface image as a blank canvas (all pixel values ​​are 0); render each point in the dense point set onto the blank canvas with the same resolution as the surface image to obtain a primitive binarized image; similarly, edge points can be rendered onto another blank canvas to construct an edge binarized image; these are well-known techniques, briefly described here: A canvas coordinate system is constructed with the bottom left corner of the blank canvas as the origin. For each discrete point in the dense point set, the coordinates (x, y) of the discrete point in the orthogonal coordinate system of the DXF design file are extracted. Before rendering, the minimum values ​​xmin and ymin of the bounding box boundaries of all primitives in the DXF are extracted. The rounded value of x-xmin / Rp is used as the x' of the rendered point in the blank canvas to ensure that the horizontal and vertical coordinates of the generated canvas are non-negative. Similarly, the y' of the rendered point in the blank canvas can be determined. Then, the coordinates of the discrete points in the canvas coordinate system are determined for mapping, and the pixel value is set to 255 (target foreground). After rendering (mapping) all discrete points to the blank canvas, the primitive binarized image can be obtained. The image coordinate system is consistent with the canvas coordinate system. The edge points are directly mapped to the canvas coordinate system with the same coordinates to obtain the rendered edge binarized image.

[0037] Based on coordinates, key points in the edge binarized image can be located. SIFT matching is then performed between these key points and the corresponding (mapped) pixels of each DXF key point in the primitive binarized image to obtain all matching pairs. This is a well-known technique, briefly described here: Obtain the SIFT feature descriptors of the corresponding (mapped) pixels of the image keypoints and DXF keypoints, and calculate the Euclidean distance between the SIFT feature descriptors of each image keypoint and each corresponding (mapped) pixel of the DXF keypoints. Use the Lowe's Ratio Test method. When the ratio of the nearest neighbor distance to the second nearest neighbor distance is less than a preset distance ratio threshold (e.g., 0.75), the initial match is considered successful. Input all the initial matched point pairs into the RANSAC (Random Sample Consensus) algorithm, set the inlier distance threshold to 2 pixels, and perform iterative filtering to remove free mismatched points (outside points) that do not conform to the global rigid geometric transformation trend. The inliers that are finally retained are the matched pairs.

[0038] In other embodiments, shape context feature matching can be used instead of SIFT matching. This is a well-known technique, which is briefly described here: extract the coordinates of the corresponding pixels of the image key points and DXF key points, calculate the shape context feature descriptor of each key point, and then calculate the chi-square distance between the descriptors. Point pairs with a chi-square distance less than a preset threshold, such as 0.2, are considered as matching pairs.

[0039] Since there are differences in translation, rotation, and scaling between the image coordinate system and the DXF coordinate system, the initial affine transformation matrix can be solved by matching key points to establish a global mapping relationship between the two coordinate systems. After obtaining all matching pairs, the initial affine transformation matrix mapping the DXF design file to the surface image is further solved. The initial affine transformation matrix represents the global mapping relationship between the orthogonal coordinate system of the DXF design file and the image coordinate system of the surface image, including rotation, translation, and scaling parameters. The initial affine transformation can help to roughly register DXF primitives on the edge of the surface image, providing an initial coarse registration reference.

[0040] Solving for the first affine transformation matrix is ​​a well-known technique, which is briefly described here: take the DXF keypoints in the matching pair as the mapping target, and take their coordinates in the orthogonal coordinate system of the DXF design file as the independent variable; take the image keypoints in the matching pair as the mapping reference, and take their coordinates in the image coordinate system of the surface image as the dependent variable; then use the least squares method to solve for the first affine transformation matrix.

[0041] It should be noted that if there are fewer than 2 matching pairs of pixels between the image keypoint and the corresponding (mapped) pixel points of the DXF keypoint, a positioning failure signal will be output directly and subsequent operations will be terminated; the shooting angle will be readjusted to obtain the surface image to avoid failure of affine transformation solution.

[0042] Step S2: Based on the dimensions of the workpiece to be tested, a sampling rate range is preset; at each sampling rate, sampling is performed on geometric primitives to obtain primitive sampling points; the primitive sampling points are subjected to affine transformation using the initial affine transformation matrix to determine the primitive coarse registration point in the surface image for each primitive sampling point, and the edge points in the surface image are matched with the primitive coarse registration points, and the matching rate is calculated.

[0043] Since the matching pair between image key points and DXF key points only provides coarse registration information of sparse key points on the workpiece outline, it is impossible to compare local details of the workpiece, which may affect the workpiece defect detection effect. Therefore, it is necessary to further perform higher-precision registration between the surface image of the workpiece to be tested and the DXF design file to compare local details. However, the pixel equivalent of workpieces of different sizes is different under a fixed camera field of view. If a fixed sampling rate is used, it may cause the sampling points to be severely stacked in the same pixel of the image, or too sparse to lose geometric details. Based on this, the embodiments of the present invention first preset the sampling rate range based on the size of the workpiece to be tested, and then sample on the geometric primitives at each sampling rate to obtain primitive sampling points. This prepares for finding the optimal sampling rate (which represents the optimal discrete point density) that best matches the pixel resolution of the surface image, thereby achieving accurate adaptation of vector data and pixel images without wasting computing power.

[0044] Preferably, in one embodiment of the present invention, considering that small-sized workpieces occupy a smaller proportion of the field of view and have denser edge geometric features, a higher frequency of sampling points is required to restore the fine contour; while for large-sized workpieces, if the same high frequency is used, the total number of sampling points will increase explosively, reducing registration efficiency; by preset sampling rate range, it can be ensured that small workpieces do not lose details and large workpieces do not slow down the process; and considering that if the sampling rate is higher than 1 / Rp, when discrete points on geometric primitives are mapped to image pixels, there may be multiple discrete points overlapping on the same pixel, thus generating data redundancy; therefore, the method of preset sampling rate range based on the size of the workpiece to be tested includes: When the maximum side length of the workpiece to be tested is less than the preset size, the sampling rate range is set to the preset first range; otherwise, the sampling rate range is set to the preset second range. The lower limit of the preset first range is greater than the upper limit of the preset second range, and the upper limits of both the preset first range and the preset second range are not greater than the reciprocal of the pixel equivalent of the surface image.

[0045] Specifically, the maximum outer contour side length of the workpiece to be tested is extracted from the DXF design file and compared with a preset size, such as 100mm. When it is less than the preset size, the workpiece is determined to be a small-sized workpiece, and the sampling rate range is set to the preset first range, which is 50-100 points / mm in this example. When it is greater than or equal to the preset size, the workpiece is determined to be a large-sized workpiece, and the sampling rate range is set to the preset second range, which is 5-20 points / mm in this example.

[0046] In other examples, the implementer can also adjust the preset size, the preset first range, and the preset second range themselves; wherein, the lower limit of the preset first range is greater than the upper limit of the preset second range to ensure that the sampling density for workpieces of different sizes has obvious step-like characteristics and avoid range overlap during subsequent sampling step search; the upper limits of the preset first range and the preset second range are not greater than the reciprocal of the pixel equivalent of the surface image to avoid multiple sampling points overlapping in the same pixel during subsequent mapping.

[0047] After setting the sampling rate range, further discretization sampling with a fixed step size is performed to determine different sampling rates. Different sampling rates can change the phase aliasing and sub-pixel truncation error when the sampling points are mapped to the pixel grid. Then, at each sampling rate, sampling is performed on the geometric primitives to obtain primitive sampling points, which prepares for subsequent affine transformations for matching or registration.

[0048] In one embodiment of the present invention, a global traversal is performed within a sampling rate range with a preset step size, such as 5 points / mm. Starting from the lower limit of the range, different sampling rates are determined step by step, and then discrete sampling is performed on each geometric primitive with each sampling rate.

[0049] Preferably, in one embodiment of the present invention, the method for obtaining primitive sampling points includes: Sampling is performed uniformly at a sampling rate on line segments and arcs, and uniform sampling is performed on circles starting from any point to obtain all primitive sampling points.

[0050] Specifically, for each line segment or each arc, sampling is performed at equal intervals starting from any endpoint and at a sampling rate; for a circle, sampling is performed at equal intervals starting from any point and at a sampling rate; finally, all primitive sampling points on each geometric primitive are determined.

[0051] It should be noted that the analysis method for the matching rate is the same for each sampling frequency during the sampling rate optimization process. Here, we will only take any sampling rate as an example for analysis and description, and will not go into detail about each one.

[0052] After obtaining all primitive sampling points on the geometric primitives, this embodiment of the invention further maps each primitive sampling point in the orthogonal coordinate system of the DXF design file to the image coordinate system of the surface image, and determines the primitive coarse registration point of each primitive sampling point in the surface image, so as to eliminate the heterogeneous influence between coordinate systems and prepare for subsequent evaluation of the registration matching relationship between the primitive sampling point (corresponding to the primitive coarse registration point) and the edge points in the surface image.

[0053] Specifically, the affine transformation matrix is ​​used to perform an affine transformation on the primitive sampling points to obtain the primitive coarse registration point of each primitive sampling point in the surface image. The primitive coarse registration point represents the approximate position of each primitive sampling point on the DXF design file roughly projected into the surface image, reflecting the standard macroscopic contour skeleton of the workpiece.

[0054] It should be noted that the application of affine transformation is a well-known technique, and the process of obtaining the coarse registration points of primitives will not be elaborated here. Since the first affine transformation is a coarse registration, there is usually a slight local deviation between the coarse registration points of primitives and the actual edge points on the surface image, which provides a basis for subsequent second affine transformations to improve the local registration accuracy.

[0055] Further matching of edge points and primitive coarse registration points in the surface image, and calculation of the matching rate. The matching rate characterizes the spatial adaptability and representational fidelity of the DXF theoretical design model and the actual workpiece contour at the pixel level under the current sampling rate, providing a basis for subsequent sampling rate optimization.

[0056] Preferably, in one embodiment of the present invention, considering that after affine transformation, the coarse registration point of the primitive represents the theoretically designed predicted position, while the edge points of the surface image represent the actual contour of the object, by calculating the Euclidean distance between the two in the same pixel coordinate system, the spatial deviation can be accurately quantified, thereby determining whether a match exists; furthermore, the matching rate can be evaluated based on the proportion of successful matches; then the method for obtaining the matching rate includes: In a surface image, matching point pairs between a primitive coarse registration point and an edge point are determined based on the Euclidean distance between them; the matching rate is determined based on the proportion of matching point pairs.

[0057] Specifically, the coordinates of the coarse registration points and edge points in the image coordinate system are extracted separately. To avoid blindly calculating Euclidean distances in the vast global pixel space, which would lead to computational overload, the K-nearest neighbor algorithm (KNN, K=1) is first used to find the nearest edge point to each coarse registration point in the surface image. The Euclidean distance between each coarse registration point and the nearest edge point is then calculated. A preset Euclidean distance threshold, such as 5 pixels, is then used. When the Euclidean distance is less than 5 pixels, the coarse registration point and its nearest edge point are marked as a matching point pair. The number of matching point pairs is then divided by the number of coarse registration points to measure the proportion of matching points and obtain the matching rate.

[0058] Step S3: Determine the optimal sampling rate based on the matching rate; solve the quadratic affine transformation matrix of the DXF design file to the surface image based on the matching results under the optimal sampling rate, and perform affine transformation on the primitive sampling points collected under the optimal sampling rate to determine the primitive fine registration point of each primitive sampling point in the surface image; match the edge points in the surface image with the primitive fine registration points, and determine the defect detection result based on the matching results.

[0059] The optimal sampling rate is further determined based on the matching rate.

[0060] Preferably, in one embodiment of the present invention, since the matching rate directly reflects the geometric fit between the DXF primitive contour features and the real edge contour features, the sampling rate corresponding to the highest matching rate is taken as the optimal sampling rate.

[0061] Since the matching results at the optimal sampling rate can provide a high-quality global mapping relationship of dense points, the affine transformation parameters of the DXF design file mapped to the surface image can be solved again based on the matching results at the optimal sampling rate. This can provide a second, accurate compensation for the slight rotation, translation, or scale deviations missed during the initial transformation. This dual affine mechanism, which progresses from "global coarse adjustment of sparse key points" to "local fine adjustment of dense edge points", can accurately align DXF geometric primitives with image pixels, providing a foundation for the subsequent accurate extraction of real defect features. Therefore, in this embodiment of the invention, the second affine transformation matrix of the DXF design file to the surface image is solved based on the matching results under the optimal sampling rate. The second affine transformation matrix represents the high-precision micro-error compensation mapping relationship between the orthogonal coordinate system of the DXF design file and the image coordinate system of the surface image on the basis of the initial alignment, which prepares for subsequent fine registration.

[0062] Preferably, in one embodiment of the present invention, since the workpiece surface may have stains, oil stains, or machining defects (i.e., the actual defects to be detected), some primitive coarse registration points may be incorrectly matched to these noise points. Therefore, the matching point pairs under the optimal sampling rate do not all represent the correct physical correspondence, which may affect the solution effect of the second affine transformation matrix. However, limiting the distance threshold can extract the most representative high-confidence mapping samples (i.e., fine registration point pairs). The second affine transformation matrix solved based on the fine registration point pairs can reduce the influence of local distortion and noise. Therefore, solving the second affine transformation matrix based on the matching results of primitive coarse registration points and edge points under the optimal sampling rate includes: Under the optimal sampling rate, the matching point pairs with Euclidean distance less than the preset distance threshold are taken as fine registration point pairs. Based on the edge points in the fine registration point pairs and the corresponding primitive sampling points of the primitive coarse registration points, the second affine transformation matrix is ​​solved.

[0063] Specifically, firstly, all matching point pairs under the optimal sampling rate are extracted, and a preset distance threshold, such as 2 pixels, is set. When the Euclidean distance is less than 2 pixels, the corresponding matching point pair is taken as a fine-matching point pair. In other embodiments, the matching point pairs can also be sorted in ascending order based on the Euclidean distance, and the bottom 20% of the matching point pairs (i.e., matching point pairs with larger Euclidean distances) are removed, and the remaining matching point pairs are taken as fine-matching point pairs. Furthermore, the primitive sampling points of the coarse registration points in the fine registration point pair are taken as the mapping targets in the DXF design file, and their coordinates in the orthogonal coordinate system of the DXF design file are taken as independent variables; the edge points in the fine registration point pair are taken as the mapping reference points, and their coordinates in the image coordinate system of the surface image are taken as dependent variables; then the least squares method is used to solve the second affine transformation matrix; solving the second affine transformation matrix is ​​a well-known technique and will not be elaborated further.

[0064] After determining the second affine transformation matrix, the primitive sampling points acquired at the optimal sampling rate can be further subjected to affine transformation, so that they are mapped from the orthogonal coordinate system of the DXF design file to the image coordinate system of the surface image. This eliminates the slight rotation, translation and scaling distortion left over from the coarse registration stage and redistributes the coordinates, so as to determine the primitive fine registration point of each primitive sampling point in the surface image.

[0065] Specifically, a second affine transformation matrix is ​​used to perform an affine transformation on the primitive sampling points to obtain the primitive fine-alignment point of each primitive sampling point in the surface image. The coordinates of the primitive fine-alignment point in the image coordinate system are no longer the approximate theoretical prediction position with global residuals, but represent the relatively more accurate standard geometric contour of the workpiece in the image coordinate system. This provides an absolute reference line for subsequent determination of whether there are defects such as missing parts, protrusions or dimensional deviations on the actual edge of the workpiece under test.

[0066] It should be noted that the application of affine transformation is a well-known technique, and the process of obtaining the precise registration points of primitives will not be elaborated further.

[0067] After dual affine transformation and optimal sampling rate screening, the precise registration points of primitives can represent the standard contour skeleton of the workpiece in the image coordinate system; while the edge points in the surface image objectively record the real contour shape of the workpiece after production and processing; matching and comparing the edge points with the precise registration points of primitives can help measure the degree of overlap between the expected theory and physical reality, and thus evaluate whether the actual workpiece deviates from the standard design model to locate defects; therefore, in this embodiment of the invention, the edge points in the surface image are matched with the precise registration points of primitives, and the defect detection result is finally determined based on the matching result.

[0068] Considering that for a qualified processing area, the actual edge points captured will closely match the corresponding precise alignment points of the graphic elements in spatial position; however, if the workpiece has defects such as chipping, burrs, scratches, or dimensional errors, the actual edge points captured will deviate from the theoretical position (precise alignment points of the graphic elements) or may not exist at all; based on the matching comparison at the spatial distance level, it can help locate defective pixels that deviate from the theoretical position. Furthermore, considering that a single, scattered defective pixel may represent weak noise, but when multiple defective pixels are continuously distributed along the geometric path or form a connected feature in the local space, it indicates that there is a substantial defect with physical significance at that location, thereby locating the defect area and providing a basis for subsequent quality rating and production traceability. Based on this, in a preferred embodiment of the present invention, the method for determining the defect detection result based on the matching result includes: In the surface image, matching point pairs between the primitive fine-registration point and the edge point are determined based on the Euclidean distance between the primitive fine-registration point and the edge point; primitive fine-registration points that do not belong to the matching point pairs are regarded as defect pixels, and defect regions are determined based on the defect pixels.

[0069] Specifically, the coordinates of the precise registration points and edge points in the image coordinate system are extracted respectively; the K-nearest neighbor algorithm (KNN, K=1) is used to find the nearest edge point to each precise registration point in the surface image, and the Euclidean distance between each precise registration point and the nearest edge point is further calculated; a preset Euclidean distance threshold, such as 2 pixels, is set. When the Euclidean distance is less than 2 pixels, the precise registration point of the primitive and its nearest edge point are marked as a matching point pair; Furthermore, the primitives that do not belong to the matching point pairs are identified as defective pixels. Topological neighborhood analysis is then performed on the defective pixels, specifically using a region connectivity detection algorithm to obtain all connected regions. To eliminate non-substantial interference such as noise, a threshold for area or length is preset. In one example of the present invention, the area (i.e. the number of pixels) of each connected component is counted, and an area threshold such as 10 is set. When the area of ​​a connected component is greater than 10 pixels, it can be considered as a real defect area; otherwise, it is considered as noise interference. In another example, the diagonal length of the smallest bounding rectangle of the connected component can be calculated and used as the region length (unit: pixels). A minimum defect length threshold is preset, such as 0.05mm. The region length is converted to a unit based on pixel equivalents and then compared with the preset minimum defect length threshold. When it is greater than the threshold, the connected component is determined to be a real defect region.

[0070] At this point, all defect areas in the surface image have been located.

[0071] In summary, this invention matches key points in the surface image of the workpiece under test with key points on geometric primitives in the DXF design file. Based on the matching results, it solves for the initial affine transformation matrix mapping the DXF design file to the surface image. A preset sampling rate range is defined. At each sampling rate, primitive sampling points are extracted from the geometric primitives. The initial affine transformation matrix is ​​used to perform an affine transformation on the primitive sampling points to determine their coarse registration points in the surface image. Edge points are matched with the coarse registration points, and the matching rate is calculated to determine the optimal sampling rate. Based on the matching results at the optimal sampling rate, a second affine transformation matrix is ​​solved, and the primitive sampling points acquired at the optimal sampling rate are subjected to an affine transformation to determine their fine registration points in the surface image. Edge points in the surface image are matched with the fine registration points, and the defect detection result is determined based on the matching results. This invention utilizes dynamic sampling and a dual affine mechanism to perform cross-modal, high-precision pixel-level registration between DXF design files and actual surface images, overcoming the problems of missed and false detections caused by positioning deviations, oil stains, burrs, and other interferences in traditional methods, thereby improving the accuracy of workpiece defect detection.

Claims

1. A method for detecting surface defects in machined parts based on DXF and double affine transformation, characterized in that, The method includes: Acquire the surface image of the workpiece to be tested and extract its edges and key points; parse and extract the geometric primitives and key points of the DXF design file of the workpiece to be tested; match the key points of the image with the key points of the DXF, and solve the initial affine transformation matrix of the DXF design file to the surface image based on the matching results. The sampling rate range is preset based on the dimensions of the workpiece to be tested; at each sampling rate, sampling is performed on geometric primitives to obtain primitive sampling points; the primitive sampling points are subjected to affine transformation using the initial affine transformation matrix to determine the primitive coarse registration point in the surface image for each primitive sampling point, and the edge points in the surface image are matched with the primitive coarse registration points, and the matching rate is calculated. The optimal sampling rate is determined based on the matching rate; the second affine transformation matrix mapping the DXF design file to the surface image is solved based on the matching results under the optimal sampling rate, and the affine transformation is performed on the primitive sampling points collected under the optimal sampling rate to determine the primitive fine registration point of each primitive sampling point in the surface image; the edge points in the surface image are matched with the primitive fine registration points, and the defect detection results are determined based on the matching results.

2. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, The method for obtaining key points in the image includes: Corner detection is performed on the surface image to obtain all corner points; the endpoints, midpoints, and corner points of each edge in the surface image are used as image key points.

3. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, The method for obtaining DXF key points includes: The geometric primitives include at least line segments, arcs, and circles; the endpoints of line segments, the endpoints of arcs, the points where they divide into four equal parts, and the quadrant points of circles are used as DXF key points.

4. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, Methods for matching image keypoints with DXF keypoints include: The geometric primitives are discretized into a dense point set using a rendering discrete rate. The dense point set is then rendered onto a blank canvas with the same resolution as the surface image to obtain a primitive binarized image. The edges are rendered onto a blank canvas with the same resolution as the surface image to obtain an edge binarized image. Feature matching is performed between the image keypoints in the edge binarized image and the corresponding pixels of each DXF keypoint in the primitive binarized image to obtain all matching pairs.

5. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, Methods based on the preset sampling rate range of the dimensions of the workpiece to be measured include: When the maximum side length of the workpiece to be tested is less than the preset size, the sampling rate range is set to the preset first range; otherwise, the sampling rate range is set to the preset second range. The lower limit of the preset first range is greater than the upper limit of the preset second range, and the upper limits of both the preset first range and the preset second range are not greater than the reciprocal of the pixel equivalent of the surface image.

6. The method for detecting surface defects of machined parts based on DXF and dual affine transformation according to claim 3, characterized in that, The method for obtaining the primitive sampling points includes: Sampling is performed uniformly at a sampling rate on line segments and arcs, and uniform sampling is performed on circles starting from any point to obtain all primitive sampling points.

7. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, The method for obtaining the matching rate includes: In a surface image, matching point pairs between a primitive coarse registration point and an edge point are determined based on the Euclidean distance between them; the matching rate is determined based on the proportion of the number of these matching point pairs.

8. The method for detecting surface defects of machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, The method for obtaining the optimal sampling rate includes: The sampling rate corresponding to the highest matching rate is taken as the optimal sampling rate.

9. The method for detecting surface defects in machined parts based on DXF and dual affine transformation according to claim 7, characterized in that, Solving for the second affine transformation matrix based on the matching results of primitive coarse registration points and edge points at the optimal sampling rate includes: Under the optimal sampling rate, the matching point pairs with Euclidean distance less than a preset distance threshold are taken as fine-matching point pairs. Based on the edge points in the fine-matching point pairs and the corresponding primitive sampling points of the primitive coarse-matching points, the second affine transformation matrix is ​​solved.

10. The method for detecting surface defects of machined parts based on DXF and dual affine transformation according to claim 1, characterized in that, Methods for determining defect detection results based on matching results include: In the surface image, matching point pairs between the primitive fine-registration point and the edge point are determined based on the Euclidean distance between the primitive fine-registration point and the edge point; primitive fine-registration points that do not belong to the matching point pairs are regarded as defect pixels, and defect regions are determined based on the defect pixels.

Citation Information

Patent Citations

  • Product edge defect detection method

    CN112330678A

  • Casting surface defect automatic detection method

    CN121169855A