A tool edge detection method for intelligent tool adjuster
Through the improved Canny operator and Zernike moment compensation technology, the problem of insufficient tool edge detection accuracy is solved, and high-efficiency and high-precision visual size detection is achieved, which is suitable for high-precision detection under low-resolution camera conditions.
Patent Information
- Application Number
- CN202311760951.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-20
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2043-12-20
AI Technical Summary
The existing technology has problems of insufficient accuracy and high equipment cost in tool edge detection. Especially under low-resolution camera conditions, it is difficult to achieve high-efficiency and high-precision visual size detection.
The improved Canny operator is used for edge extraction, and the Zernike moment is combined for sub-pixel level compensation. The edge point positioning accuracy is improved through image acquisition, guided filtering preprocessing, gradient detection templates and non-maximum suppression methods.
It achieves higher precision of tool image information, improves detection efficiency and accuracy, and can stably reach a detection accuracy of 0.01mm under low-resolution cameras, meeting the needs of high-precision tool detection.
Smart Images

Figure CN117670915B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of machine tool processing and image recognition, and in particular relates to a tool edge detection method for an intelligent tool adjuster. Background Art
[0002] With the continuous development of intelligent manufacturing technology, the measurement accuracy of machine tool tools is getting higher and higher. This is because the accuracy of tool setting determines the accuracy of the mapping between the machining coordinate system and the actual machine tool coordinate system in actual processing, and is one of the important factors that determine the machining accuracy of machine tools. Tool setting can be divided into three types: manual tool setting, on-machine tool setting, and presetter tool setting. Presetters are popular with many manufacturers because they do not require specific machine tools, have high enough detection accuracy, and have low equipment costs. Image-based tool presetters based on image processing are widely used due to their non-contact and wide range of applications. Among them, the edge positioning of the tool image determines the measurement accuracy and is the most important part of tool detection. Summary of the invention
[0003] The present invention aims to solve the deficiencies of the prior art and proposes a tool edge detection method for an intelligent tool adjuster. The Canny operator is improved by updating the preprocessing operation, gradient detection template, and non-maximum suppression method, so that the rough edge positioning can detect the tool edge as accurately as possible. The edge point position is then fine-tuned by the Zernike moment, and the edge position after Zernike fine-tuning is compensated based on the three-layer edge step model, thereby achieving more accurate edge point positioning.
[0004] To achieve the above object, the present invention provides the following solutions:
[0005] A tool edge detection method for an intelligent tool adjuster includes: an image acquisition link, an edge extraction link and a compensation link;
[0006] The image acquisition link is used to acquire the tool image and pre-process the tool image to obtain a processed image;
[0007] The edge extraction step uses an improved Canny operator to extract edges from the processed image to obtain edge vectors;
[0008] The compensation link performs sub-pixel level compensation on the edge vector based on the Zernike moment, improves the edge vector accuracy, and obtains a tool recognition result.
[0009] Preferably, the image acquisition link includes: image acquisition and image preprocessing;
[0010] The image acquisition process uses an industrial camera to photograph the tool to obtain the tool image;
[0011] The image preprocessing process uses a guided filtering algorithm to preprocess the tool image to obtain the processed image.
[0012] Preferably, the image preprocessing process includes:
[0013] O i =a k G i +b k ,i∈w k
[0014] Among them, O is the output image, G is the guide image, w is the window size, k is the position of each pixel in the window itself, i is the pixel position corresponding to the pixel position in the window, and a and b are:
[0015]
[0016] Among them, I is the input image, cov and var are image covariance and variance operations respectively, and are the pixel grayscale means of the input image and the guide image respectively.
[0017] Preferably, the edge extraction link adopts an improved Canny operator, including improvements to the gradient calculation process and non-maximum suppression process of the Canny operator;
[0018] The gradient calculation process adopts the Scharr template, and adds detection templates in the directions of 45° and 135°;
[0019] The non-maximum suppression process adopts a non-maximum suppression method based on interpolation to refine the extracted edges and suppress possible non-edge pixels. By linear interpolation, two more diagonals are added based on the two diagonals (0°, 90°) and (45°, 135°) through the following formula, so that the original four-directional gradient suppression is changed to eight-directional gradient suppression:
[0020]
[0021]
[0022] Among them, P(x, y) is the gradient amplitude calculation, θ(x, y) is the gradient direction calculation formula, P x (x, y) and P y (x, y) are the components of the image pixel in the x and y directions respectively.
[0023] Preferably, the workflow of the compensation link includes:
[0024] The Zernike moment sub-pixel edge extraction algorithm is used to construct a Zernike parameter matrix, and the Zernike parameters are compensated by using the error compensation parameters set by the third-order grayscale edge model to obtain the compensated edge pixel coordinates, thereby improving the edge vector accuracy.
[0025] Compared with the prior art, the present invention has the following beneficial effects:
[0026] Through the strategy proposed in the present invention, the extracted tool image information is more accurate, so that when using a low-resolution camera, the image processing speed and processing accuracy are improved, thereby achieving efficient visual size detection.
[0027] Compared with the traditional Canny and Zernike algorithms, with the help of this algorithm, the tool size detection system can obtain image edge information with higher detection efficiency and higher accuracy. Experiments show that the tool size error detected by this algorithm can be stabilized below 0.01mm, achieving micron-level detection accuracy, which meets the needs of high-precision tool detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0029] Figure 1 A schematic diagram of a method flow of an embodiment of the present invention;
[0030] Figure 2 Schematic diagram of gradient interpolation of an embodiment of the present invention, wherein (a) is interpolation from 45° to 90°, (b) is interpolation from 90° to 135°, (c) is interpolation from 135° to 180°, and (d) is interpolation from 315° to 360°;
[0031] Figure 3 Schematic diagram of edge model of an embodiment of the present invention, wherein (a) is a Zernike edge model, and (b) is a rotated Zernike edge model;
[0032] Figure 4 It is the third-order true edge model of the embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0035] In this embodiment, if Figure 1 As shown, a tool edge detection method for an intelligent tool adjuster includes: an image acquisition link, an edge extraction link and a compensation link.
[0036] The image acquisition link is used to collect tool images and pre-process the tool images to obtain processed images.
[0037] The image acquisition process includes the image acquisition process and the image preprocessing process; the image acquisition process uses an industrial camera to shoot the tool to obtain the tool image; the image preprocessing process uses a guided filtering algorithm to preprocess the tool image to obtain the processed image.
[0038] Traditional Gaussian filtering is not enough to ensure that the processed image has a sufficiently clear image edge, while bilateral filtering, which can effectively retain the image edge, has the problem of image edge gradient flipping, that is, when the image edge is too sharp, it will cause a second "edge" to appear around the edge. Therefore, this embodiment uses guided filtering to replace the original Gaussian filtering to preprocess the grayscale image collected by the device. The preprocessing process includes:
[0039] O i =a k G i +b k ,i∈w k
[0040] Among them, O is the output image, G is the guide image, w is the window size, k is the position of each pixel in the window itself, i is the pixel position corresponding to the pixel position in the window, and a and b are:
[0041]
[0042] Among them, I is the input image, cov and var are image covariance and variance operations respectively, and are the pixel grayscale mean of the input image and the guide image respectively. After the image to be processed is input as both the guide image and the input image, an image with reduced noise and enhanced edge effect can be generated.
[0043] The edge extraction stage extracts the edge of the preprocessed image based on the Canny operator to obtain the edge vector.
[0044] In order to capture weaker edge gradient information in the image, this embodiment replaces the two-direction Sobel template used in the traditional Canny algorithm with a four-direction Scharr template that has stronger differential capability and can detect more directions. That is, in addition to the traditional x and y axis basis, detection templates in the directions of 45° and 135° are added. The template is shown in the following formula:
[0045]
[0046]
[0047] In order to reduce the number of edges after gradient calculation, the Canny algorithm introduces non-maximum suppression to refine the extracted edges and suppress possible non-edge pixels. The traditional Canny operator mainly calculates the gradient difference in four directions: 0°, 45°, 90°, and 135°. In order to be able to judge the gradient difference of pixels at a finer granularity, thereby reducing the problem of edge points being mistaken for non-edge points and suppressed, this paper proposes a non-maximum suppression method based on interpolation. Through the linear interpolation method, two more diagonals are added on the basis of the two diagonals (0°, 90°) and (45°, 135°) through the following formula, thereby changing the original four-direction gradient suppression into eight-direction gradient suppression.
[0048]
[0049]
[0050] Among them, Py(x, y) is the gradient amplitude calculation, θ(x, y) is the gradient direction calculation formula, P x (x, y) and P y (x, y) are the components of the image pixel in the x and y directions respectively.
[0051] After determining the eight-directional gradients of the pixel point, it is necessary to compare the gradient amplitude of each pixel point with the corresponding values of the surrounding pixels: if the gradient amplitude of the point is greater than the gradient amplitude of its neighboring pixels, the gradient of the pixel point is retained; otherwise, the corresponding gradient of the pixel point is set to 0 to suppress the pixel, ultimately achieving the purpose of thinning the edge.
[0052] The specific interpolation method and P x (x, y) and Py The size relationship of (x, y) is related to:
[0053] (1) When P x (x, y) <P y When (x, y), the gradient of the central pixel point P determines the positions of points P1, P2, P3 and P4, as shown in the following figure. Figure 2 As shown in (a) and (b), the following formula is used to determine the interpolation gradients d1 and d2 and to match the points P1, P2, P3 and P4 to perform maximum value suppression.
[0054]
[0055] (2) When P x (x, y)>P y (x, y), the central pixel point P is specifically expressed as follows Figure 2 As shown in (c) and (d), the following formula is used to determine the interpolation gradient for non-maximum suppression.
[0056]
[0057] The compensation stage compensates the edge vector at the sub-pixel level based on the Zernike moment to improve the edge vector accuracy and obtain the tool recognition result.
[0058] The traditional Zernike moment sub-pixel edge extraction algorithm is used to calculate the edge vector and extract the Zernike parameters. The Zernike parameter matrix is constructed, and the Zernike parameters are compensated by the pre-set error compensation parameters to obtain the final Zernike parameters, thereby obtaining the compensated edge pixel coordinates and improving the edge vector accuracy.
[0059] In this embodiment, the theoretical basis of the Zernike moment sub-pixel edge extraction algorithm is a second-order edge model of grayscale, which is used to represent the foreground, background and edge. The specific form is an edge model containing four parameters k, h, l and Θ, such as Figure 3 (a) is shown. In a unit circle, h represents the background grayscale value, k represents the grayscale difference between the foreground and the background, Θ represents the angle between the edge and the x-axis coordinate, and l represents the distance from the origin of the coordinate to the vertical line of the edge. Since the above parameters are all mathematically expressed, they can be accurate to decimal positions, thereby achieving sub-pixel edge positioning capabilities. In the unit circle, the nth order and mth order Zernike moment of a discrete image can be defined as:
[0060]
[0061] in, represents the normalization formula, * represents the convolution operation, Denotes the integral kernel function V n,m The conjugate complex number of (ρ, θ) with V 0,0 =1, V 1,1 =x+iy、V 2,0 =2x 2 +2y 2 -1, i is the imaginary number symbol, and f(x, y) is the rectangular coordinate formula.
[0062] Due to the rotation invariance of the Zernike moment, the Zernike moment can be transformed to obtain:
[0063]
[0064] Among them, Z′ 0,0 , Z′ 1,1 and Z′ 2,0 is the moment formula after rotation of θ degrees, and the rotated image is symmetric about the x-axis, so we have:
[0065] Im[Z′ 1,1 ]=sinθRe[Z 1,1 ]-cosθIm[Z 1,1 ]=0
[0066] Among them, Zn[Z′ 1,1 ] represents Z′ 1,1 The real part of Re[Z 1,1 ] represents Z 1,1 The imaginary part of . From the above formula, we can get:
[0067]
[0068] Combination Figure 3 (b) It can be further deduced that:
[0069]
[0070] The above equation can be used to find Figure 3 The corresponding relationship between the four parameters shown and the above three moments is:
[0071]
[0072] In the discrete case, the moment can represent the convolution of the template and the grayscale image. Considering the template effect, if the unit circle is used for sampling, in the N×N pixel area, when the template moves on the image for convolution, the template covers the N pixels around its center. 2 pixels, the unit radius becomes Therefore, it is necessary to enlarge the vertical distance l calculated on the unit circle times. That is, the corrected pixel edge position is:
[0073]
[0074] Among them, N is the template size, (x, y) is the coordinate of the center of the unit circle, (x s ,y s ) is the corrected image sub-pixel edge coordinate. Obviously, the size of the template will directly affect the accuracy of edge detection. The larger the template, the higher the detection accuracy, but its operating efficiency will be lower. Currently, the commonly used template size for Zernike moment is 7×7.
[0075] From the above analysis, it can be seen that the Zernike moment is a sub-pixel edge detection algorithm based on the second-order edge model. However, in actual situations, the grayscale edges of images acquired by the CCD sensor are often multiple layers, and the real edges are hidden in these multiple layers of grayscale. In order to accurately find the real edges, it is necessary to compensate the errors of the Zernike model. This embodiment compensates the results of Zernike sub-pixel positioning based on the third-order grayscale edge model to obtain higher recognition accuracy.
[0076] The third-order true marginal model is Figure 4 As shown in the figure, based on the second-order edge model, the image grayscale is divided into foreground and background and the grayscale value h+Δk between the foreground and background is introduced. At this time, the distance l from the center point to the edge will be divided into l1 and l2, and the corresponding grayscales are Δk and k. The real edge is between l1 and l2. If l is used R Represents the distance from the center point to the real edge. According to the linear relationship of the ideal edge, the following equation exists. According to the corresponding relationship between the above four parameters and the three moments, the relationship between Δk, k, l1 and l2 can be calculated as follows:
[0077]
[0078] Among them, due to It can be regarded as a constant, so it is replaced by λ. λ is a real number in the interval [0,1], so the above formula can be rewritten as:
[0079] l R =l2-λ(l2-l1)
[0080] According to the corresponding relationship between the above four parameters and the three moments, we can get the l parameter as l T , then:
[0081]
[0082] Where Z 2,0 and Z′ 1,1 is the Zernike moment under the third-order model, we have:
[0083]
[0084]
[0085] Solve the above equation and enter l T We can get:
[0086]
[0087] That is, we can find l under the third-order model T With l R The error is:
[0088]
[0089] From the above formula, we can see that when λ=1 or λ=0, E=0, that is, at this time l R = l T , to obtain the ideal edge.
[0090] When λ is a real number (0,1), the compensation link can achieve error correction for the Zernike edge detection algorithm through the following steps:
[0091] The traditional Zernike formula is used to solve the related parameters of the located edge points. According to the pixel parameters, appropriate l1 and l2 are selected, and the corresponding k and Δk are obtained to obtain λ and calculate the error E. According to the error E and the calculated l T Compensation is performed to obtain the final l R , thus improving the edge vector accuracy.
[0092] The embodiments described above are only descriptions of the preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made to the technical solutions of the present invention by ordinary technicians in this field should all fall within the protection scope determined by the claims of the present invention.
Claims
1. A tool edge detection method for an intelligent tool adjuster, It is characterized in that include: Image acquisition, edge extraction and compensation; The image acquisition link is used to acquire a tool image and pre-process the tool image to obtain a processed image; The edge extraction step uses an improved Canny operator to extract edges from the processed image to obtain edge vectors; The compensation link performs sub-pixel level compensation on the edge vector based on the Zernike moment to improve the edge vector accuracy and obtain a tool edge detection result; The edge extraction link adopts an improved Canny operator, including improvements to the gradient calculation process and non-maximum suppression process of the Canny operator; The gradient calculation process adopts the Scharr template, and adds detection templates in the directions of 45° and 135°; The non-maximum suppression process adopts a non-maximum suppression method based on interpolation to refine the extracted edges and suppress the non-edge pixels therein. By linear interpolation, two more diagonal lines are added based on the two diagonal lines (0°, 90°) and (45°, 135°) by the following formula, so that the original four-directional gradient suppression is changed to eight-directional gradient suppression: Among them, P(x, y) is the gradient amplitude calculation, θ(x, y) is the gradient direction calculation formula, P x (x, y) and P y (x, y) are the components of the image pixel in the x and y directions respectively; The linear interpolation and P x (x, y) and P y The size relationship of (x, y) is related to: (1) When P x (x, y) <P y (x, y), the gradient of the central pixel P determines the point P 1 , P 2 , P 3 and P 4 At the four-point position, the following formula is used to determine the interpolation gradient d 1 ,d 2 With P 1 , P 2 , P 3 and P 4 Point to perform maximum suppression: (2) When P x (x, y)>P y When (x, y), the following formula is used to determine the interpolation gradient for non-maximum suppression; The workflow of the compensation link includes: Using the Zernike moment sub-pixel edge extraction algorithm, a Zernike parameter matrix is constructed, and the Zernike parameters are compensated by using the error compensation parameters set by the third-order grayscale edge model, so as to obtain the coordinates of the compensated edge pixel points and improve the accuracy of the edge vector; The Zernike moment sub-pixel edge extraction algorithm is an edge model containing four parameters: k, h, l and Θ. In a unit circle, h represents the background gray value, k represents the gray difference between the foreground and the background, Θ represents the angle between the edge and the x-axis coordinate, and l represents the distance from the origin of the coordinate to the vertical line of the edge. In the unit circle, the Zernike moment of the nth order and mth order of a discrete image can be defined as: in, represents the normalization formula, * represents the convolution operation, Denotes the integral kernel function V n,m The conjugate complex number of (ρ, θ) with V 0,0 =1, V 1,1 =x+iy、V 2,0 =2x 2 +2y 2 -1, i is the imaginary number symbol, f(x, y) is the rectangular coordinate formula; Due to the rotation invariance of the Zernike moment, the Zernike moment can be transformed to obtain: Among them, Z′ 0,0 , Z′ 1,1 and Z′ 2,0 is the moment formula after rotation of θ degrees, and the rotated image is symmetric about the x-axis, so we have: Im[Z′ 1,1 ]=sinθRe[Z 1,1 ]-cos θIm[Z 1,1 ]=0 Among them, Im[Z′ 1,1 ] represents Z′ 1,1 The real part of Re[Z 1,1 ] represents Z 1,1 The imaginary part of ; From the above formula we can get: It can be further deduced that: The above equations can be used to find the four parameters k, h, l and Θ and Z′ 0,0 , Z′ 1,1 and Z′ 2,0 The corresponding relationship between the three moments is: In the discrete case, the moment can represent the convolution of the template and the grayscale image. Considering the template effect, the unit circle is used for sampling. In the N×N pixel area, when the template moves on the image for convolution, the template covers the N pixels around its center. 2 pixels, the unit radius becomes Then enlarge the vertical distance l calculated on the unit circle times, that is, the corrected pixel edge position is: Among them, N is the template size, (x, y) is the coordinate of the center of the unit circle, (x s ,y s ) is the corrected image sub-pixel edge coordinate; Based on the third-order grayscale edge model, the result of Zernike sub-pixel positioning is compensated to obtain higher recognition accuracy: Based on the second-order edge model, the image grayscale is divided into foreground and background and the grayscale value h+Δk between the foreground and background is introduced; at this time, the distance l from the center point to the edge will be divided into l 1 and l 2 , the corresponding grayscale is Δk and k, where the real edge is at l 1 With l 2 If you use l R represents the distance from the center point to the real edge. According to the linear relationship of the ideal edge, the following equation exists. According to the corresponding relationship between the above four parameters and the three moments, Δk, k, l can be calculated. 1 With l 2 The relationship between them is as follows: Among them, due to It can be regarded as a constant, so it is replaced by λ, where λ is a real number in the interval [0,1]. The above formula can be rewritten as: L R l 2 -λ(l 2 -L 1 ) According to the four parameters k, h, l and Θ and Z′ 0,0 , Z′ 1,1 and Z′ 2,0 The corresponding relationship between the three moments can be obtained and set as l T , then: Where Z 2,0 and Z′ 1,1 is the Zernike moment under the third-order model, we have: Solve the above equation and enter l T We can get: That is, we can find l under the third-order model T With l R The error is: From the above formula, we can see that when λ=1 or λ=0, E=0, that is, at this time l R = l T , to obtain the ideal edge.
2. According to the tool edge detection method for an intelligent tool adjuster according to claim 1, It is characterized in that The image acquisition process includes: image acquisition process and image preprocessing process; The image acquisition process uses an industrial camera to photograph the tool to obtain the tool image; The image preprocessing process uses a guided filtering algorithm to preprocess the tool image to obtain the processed image.
3. According to the tool edge detection method for an intelligent tool adjuster as described in claim 2, It is characterized in that The image preprocessing process includes: O i =a j ·G i +b j ,i∈ω j Among them, O is the output image, G is the guide image, ω is the window size, j is the position of each pixel in the window itself, i is the pixel position corresponding to the pixel position in the window, and a and b are: Among them, I is the input image, cov and var are image covariance and variance operations respectively, and are the pixel grayscale means of the input image and the guide image respectively.
