Position measurement method and device based on differential search algorithm

Through the positioning measurement method based on the differential search algorithm, the image processing operation is simplified, parameter settings are reduced, robustness and efficiency are improved, and high-accuracy positioning measurement of straight lines and circles on the workpiece is achieved.

CN114943702BActive Publication Date: 2025-06-13SHENZHEN SHIZONG AUTOMATION EQUIP CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210563603.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-23
Publication Date
2025-06-13
Estimated Expiration
2042-05-23

AI Technical Summary

Technical Problem

When performing visual positioning and appearance dimension measurement, multiple image processing operations are required, such as filtering, binarization, corrosion, expansion and edge detection, resulting in a wide variety of parameters and reducing the robustness of positioning detection.

Method used

The positioning measurement method based on the differential search algorithm is adopted. By obtaining the workpiece target image collected by the visual camera, intercepting the area of ​​interest, selecting the appropriate search strategy based on the direction and background state of the straight line or circle for differential search, obtaining the target point, and fitting it into a straight line or circle, and outputting relevant parameters.

Benefits of technology

This reduces the complex operation and parameter settings of image processing, improves the robustness and efficiency of the algorithm, and realizes high-accuracy positioning measurement of straight lines and circles on the workpiece.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114943702B_ABST
    Figure CN114943702B_ABST
Patent Text Reader

Abstract

The present invention discloses a positioning measurement method and device based on a differential search algorithm. The method includes: acquiring a target image of a workpiece to be detected collected by a vision camera, and reading the target image in grayscale format; intercepting an ROI region image in the target image; selecting a predetermined search strategy for differential search according to the state of a straight line or a circle in the ROI region image to obtain a plurality of target points; fitting the plurality of target points obtained by the search into a target straight line or a circle, and outputting the parameters of the straight line or the circle. According to the positioning measurement method and device based on the differential search algorithm provided by the embodiments of the present invention, the positioning measurement of a straight line or a circle on the workpiece to be measured is realized based on the straight line and circle finding of the differential search algorithm. Compared with the traditional image processing algorithm, the processing procedures such as binarization, erosion or dilation, and edge detection are reduced, and accordingly, the setting of multiple parameters is also reduced, improving the robustness of the algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of visual positioning, and particularly to a positioning measurement method and device based on a differential search algorithm. Background Art

[0002] The technology of positioning a workpiece to be detected and measuring its related appearance dimensions based on machine vision has been widely applied in automated equipment such as AOI, welding, bonding, and dispensing. Among them, searching for straight lines and circles on the workpiece image is a key process for positioning and appearance measurement. By detecting the straight lines where the edges of the workpiece are located through image processing technology, and then calculating the distances or intersections between the straight lines, information such as the appearance dimensions of the workpiece can be obtained. By detecting the center positions and radii of circles on some workpieces, the position of the workpiece on the fixture of the automated equipment can be located, providing important position information for subsequent processes such as bonding, welding, or dispensing.

[0003] In the related technology, the main straight line search technology needs to first perform operations such as filtering, binarization, erosion, or dilation on the image. In some application scenarios, edge detection technologies such as Sobel or Canny are also required to further highlight the characteristics of the straight lines, and then the Hough transform is used to find the straight lines on the image. Similarly, for the technology of searching for circles, a series of operations such as filtering, binarization, and edge detection are also required, and then the Hough transform is used to find the circles on the image. The main disadvantages of these technologies are that there are too many setting parameters involved. For example, for the setting of the binarization threshold, although there are currently adaptive binarization based on local thresholds, and OTSU and maximum entropy binarization technologies based on global thresholds that do not require setting fixed thresholds, these algorithms are often only applicable to certain specific scenarios. In addition, erosion, dilation, and edge detection also involve the setting of a series of parameters. Moreover, the Hough transform itself also requires setting multiple parameters. For example, when finding circles, parameters such as the maximum and minimum radii of the circles, the distance between the centers of the circles, and the accumulator threshold of the centers need to be set. The setting of more parameters reduces the robustness of the positioning detection technology. Summary of the Invention

[0004] The present invention aims to solve at least one of the technical problems in the related technology to some extent. For this purpose, the object of the present invention is to provide a positioning measurement method and device based on a differential search algorithm.

[0005] To achieve the above object, in a first aspect, according to an embodiment of the present invention, a positioning measurement method based on a differential search algorithm, which is suitable for straight line positioning measurement, includes:

[0006] Obtain a target image of the workpiece to be detected collected by a vision camera, and read the target image in grayscale format;

[0007] Intercept the ROI region image in the target image;

[0008] Select a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image to obtain multiple target points;

[0009] Fit the multiple obtained target points into a target straight line and output the slope value and offset value of the straight line.

[0010] Second, the positioning measurement method based on the differential search algorithm according to the embodiment of the present invention is suitable for circle positioning measurement, including:

[0011] Obtain the target image of the workpiece to be detected collected by the vision camera and read the target image in grayscale format;

[0012] Intercept the ROI region image in the target image;

[0013] Select a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image to obtain multiple target points;

[0014] Fit the multiple obtained target points into a target circle and output the circular coordinates and radius of the circle.

[0015] Third, the positioning measurement device based on the differential search algorithm according to the embodiment of the present invention is suitable for straight line positioning measurement, and is characterized by including:

[0016] An acquisition unit for acquiring the target image of the workpiece to be detected collected by the vision camera and reading the target image in grayscale format;

[0017] An interception unit for intercepting the ROI region image in the target image;

[0018] A differential search unit for selecting a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image to obtain multiple target points;

[0019] A fitting unit for fitting the multiple obtained target points into a target straight line and outputting the slope value and offset value of the straight line.

[0020] Fourth, the positioning measurement device based on the differential search algorithm according to the embodiment of the present invention is suitable for circle positioning measurement, including:

[0021] An acquisition unit for acquiring the target image of the workpiece to be detected collected by the vision camera and reading the target image in grayscale format;

[0022] An interception unit for intercepting the ROI region image in the target image;

[0023] The differential search unit selects a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image to obtain multiple target points;

[0024] The fitting unit is used to fit the multiple obtained target points into a target circle and output the circular coordinates and radius of the circle.

[0025] According to the positioning measurement method and device based on the differential search algorithm provided by the embodiments of the present invention, the straight line and circle based on the differential search algorithm are used to realize the positioning measurement of the straight line or circle on the workpiece to be measured. Compared with the traditional image processing algorithm, the processing procedures such as binarization, erosion or dilation, and edge detection are reduced. Correspondingly, the setting of multiple parameters is also reduced, and the robustness of the algorithm is improved.

[0026] Additional aspects and advantages of the present invention will be given in part in the following description, become apparent in part from the following description, or be understood through the practice of the present invention. Description of the Drawings

[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on the structures shown in these drawings.

[0028] Figure 1 is a flowchart of an embodiment of the positioning measurement method based on the differential search algorithm of the present invention;

[0029] Figure 2 is a flowchart of another embodiment of the positioning measurement method based on the differential search algorithm of the present invention;

[0030] Figure 3 is a schematic structural diagram of an embodiment of the positioning measurement device based on the differential search algorithm of the present invention.

[0031] The realization, functional characteristics, and advantages of the object of the present invention will be further described in conjunction with the embodiments with reference to the drawings. Detailed Embodiments

[0032] The following will describe in detail the embodiments of the present invention. The examples of the embodiments are shown in the drawings, where the same or similar reference numerals represent the same or similar elements or elements with the same or similar functions from beginning to end. The embodiments described below by referring to the drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation of the present invention.

[0033] Refer to Figure 1 as shown, Figure 1The flowchart of an embodiment of the positioning measurement method based on the differential search algorithm provided by the embodiment of the present invention is shown. For the convenience of description, only the parts related to the embodiment of the present invention are shown. Specifically, this method is suitable for positioning and measuring a straight line on a workpiece to be measured, and it includes:

[0034] S101. Obtain the target image of the workpiece to be detected collected by the vision camera, and read the target image in the format of a grayscale image. Take a picture of the workpiece to be detected through the vision camera to obtain the target image of the workpiece to be detected.

[0035] S102. Intercept the ROI region image in the target image, that is, intercept the region of interest from the target image to obtain the ROI region image, and the ROI region image contains the straight line to be detected.

[0036] S103. Select a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image to obtain multiple target points.

[0037] S104. Fit the multiple target points obtained by the search into a target straight line, and output the slope value and offset value of the straight line.

[0038] It can be understood that between step S102 and step S103, it may further include: performing filtering processing on the ROI region image. For example, performing Gaussian filtering or median filtering on the ROI region image, and the kernel size is generally 5x5. For some images with clear backgrounds, no filtering processing is required.

[0039] Step S103 may specifically include:

[0040] When the direction of the straight line in the ROI region image is close to a vertical straight line and the background part is located on the left side of the ROI region image, search according to the search strategy from left to right to obtain multiple target points; when the background part is located on the right side of the ROI region image, search according to the search strategy from right to left to obtain multiple target points.

[0041] When the direction of the straight line in the ROI region image is close to a horizontal straight line and the background part is located on the upper side of the ROI region image, search according to the search strategy from top to bottom to obtain multiple target points; when the background part is located on the lower side of the ROI region image, search according to the search strategy from bottom to top to obtain multiple target points.

[0042] When photographing the workpiece to be detected, a light source is usually used to illuminate the workpiece to be detected, and a certain background is set to highlight the position of the workpiece to be detected in the entire image. Therefore, a predetermined search strategy can be selected for differential search according to the direction of the straight line and the background state in the ROI region image. Specifically, when the direction of the straight line in the ROI region image is close to a vertical straight line and the background part is located on the left side of the ROI region image, the search is performed according to the search strategy from left to right, and when the background part is located on the right side of the ROI region image, the search is performed according to the search strategy from right to left. When the direction of the straight line in the ROI region image is close to a horizontal straight line and the background part is located on the upper side of the ROI region image, the search is performed according to the search strategy from top to bottom, and when the background part is located on the lower side of the ROI region image, the search is performed according to the search strategy from bottom to top.

[0043] The following specifically describes the above four search strategies: from left to right, from right to left, from top to bottom, and from bottom to top.

[0044] (1) The search strategy from left to right includes:

[0045] Step 1: Starting from the left edge of the ROI region image, perform a differential operation on the pixel values of each row in turn by subtracting the pixel value of the left point from the pixel value of the right point to obtain a first difference value. Take the absolute value of the first difference value and set a threshold. If the absolute value of a certain first difference value is less than the threshold, reassign it to 0.

[0046] That is, starting from the left edge of the ROI region image, perform a differential operation on the pixel values of each row of the image by subtracting the pixel value of the left point from the pixel value of the right point, such as G i,1 -G i,0 , G i,2 -G i,1 , ……, G i,n-1 -G i,n-2 , where G represents the grayscale value matrix of the image. If the width of the image is n and the height is m, the size of this matrix is n×m, and G i,1 -G i,0 represents the first grayscale value of a certain row i (0≤i≤m - 1) minus the 0th grayscale value. Then take the absolute values of these differentials, and at the same time set a threshold. If the absolute value of a certain differential is less than this threshold, reassign it to 0. This is because sometimes the straight line cannot pass through the upper and lower edges of the intercepted ROI image, and there are some smooth regions near the upper or lower edge of the image, so this part of the image is ignored in the subsequent search process.

[0047] Step 2: Sort the absolute values of the first-order difference values for each row, find the maximum value in the absolute values and its position index in that row, and set the number of search points.

[0048] That is, sort the absolute values of the first-order difference values for each row, find the position index of the maximum value in that row, and then set the number of search points. The setting of this parameter has no direct impact on the search result. Because ultimately, a straight line is fitted based on the searched points. If the number of search points is large, the fitting accuracy will be improved, and vice versa, the search speed will be increased. For example, if the height m of the ROI image is 200 and the number of search points is set to 50, then information is selected from every 4 rows from top to bottom, and finally, a straight line is fitted based on the position of the maximum value among the absolute values of the first-order difference values of these 50 rows.

[0049] Step 3: Perform second-order difference on all the searched points. In the vertical direction, subtract the X coordinate value of the next point in the image from the X coordinate value of the previous point to obtain the second-order difference value. Take the absolute value of the second-order difference value, form an array with these absolute values of the second-order difference values, and find the median Med of this array.

[0050] Since there are usually scratches, dirt, etc. on the surface of the workpiece to be detected, even if the captured image is filtered, it is possible that some points among the finally searched 50 points deviate far from other points. If these points are also included when fitting the straight line, it will seriously affect the fitting accuracy of the straight line. Therefore, these points need to be filtered out. Perform second-order difference on all the searched points. Suppose these 50 points are P1, P2, P3, ……, P50 respectively. In the vertical direction, subtract the X coordinate value of the previous point from the X coordinate value of the next point in the image, that is, P2.X - P1.X, P3.X - P2.X, ……, P50.X - P49.X. Take the absolute value of the difference value, and then form an array A with these absolute values, and find the median Med of this array.

[0051] Step 4: Divide all the absolute values in this array by the median to obtain a set of ratio values; set a ratio threshold th1. If the ratio value in this array is greater than 1 - th1 and less than 1 + th1, retain the point corresponding to this ratio value, and delete the rest; when the searched straight line is very close to the vertical straight line, the median Med of this array may be equal to 0 and cannot be used as a divisor. Then set a ratio threshold th2. If the ratio value in the array is less than or equal to th2, retain the point corresponding to this ratio value, and delete the rest.

[0052] That is to say, divide all the values in the array by the median to obtain a set of proportional values. Set a proportional threshold th1. If the proportional value in the array is greater than 1 - th1 and less than 1 + th1, retain the points corresponding to the proportional value, and delete the remaining points. For example, if abs(P2.X - P1.X) / Med > 1 + th1, then delete point P2. In some cases, when the searched straight line is very close to a vertical straight line, the median Med of the array may be equal to 0 and cannot be used as a divisor. Then set a straight line threshold th2. If the number in array A is less than or equal to th2, retain the point corresponding to the number, and delete the rest.

[0053] Step Five: For the points retained after screening, perform differencing in sequence by subtracting the X coordinate value of the previous point from the X coordinate value of the next point to obtain three differencing values, and count the number num_op of positive values and the number num_ne of negative values among these differencing values. Set a fluctuation threshold th3. If there are both positive and negative values among the differencing values, but the maximum value among the differencing values is less than th3, and at the same time the minimum value is greater than -1 * th3, retain these points as target points. If the differencing values are all positive or negative, also retain these points as target points. However, if there are both positive and negative values among the differencing values, and the maximum value or the minimum value exceeds th3, then perform the next round of screening.

[0054] In the process of deleting deviated points in the previous step, the main reference basis is the difference in the X coordinates between a certain point and its previous point. However, in some cases, if the previous point is already far from the actual straight line, and the difference in the X coordinates between this point and the previous point is within the threshold range, then both this point and the previous point are saved. Therefore, only one round of screening is not enough. For the points remaining after the first round of screening, the number may be less than 50. Subtract the X coordinate value of the previous point from the X coordinate value of the next point in sequence, and then count the number num_op of positive values and the number num_ne of negative values among these differencing values. Generally, if the points remaining after the first round of screening are all on the same straight line, then these differencing values should all be positive or negative. However, sometimes the edges of some detected workpieces are not strict straight lines but wavy lines like sawteeth, and the selected points fluctuate left and right or up and down within a certain range along the theoretical straight line. Therefore, set a fluctuation threshold th3. If there are both positive and negative values among the differencing values, but the maximum value among the differencing values is less than th3, and at the same time the minimum value is greater than -1 * th3, then these points can be used to fit a straight line. In addition, if the differencing values are all positive or negative, these points can also be used to fit a straight line. However, if there are both positive and negative values among the differencing values, and their maximum value or minimum value exceeds the threshold, then perform the next round of screening.

[0055] Step 6: Set up a while loop. If num_op * num_ne != 0, it means that both positive and negative values have always existed in the difference values, so keep looping; otherwise, break out of the loop. In the loop, if num_op >= num_ne, delete the previous point corresponding to the negative difference value; conversely, if num_op < num_ne, delete the previous point corresponding to the positive difference value. When both positive and negative values no longer appear simultaneously in the difference values, use the remaining points as target points.

[0056] That is, set up a while loop. If num_op * num_ne != 0, it means that both positive and negative values have always existed in the difference values, so keep looping; otherwise, break out of the loop. In the loop, if num_op >= num_ne, delete the previous point corresponding to the negative difference value. For example, if P2.X - P1.X < 0, then delete point P1. This is different from the first screening. In the first screening, the previous point was referred to, while here the next point is referred to, which can avoid the deviation of the entire straight line due to problems with the previous points. Conversely, if num_op < num_ne, delete the previous point corresponding to the positive difference value. When both positive and negative values no longer appear simultaneously in the difference values, use the remaining points to fit a straight line.

[0057] (2) The search strategy from right to left includes:

[0058] Step 1: Start from the right edge of the ROI region image, perform a difference operation on the pixel values of each row in turn by subtracting the pixel value of the right point from the pixel value of the left point to obtain the first difference value. Take the absolute value of the first difference value and set a threshold. If the absolute value of a certain first difference value is less than the threshold, reassign it to 0.

[0059] That is, start from the right edge of the image and perform a difference operation on the pixel values of each row of the image in turn by subtracting the pixel value of the right point from the pixel value of the left point, such as G i,n-2 -G i,n-1 ,G i,n-3 -G i,n-2 ,……,G i,0 -G i,1 ,where G represents the gray value matrix of the image, n is the width of the image, m is the height of the image, and G i,n-2 -G i,n-1 represents subtracting the 0th gray value from the 1st gray value starting from the left in a certain row i (0 ≤ i ≤ m - 1). The subsequent operations are the same as the other operations in Step 1 of the left-to-right strategy.

[0060] Step 2: Sort the absolute values of the first-order difference values for each row, find the maximum value among the absolute values, obtain the index value at the position in that row, subtract this index value from the width n of the ROI region image, and then set the number of search points.

[0061] That is, sort the absolute differences of each row, find the position index of the maximum value in that row, and then subtract this index value from the image width n, because the points used to fit the line are still referenced from the left edge of the image in the horizontal direction. The remaining operations are the same as other operations in Step 2 of the left-to-right strategy.

[0062] Step 3: Perform second-order differences on all the searched points. In the vertical direction, subtract the X coordinate value of the previous point in the image from the X coordinate value of the next point to obtain the second-order difference value. Take the absolute value of the second-order difference value, form an array of these absolute values of the second-order difference values, and find the median Med of this array.

[0063] Step 4: Divide all the absolute values in this array by the median to obtain a set of ratio values. Set the ratio threshold th1. If the ratio value in this array is greater than 1 - th1 and less than 1 + th1, retain the points corresponding to this ratio value, and delete the rest; when the searched line is very close to a vertical line, the median Med of this array may be equal to 0 and cannot be used as a divisor. Then set the ratio threshold th2. If the ratio value in the array is less than or equal to th2, retain the points corresponding to this ratio value, and delete the rest.

[0064] Step 5: For the points retained after screening, perform differences in turn by subtracting the X coordinate value of the previous point from the X coordinate value of the next point to obtain the third-order difference values, and count the number num_op of positive values and the number num_ne of negative values among these difference values; set the fluctuation threshold th3. If there are both positive and negative values in the difference values, but the maximum value of the difference values is less than th3 and the minimum value is greater than -1 * th3, retain these points as target points. If the difference values are all positive or negative, also retain these points as target points. However, if there are both positive and negative values in the difference values and the maximum value or the minimum value exceeds th3, perform the next round of screening.

[0065] Step 6: Set a while loop. If num_op * num_ne!= 0, it means that there are always both positive and negative values in the difference values, and then keep looping, otherwise jump out of the loop. In the loop, if num_op ≥ num_ne, delete the previous point corresponding to the negative difference value; conversely, if num_op < num_ne, delete the previous point corresponding to the positive difference value. When there are no longer both positive and negative values in the difference values, take the remaining points as target points.

[0066] In this strategy, the operations in steps three, four, five, and six are the same as the relevant steps of the left-to-right strategy.

[0067] (3) The top-to-bottom search strategy includes:

[0068] Step 1: Starting from the upper edge of the ROI region image, perform a first-order difference on the pixel values of each column in turn by subtracting the pixel value of the upper point from the pixel value of the lower point to obtain the first-order difference value. Take the absolute value of the first-order difference value, and set a threshold. If the absolute value of a certain first-order difference value is less than the threshold, reassign it to 0.

[0069] That is, starting from the upper edge of the image, perform a first-order difference on the pixel values of each column in turn by subtracting the pixel value of the upper point from the pixel value of the lower point, such as G 1,j -G 0,j , G 2,j -G 1,j , ……, G m-1,j -G m-2,j , where G represents the gray value matrix of the image, n is the width of the image, m is the height of the image, G 1,j -G 0,j represents the first gray value minus the 0th gray value in a certain column j (0 ≤ j ≤ n - 1) starting from the upper edge. Then take the absolute values of these differences, and at the same time set a threshold. If the absolute value of a certain difference is less than the threshold, reassign it to 0. This is because sometimes the straight line cannot pass through the left and right edges of the intercepted ROI image, and there are some smooth regions near the left or right edge of the image, so this part of the image is ignored in the subsequent search process.

[0070] Step 2: Sort the absolute values of the first-order difference values of each column, find the position index of the maximum value in the absolute values, and set the number of search points.

[0071] That is, sort the absolute values of the first-order differences of each column and find the position index of the maximum value in that column. Then set the number of search points. Suppose the width n of the image is 200 and the number of search points is set to 50. Then, select the information of 1 column from every 4 columns from left to right, and finally fit the straight line according to the position of the maximum value of the absolute difference in these 50 columns.

[0072] Step 3: Perform a second-order difference on all the searched points. In the horizontal direction, subtract the Y coordinate value of the left point in the image from the Y coordinate value of the right point to obtain the second-order difference value. Take the absolute value of the second-order difference value, form an array with these absolute values of the second-order difference values, and find the median Med of the array.

[0073] That is to say, after the first screening, perform second-order difference on all the searched points. Assume these 50 points are P1, P2, P3, ……, P50 respectively. In the horizontal direction, subtract the Y coordinate value of the left point from the Y coordinate value of the right point in the image, that is, P2.Y - P1.Y, P3.Y - P2.Y, ……, P50.Y - P49.Y. Take the absolute value of this difference, and then form an array A with these absolute values. Find the median Med of this array.

[0074] Step 4: Divide all the absolute values in this array by the median to obtain a set of ratio values; set a ratio threshold th1. If the ratio value in this array is greater than 1 - th1 and less than 1 + th1, retain the point corresponding to this ratio value, and delete the rest of the points. When the searched line is very close to the horizontal line, the median Med of this array may be equal to 0 and cannot be used as a divisor. Then set a ratio threshold th2. If the ratio value in the array is less than or equal to th2, retain the point corresponding to this ratio value, and delete the rest.

[0075] That is to say, divide all the values in this array by the median to obtain a set of ratio values. Set a ratio threshold th1. If the ratio value in the array is greater than 1 - th1 and less than 1 + th1, retain the point corresponding to this ratio value, and delete the rest of the points. For example, if abs(P2.Y - P1.Y) / Med > 1 + th1, then delete point P2. Similar to the case of the vertical line, when the searched line is very close to the horizontal line, the median Med of this array may be equal to 0 and cannot be used as a divisor. Then set a line threshold th2. If the number in array A is less than or equal to th2, retain the point corresponding to this number, and delete the rest.

[0076] Step 5: For the points retained after screening, perform third-order difference by subtracting the Y coordinate value of the left point from the Y coordinate value of the right point in sequence to obtain third-order difference values, and count the number num_op of positive values and the number num_ne of negative values among these difference values. Set a fluctuation threshold th3. If there are both positive and negative values in the difference values, but the maximum value of the difference values is less than th3 and the minimum value is greater than -1*th3, retain these points as target points. If the difference values are all positive or all negative, also retain these points as target points. However, if there are both positive and negative values in the difference values and the maximum value or the minimum value exceeds th3, perform the next round of screening.

[0077] This step is similar to Step 5 in the left-to-right strategy. For the points remaining after the first screening, subtract the Y coordinate value of the left point from the Y coordinate value of the right point in sequence, then count the number of positive values num_op and the number of negative values num_ne among these difference values, and set the fluctuation threshold th3. If there are both positive and negative values among the difference values, but the maximum value among the difference values is less than th3 and the minimum value is greater than -1*th3, then these points can be used to fit a straight line. In addition, if the difference values are all positive or all negative, then these points can also be used to fit a straight line. However, if there are both positive and negative values among the difference values and their maximum or minimum value exceeds the threshold, then proceed to the next round of screening.

[0078] Step 6: Set a while loop. If num_op * num_ne!= 0, it means that there are always both positive and negative values among the difference values, then keep looping; otherwise, jump out of the loop. In the loop, if num_op ≥ num_ne, then delete the previous point corresponding to the negative difference value; conversely, if num_op < num_ne, then delete the previous point corresponding to the positive difference value. When there are no longer both positive and negative values among the difference values, then use the remaining points as target points.

[0079] That is, set a while loop. If num_op * num_ne!= 0, then enter the loop. If num_op ≥ num_ne, then delete the previous point corresponding to the negative difference value. For example, if P2.Y - P1.Y < 0, then delete point P1. Conversely, if num_op < num_ne, then delete the previous point corresponding to the positive difference value. When there are no longer both positive and negative values among the difference values, then use the remaining points to fit a straight line.

[0080] (4) The bottom-up search strategy described above includes:

[0081] Step 1: Starting from the lower edge of the ROI region image, perform a difference operation on the pixel values of each column in sequence by subtracting the pixel value of the upper point from the pixel value of the lower point to obtain the first difference value. Take the absolute value of the first difference value and set a threshold. If the absolute value of a certain first difference value is less than the threshold, then reassign it to 0.

[0082] That is, starting from the lower edge of the image, perform a difference operation on the pixel values of each column in the image by subtracting the pixel value of the upper point from the pixel value of the lower point, such as G m-2,j -G m-1,j ,G m-3,j -G m-3,j ,……,G 0,j -G 1,j ,where G represents the gray value matrix of the image, n is the width of the image, m is the height of the image, Gm-2,j -G m-1,j It represents the subtraction of the 0th grayscale value from the 1st grayscale value starting from the lower edge of a certain column j (0 ≤ j ≤ n - 1). The subsequent operations are the same as those in Step 1 of the top-down strategy.

[0083] Step 2: Sort the absolute values of the first-order difference values for each column, find the maximum value among the absolute values, obtain the index value of the position in this row, subtract this index value from the width n of the ROI region image, and then set the number of search points.

[0084] That is, sort the absolute differences of each column, find the position index of the maximum value in this column. Then subtract this index value from the image height m because the points ultimately used to fit the line are based on the upper edge of the image as the reference starting point in the vertical direction. The subsequent operations are the same as those in Step 2 of the top-down strategy.

[0085] Step 3: Perform a second-order difference on all the searched points. In the horizontal direction, subtract the Y coordinate value of the left point in the image from the Y coordinate value of the right point to obtain the second-order difference value. Take the absolute value of the second-order difference value, form an array with these absolute values of the second-order difference values, and find the median Med of this array.

[0086] Step 4: Divide all the absolute values in this array by the median to obtain a set of ratio values; set a ratio threshold th1. If the ratio value in this array is greater than 1 - th1 and less than 1 + th1, retain the points corresponding to this ratio value, and delete the rest; when the searched line is very close to a horizontal line, the median Med of this array may be equal to 0 and cannot be used as a divisor. Then set a ratio threshold th2. If the ratio value in the array is less than or equal to th2, retain the points corresponding to this ratio value, and delete the rest.

[0087] Step 5: For the points retained after screening, perform a difference in sequence by subtracting the Y coordinate value of the left point from the Y coordinate value of the right point to obtain the third-order difference value, and count the number num_op of positive values and the number num_ne of negative values among these difference values. Set a fluctuation threshold th3. If there are both positive and negative values in the difference values, but the maximum value of the difference values is less than th3 and the minimum value is greater than -1 * th3, retain these points as target points. If the difference values are all positive or negative, also retain these points as target points. However, if there are both positive and negative values in the difference values and the maximum value or the minimum value exceeds th3, perform the next round of screening.

[0088] Step 6. Set a while loop. If num_op * num_ne != 0, it indicates that there are always both positive and negative values in the difference values, and the loop continues; otherwise, the loop is exited. In the loop, if num_op >= num_ne, delete the previous point corresponding to the negative difference value; conversely, if num_op < num_ne, delete the previous point corresponding to the positive difference value. When there are no longer both positive and negative values in the difference values, the remaining points are used as target points.

[0089] In this strategy, the operations in Steps 3, 4, 5, and 6 are the same as the relevant steps of the top-down strategy.

[0090] In some embodiments of the present invention, Step S104 includes:

[0091] Find two parameters of the straight line, the slope K and the offset B, by the least squares method, as shown in Equation (1), where x i is the X coordinate value of the i-th point among the finally searched N points on the image, and y i is its Y coordinate value. Use Equation (1) to take partial derivatives of K and B respectively, obtain the partial derivative equations, and make them equal to 0 to solve for K and B:

[0092]

[0093] According to the positioning measurement method and device based on the differential search algorithm provided by the embodiments of the present invention, the straight line and circle based on the differential search algorithm are used to realize the positioning measurement of the straight line on the workpiece to be measured. Compared with the traditional image processing algorithm, the binarization, erosion or dilation, edge detection and other processing processes are reduced, and accordingly, the setting of multiple parameters is also reduced, improving the robustness of the algorithm.

[0094] Refer to Figure 2 as shown Figure 2 shows a flowchart of another embodiment of the positioning measurement method based on the differential search algorithm provided by the embodiments of the present invention. For the sake of description, only the parts related to the embodiments of the present invention are shown. Specifically, this method is suitable for positioning and measuring the circle on the workpiece to be measured, and it includes:

[0095] S201. Obtain the target image of the workpiece to be detected collected by the vision camera, and read the target image in grayscale format. Take a picture of the workpiece to be detected through the vision camera to obtain the target image of the workpiece to be detected.

[0096] S202. Intercept the ROI region image in the target image. That is, intercept the region of interest from the target image to obtain the ROI region image, and the ROI region image contains the circle to be detected.

[0097] S203. Select a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image to obtain multiple target points.

[0098] S204. Fit the multiple target points obtained by the search into a target circle, and output the circular coordinates and radius of the circle.

[0099] It can be understood that between step S202 and step S203, it may also include: performing filtering processing on the ROI region image. For example, performing Gaussian filtering or median filtering on the ROI region image, and the kernel size is generally 5x5. For some images with clear backgrounds, no filtering processing is required.

[0100] Step S103 may specifically include: when the circle in the ROI region image is in a complete state, perform simultaneously according to four search strategies from left to right, from right to left, from top to bottom, and from bottom to top; when the circle in the ROI region image is in a partially missing state, close the search strategy on the side where the missing part is located.

[0101] Finding the circle in the image based on the differential search algorithm also includes four strategies from left to right, from right to left, from top to bottom, and from bottom to top, and at the same time setting the search size ratio r and the number of points num for each strategy. This is because sometimes the circles on some workpieces to be detected are not complete circles, but only partial arc curves, so only need to search from one or two directions. If the circle is complete, four strategies need to be performed simultaneously for the search.

[0102] The following specifically describes the above four search strategies from left to right, from right to left, from top to bottom, and from bottom to top.

[0103] (1) The search strategy from left to right includes:

[0104] Step 1. Set the proportional size r1 of the search direction, perform a differential operation on the pixel values of each row of the ROI region image in turn according to the pixel value of the right point minus the pixel value of the left point to obtain a first differential value, and take the absolute value of the first differential value; create an array A with a length of m, the first column is the i value, and the second column is the position index of the maximum value among the absolute values of the first differential values in the i-th row in that row to obtain an index value. If the index value is 0, reset it to 10000.

[0105] That is, set the proportional size r1 of this search direction. This parameter tries to make the left half of the circle fall within the search range, but not exceed the highest arc point at the top and the lowest arc point at the bottom of the circle. The actual width of the search image is n*r1, where n is the width of the entire image. Then perform a differential operation on the pixel values of each row of the image in turn according to the pixel value of the right point minus the pixel value of the left point, such as G i,1 -Gi,0 ,G i,2 -G i,1 ,……,G i,n*r1-1 -G i,n*r1-2 ,where G represents the grayscale value matrix of the image, and G i,1 -G i,0 represents the subtraction of the first grayscale value from the 0th grayscale value in a certain row i (0 ≤ i ≤ m - 1), where m is the height of the entire image. Here, there is no need to set a difference threshold as in the case of searching for a straight line because the X coordinate values of the points on the circular arc edge already vary greatly in the horizontal direction. Then, create a two-dimensional array A with a length of m. The first column is the i value, and the second column is the position index of the maximum value among the absolute differences in the i-th row in that row. If the index value is 0, reset it to 10000.

[0106] Step 2: Based on the elements in the second column of array A, sort array A in ascending order to obtain array A_Sort. Set the search range parameter Range (Range > 0) and perform a for loop starting from the first row of array A_Sort. If A_Sort[i, 0] ≥ Range, create a new array A_Cut such that A_Cut = A[A_Sort[i, 0] - Range : A_Sort[i, 0] + Range, :]; if A_Sort[i, 0] < Range, then A_Cut = A[0 : A_Sort[i, 0] + Range, :]. The role of array A_Cut is to intercept a continuous circular arc region in the vertical direction. Subtract the previous row element from the next row element in the second column of array A_Cut, that is, take the differences of the X coordinate values of the circular arc edge points obtained in each row in sequence, and add the obtained difference values to vector V. Set the circular arc threshold C1 (C1 > 0). If the maximum value in vector V is less than C1 and the minimum value is greater than -1 * C1, then save the point [A_Sort[i, 0], A_Sort[i, 1]] to array B as the target point; if the maximum value in vector V is greater than C1 or the minimum value is less than -1 * C1, then ignore this point and continue the for loop to judge each row of points. When A_Sort[i, 1] = 10000, terminate the for loop.

[0107] Step 3: Based on the second column of array B, sort array B in ascending order, intercept several points with the same X coordinate value at the top of array B, and then select the point with the row number in the middle position from these points as the topmost point P_Top of the left half of the circular arc.

[0108] Generally, for the point at the topmost of the left half of the arc, its X coordinate value in the image is the smallest compared to other points on the arc edge. Due to the issue of camera resolution, in array B, there may be multiple same minimum X coordinate values. Therefore, taking the second column of array B, that is, the column where the X coordinate value is located, as the reference, sort B from small to large, then intercept several points with the same X coordinate value at the top of array B, and select the point with the middle row number among these points as the topmost point P_Top of the left half of the arc.

[0109] Step 4: Set the search step parameter L (L is a positive integer). The main function of this parameter is to make the finally searched points be evenly distributed on the arc edge as much as possible. At the same time, set the number of search points num1, make a for loop, and the number of loop times is num1. Taking the P_Top as the reference point, select the following points from array A: [P_Top.Y+(1+k)*L, A[P_Top.Y+(1+k)*L, 1]], [P_Top.Y-(1+k)*L, A[P_Top.Y-(1+k)*L, 1]], where P_Top.Y is the Y coordinate value of point P_Top in the image, that is, the row number where the point is located, k = 0, 1,..., num1 - 1, [P_Top.Y+(1+k)*L, A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, A[P_Top.Y-(1+k)*L, 1]] are a pair of points symmetric about P_Top. Then set the arc threshold C2 (C2 > 0), let diff = abs(A[P_Top.Y+(1+k)*L, 1] - A[P_Top.Y-(1+k)*L, 1]). If diff < C2, then select this pair of points as the target points of the finally fitted circle. This is because diff is the absolute value of the difference between this pair of points in the horizontal direction, and they are symmetric about the center point, so their X coordinate values are relatively close. If diff ≥ C2, it means that at least one of this pair of points is not on the arc, and the corresponding points are ignored. In the ideal case, the finally searched number of points is 2*num1 + 1, where 1 is the vertex P_Top.

[0110] (2) The search strategy from right to left includes:

[0111] Step 1: Set the proportional dimension r2 of this search direction. Perform a first-order difference on the pixel values of each row of the ROI region image in turn by subtracting the pixel value of the right point from the pixel value of the left point to obtain the first-order difference value, and take the absolute value of the first-order difference value; create an array A with a length of m. The first column is the i value, and the second column is the position index in this row of the maximum value among the absolute values of the first-order difference values in this i row to obtain the index value. If the index value is 0, reset it to 10000.

[0112] That is, set the proportional dimension r2 of the search direction. This parameter tries to make the right half of the circle fall within the search range, but not exceed the highest arc point at the top and the lowest arc point at the bottom of the circle. The actual search image range starts from the right edge of the image to the part with a width of n*r2, where n is the width of the entire image. Then, the pixel values of each row of the image are successively differentiated by subtracting the pixel value of the right point from the pixel value of the left point, such as G i,n-2 -G i,n-1 , G i,n-3 -G i,n-2 , ……, G i,n-n*r2-1 -G i,n-n*r2-2 . The subsequent operations are the same as the other operations in Step 1 of Module 1.

[0113] Step 2: Using the elements in the second column of array A as a benchmark, sort array A from smallest to largest to obtain array A_Sort. Set the search range parameter Range (Range>0), and perform a for loop. Starting from the first row of array A_Sort, if A_Sort[i,0]≥Range, create a new array A_Cut such that A_Cut = A[A_Sort[i,0]-Range:A_Sort[i,0]+Range,:]; if A_Sort[i,0]<Range, then A_Cut = A[0:A_Sort[i,0]+Range,:]. The function of array A_Cut is to vertically intercept a continuous arc region. Subtract the element in the previous row from the element in the next row in the second column of array A_Cut. That is, successively differentiate the X coordinate values of the arc edge points obtained in each row, and add the obtained difference values to vector V. Set the arc threshold C1 (C1>0). If the maximum value in vector V is less than C1 and the minimum value is greater than -1*C1, then save the point [A_Sort[i,0], n - A_Sort[i,1]] to array B as the target point, where n is the width of the image; if the maximum value in vector V is greater than C1 or the minimum value is less than -1*C1, then ignore this point and continue the for loop to judge each row of points. When A_Sort[i,1] = 10000, terminate the for loop.

[0114] The operation of this step is similar to Step 2 in the left-to-right strategy. However, when constructing array B, the points that meet the judgment conditions are changed to [A_Sort[i,0], n - A_Sort[i,1]], and then saved to array B, where n is the width of the entire image. Since A_Sort[i,1] is the X coordinate value obtained with the right edge of the reference image as the starting point, but the points ultimately used to fit the circle are still referenced from the left edge of the image.

[0115] Step 3: Using the second column of array B as a reference, sort array B in ascending order, intercept several points with the same X coordinate value at the top of array B, and then select the point with the middle row number from these points as the topmost point P_Top of the right half of the arc.

[0116] Generally, the topmost point of the right half of the arc has the largest X coordinate value in the image compared to other points on the arc edge. Therefore, using the second column of array B as a reference, that is, the column where the X coordinate value is located, sort B in descending order, then intercept several points with the same X coordinate value at the top of array B, and then select the point with the middle row number from these points as the topmost point P_Top of the right half of the arc.

[0117] Step 4: Set the search step parameter L (L is a positive integer), and at the same time set the number of search points num2. Make a for loop with the number of loops being num2. Using the point P_Top as a reference point, select the following points from array A: [P_Top.Y+(1+k)*L, A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, A[P_Top.Y-(1+k)*L, 1]], where P_Top.Y is the Y coordinate value of point P_Top in the image, that is, the row number where the point is located, k = 0, 1,..., num2-1. Then set the arc threshold C2 (C2>0), and let diff = abs(A[P_Top.Y+(1+k)*L, 1]-A[P_Top.Y-(1+k)*L, 1]). If diff<C2, then change a pair of points to [P_Top.Y+(1+k)*L, n-A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, n-A[P_Top.Y-(1+k)*L, 1]], and select them as the target points for the final fitted circle. If diff≥C2, ignore the corresponding points.

[0118] The operation of this step is similar to that of Step 4 in the left-to-right strategy. Set the search step size parameter L (L is a positive integer), and at the same time set the number of search points num2. Make a for loop with the number of loops being num2. Taking P_Top as the reference point, select the following points from array A: [P_Top.Y+(1+k)*L, A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, A[P_Top.Y-(1+k)*L, 1]], where k = 0, 1,..., num2-1. Then set the arc threshold C2 (C2>0). If diff = abs(A[P_Top.Y+(1+k)*L, 1]-A[P_Top.Y-(1+k)*L, 1]), and if diff<C2, then change a pair of points to [P_Top.Y+(1+k)*L, n-A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, n-A[P_Top.Y-(1+k)*L, 1]], and select them as the edge points of the final fitted circle.

[0119] (3) The top-to-bottom search strategy includes:

[0120] Step 1: Set the proportional dimension r3 of the search direction. Perform a first-order difference on the pixel values of each column of the ROI region image in sequence by subtracting the pixel value of the upper point from the pixel value of the lower point to obtain the first-order difference value, and take the absolute value of the first-order difference value. Create an array A with a length of n. The second column is the j value, and the first column is the position index in the row where the maximum value of the absolute value of the first-order difference in the jth column is located to obtain the index value. If the index value is 0, reset it to 10000.

[0121] That is, set the proportional dimension r3 of this search direction. This parameter tries to make the upper half of the circle fall within the search range, but not exceed the leftmost arc point and the rightmost arc point of the circle. The actual height of the search image is m*r2, where m is the height of the entire image. Then perform a difference on the pixel values of each column in sequence by subtracting the pixel value of the upper point from the pixel value of the lower point, such as G 1,j -G 0,j , G 2,j -G 1,j , ……, G m*r3-1,j -G m*r3-2,j , G 1,j -G 0,j represents the first gray value minus the 0th gray value from the upper edge of a certain column j (0≤j≤n-1), and n is the width of the entire image. Then create a two-dimensional array A with a length of n. The first column is the position index in the column where the maximum value of the absolute difference in the jth column is located. If the index value is 0, reset it to 10000, and the second column is the j value.

[0122] Step 2: Taking the elements in the first column of array A as the benchmark, sort array A in ascending order to obtain array A_Sort. Set the search range parameter Range (Range>0), and perform a for loop. Starting from the first row of array A_Sort, if A_Sort[i,1]≥Range, create a new array A_Cut such that A_Cut = A[:, A_Sort[i,1]-Range:A_Sort[i,1]+Range]; if A_Sort[i,1]<Range, then A_Cut = A[:,0:A_Sort[i,1]+Range]. The function of array A_Cut is to horizontally intercept a continuous arc region. Subtract the elements in the previous row from the elements in the next row of the first column in the Cut array in sequence, that is, take the difference of the Y coordinate values of the arc edge points obtained by searching each column in the image in sequence, and add the obtained difference values to vector V. Set the arc threshold C1 (C1>0). If the maximum value in vector V is less than C1 and the minimum value is greater than -1*C1, then save the point [A_Sort[i,0], A_Sort[i,1]] to array B; if the maximum value in vector V is greater than C1 or the minimum value is less than -1*C1, then ignore this point and continue the for loop to make this judgment for each row of points. When A_Sort[i,0] = 10000, terminate the for loop.

[0123] Step 3: Taking the first column of array B as the benchmark, sort array B in ascending order, intercept several points with the same Y coordinate value at the top of array B, and then select the point with the middle column number from these points as the topmost point P_Top of the upper half of the arc.

[0124] Generally, for the topmost point of the upper half of the arc compared with other points on the arc edge, its Y coordinate value in the image is the smallest. Therefore, taking the first column of array B as the benchmark, that is, the column where the Y coordinate value is located, sort B in ascending order, then intercept several points with the same Y coordinate value at the top of array B, and then select the point with the middle column number from these points as the topmost point P_Top of the upper half of the arc.

[0125] Step 4: Set the search step parameter L (L is a positive integer), and at the same time set the number of search points num3. Make a for loop with the number of loops being num3. Taking the P_Top as the reference point, select the following points from the array A: [A[0, P_Top.X+(1+k)*L], P_Top.X+(1+k)*L] and [A[0, P_Top.X+(1-k)*L], P_Top.X+(1-k)*L], where P_Top.X is the X coordinate value of the point P_Top in the image, that is, the column number where the point is located, k = 0, 1,..., num3 - 1. Then set the arc threshold C2 (C2 > 0), and let diff = abs(A[0, P_Top.X+(1+k)*L] - A[0, P_Top.X+(1-k)*L]). If diff < C2, then select this pair of points as the target points for the final fitted circle. If diff ≥ C2, ignore the corresponding points.

[0126] (4) The bottom-up search strategy includes:

[0127] Step 1: Set the proportional size r4 of the search direction. Perform a first-order difference on the pixel values of each column of the ROI region image in sequence by subtracting the pixel value of the lower point from the pixel value of the upper point to obtain the first-order difference value, and take the absolute value of the first-order difference value. Create an array A with a length of n. The second column is the j value, and the first column is the position index of the maximum value among the absolute values of the first-order differences in the j-th column in that row to obtain the index value. If the index value is 0, reset it to 10000.

[0128] That is, set the proportional size r4 of this search direction. This parameter should try to make the lower half of the circle fall within the search range, but not exceed the leftmost arc point and the rightmost arc point of the circle. The actual height of the search image is m*r4, where m is the height of the entire image. Then perform a difference on the pixel values of each column in sequence by subtracting the pixel value of the lower point from the pixel value of the upper point, such as G m-2,j -G m-1,j ,G m-3,j -G m-2,j ,……,G m-m*r4-1,j -G m-m*r4-2,j ,where G m-2,j -G m-1,j represents the first gray value minus the 0-th gray value starting from the lower edge of a certain column j (0 ≤ j ≤ n - 1), and n is the width of the entire image. Then, similar to step 1 of module 3, create a two-dimensional array A with a length of n. The first column is the position index of the maximum value among the absolute differences in the j-th column in that column. If the index value is 0, reset it to 10000, and the second column is the j value.

[0129] Step 2: Taking the elements in the first column of two groups of A as the reference, sort array A from smallest to largest to obtain array A_Sort. Set the search range parameter Range (Range > 0), and perform a for loop. Starting from the first row of array A_Sort, if A_Sort[i,1] ≥ Range, create a new array A_Cut such that A_Cut = A[:, A_Sort[i,1] - Range : A_Sort[i,1] + Range]; if A_Sort[i,1] < Range, then A_Cut = A[:, 0 : A_Sort[i,1] + Range]. The function of array A_Cut is to intercept a continuous arc region horizontally. Subtract the element in the previous row from the element in the next row of the first column in the Cut array in turn, that is, take the difference of the Y coordinate values of the arc edge points obtained by searching each column in the image in turn, and add the obtained difference values to vector V. Set the arc threshold C1 (C1 > 0). If the maximum value in vector V is less than C1 and the minimum value is greater than -1 * C1, save the point [m - A_Sort[i,0], A_Sort[i,1]] to array B, where m is the height of the image; if the maximum value in vector V is greater than C1 or the minimum value is less than -1 * C1, ignore this point and continue the for loop to perform this judgment for each row of points. When A_Sort[i,0] = 10000, terminate the for loop.

[0130] The operation of this step is similar to Step 2 in the top - down strategy. However, when constructing array B, for the points that meet the judgment conditions, change them to [m - A_Sort[i,0], A_Sort[i,1]], and then save them to array B, where m is the height of the entire image. Since A_Sort[i,0] is the Y coordinate value obtained with the lower edge of the reference image as the starting point, but the points ultimately used to fit the circle are still referenced from the upper edge of the image.

[0131] Step 3: Taking the first column of array B as the reference, sort array B from smallest to largest, intercept several points with the same Y coordinate value at the top of array B, and then select the point with the middle column number from these points as the top - most point P_Top of the lower half of the arc.

[0132] Generally, the top - most point of the lower half of the arc has the largest Y coordinate value in the image compared to other points on the arc edge. Therefore, taking the first column of array B as the reference, that is, the column where the Y coordinate value is located, sort B from largest to smallest, then intercept several points with the same Y coordinate value at the top of array B, and then select the point with the middle column number from these points as the top - most point P_Top of the lower half of the arc.

[0133] Step 4: Set the search step parameter L (L is a positive integer), and at the same time set the number of search points num4. Make a for loop with the number of loops being num4. Taking the P_Top as the reference point, select the following points from the array A: [A[0, P_Top.X+(1+k)*L], P_Top.X+(1+k)*L] and [A[0, P_Top.X+(1-k)*L], P_Top.X+(1-k)*L], where P_Top.X is the X coordinate value of the point P_Top in the image, that is, the column number where the point is located, k = 0, 1, ……, num4-1. Then set the arc threshold C2 (C2>0), and let diff = abs(A[0, P_Top.X+(1+k)*L]-A[0, P_Top.X+(1-k)*L]). If diff < C2, change this pair of points to [m - A[0, P_Top.X+(1+k)*L], P_Top.X+(1+k)*L] and [m - A[0, P_Top.X+(1-k)*L], P_Top.X+(1-k)*L], and select them as the target points of the final fitted circle. If diff ≥ C2, ignore the corresponding points.

[0134] In some embodiments of the present invention, step S204 includes:

[0135] Find three parameters a, b, c of the circle by the least squares method, as shown in formula (2), where x i is the X coordinate value of the i-th point among the N arc edge points finally searched on the image, and y i is its Y coordinate value. Use this formula (2) to take partial derivatives of a, b, c respectively to obtain the partial derivative equations, and make them equal to 0. Finally, solve for a, b, c, and then the center coordinates are equal to [-a / 2, -b / 2], and the radius of the circle

[0136]

[0137] According to the positioning measurement method and device based on the differential search algorithm provided by the embodiments of the present invention, the circle finding based on the differential search algorithm realizes the positioning measurement of the circle on the workpiece to be measured. Compared with the traditional image processing algorithm, it reduces the processing procedures such as binarization, erosion or dilation, and edge detection. Correspondingly, it also reduces the setting of multiple parameters and improves the robustness of the algorithm.

[0138] Refer to Figure 3 as shown Figure 3 shows a schematic structural diagram of an embodiment of the positioning measurement device based on the differential search algorithm provided by the embodiments of the present invention. For the sake of convenience of description, only the parts related to the embodiments of the present invention are shown. Specifically, the positioning measurement device based on the differential search algorithm is suitable for positioning and measuring a straight line on the workpiece to be measured, and it includes:

[0139] An acquisition unit 301, configured to acquire a target image of a workpiece to be detected collected by a vision camera, and read the target image in grayscale format.

[0140] An interception unit 302, configured to intercept an ROI region image in the target image.

[0141] A differential search unit 303, configured to perform differential search according to a predetermined search strategy based on the direction of a straight line and the background state in the ROI region image to obtain a plurality of target points.

[0142] A fitting unit 304, configured to fit the plurality of obtained target points into a target straight line, and output the slope value and offset value of the straight line.

[0143] According to the positioning measurement device based on the differential search algorithm provided by the embodiment of the present invention, the straight line finding based on the differential search algorithm realizes the positioning measurement of the straight line on the workpiece to be detected. Compared with the traditional image processing algorithm, the processing procedures such as binarization, erosion or dilation, and edge detection are reduced. Correspondingly, the setting of multiple parameters is also reduced, and the robustness of the algorithm is improved.

[0144] Another embodiment of the positioning measurement device based on the differential search algorithm provided by the present invention is suitable for positioning and measuring a circle on a workpiece to be detected, and includes:

[0145] An acquisition unit, configured to acquire a target image of a workpiece to be detected collected by a vision camera, and read the target image in grayscale format.

[0146] An interception unit, configured to intercept an ROI region image in the target image.

[0147] A differential search unit, which performs differential search according to a predetermined search strategy based on the integrity of a circle in the ROI region image to obtain a plurality of target points.

[0148] A fitting unit, configured to fit the plurality of obtained target points into a target circle, and output the circular coordinates and radius of the circle.

[0149] According to the positioning measurement device based on the differential search algorithm provided by the embodiment of the present invention, the circle finding based on the differential search algorithm realizes the positioning measurement of the circle on the workpiece to be detected. Compared with the traditional image processing algorithm, the processing procedures such as binarization, erosion or dilation, and edge detection are reduced. Correspondingly, the setting of multiple parameters is also reduced, and the robustness of the algorithm is improved.

[0150] It should be noted that the embodiments in this specification are all described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the embodiments, reference can be made to each other. For device or system embodiments, since they are basically similar to method embodiments, they are described relatively simply. For the relevant parts, reference can be made to the corresponding descriptions in the method embodiments.

[0151] It should also be noted that in this text, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the said element.

[0152] The steps of the methods or algorithms described in connection with the embodiments disclosed herein can be implemented directly in hardware, in software modules executed by a processor, or in a combination of both. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the technical field.

[0153] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but will be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A positioning measurement method based on the differential search algorithm, suitable for linear positioning measurement, characterized in that, it includes: Obtain the target image of the workpiece to be detected collected by the vision camera, and read the target image in grayscale format; Intercept the ROI region image in the target image; Select a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image to obtain multiple target points; Fit the multiple target points obtained by the search into a target straight line, and output the slope value and offset value of the straight line; Among them, the step of selecting a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image to obtain multiple target points includes: When the direction of the straight line in the ROI region image is close to a vertical straight line and the background part is on the left side of the ROI region image, search according to the left-to-right search strategy to obtain multiple target points, and when the background part is on the right side of the ROI region image, search according to the right-to-left search strategy to obtain multiple target points; When the direction of the straight line in the ROI region image is close to a horizontal straight line and the background part is on the upper side of the ROI region image, search according to the top-to-bottom search strategy to obtain multiple target points, and when the background part is on the lower side of the ROI region image, search according to the bottom-to-top search strategy to obtain multiple target points.

2. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, before selecting a predetermined search strategy for differential search according to the direction of the straight line and the background state in the ROI region image, it further includes: Performing filtering processing on the ROI region image.

3. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, The left-to-right search strategy includes: Starting from the left edge of the ROI region image, perform a first-order difference on the pixel values of each row in turn by subtracting the pixel value of the left point from the pixel value of the right point to obtain a first-order difference value, take the absolute value of the first-order difference value, and set a threshold. If the absolute value of a certain first-order difference value is less than the threshold, reassign it to 0; Sort the absolute values of the first-order difference values of each row, find the maximum value among the absolute values, determine the position index of the maximum value in this row to obtain an index value, and set the number of search points; Perform a second-order difference on all the searched points. In the vertical direction, subtract the X coordinate value of the next point in the image from the X coordinate value of the previous point to obtain a second-order difference value, take the absolute value of the second-order difference value, form an array of these absolute values of the second-order difference values, and find the median Med of the array; Divide all the absolute values in the array by the median to obtain a set of ratio values; set a ratio threshold th1. If the ratio value in the array is greater than 1 - th1 and less than 1 + th1, retain the points corresponding to the ratio value, and delete the remaining points. For the points retained after screening, calculate the third-order difference values by successively subtracting the X coordinate value of the previous point from the X coordinate value of the next point, and count the number num_op of positive values and the number num_ne of negative values among these difference values. Set a fluctuation threshold th3. If there are both positive and negative values among the difference values, but the maximum value of the difference values is less than th3 and the minimum value is greater than -1*th3, retain these points as target points. If the difference values are all positive or negative, also retain these points as target points. However, if there are both positive and negative values among the difference values, and the maximum value is greater than th3 or the minimum value is less than -1*th3, then perform the next round of screening; Set a while loop. If num_op * num_ne!= 0, it means that there are always both positive and negative values among the difference values, then keep looping. Otherwise, break out of the loop. In the loop, if num_op ≥ num_ne, delete the previous point corresponding to the negative difference value. Conversely, if num_op < num_ne, delete the previous point corresponding to the positive difference value. When there are no longer both positive and negative values among the difference values, then take the remaining points as target points.

4. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, the search strategy from right to left includes: Starting from the right edge of the ROI region image, perform a first-order difference on the pixel values of each row in turn by subtracting the pixel value of the left point from the pixel value of the right point to obtain the first-order difference values. Take the absolute value of the first-order difference values, and set a threshold. If the absolute value of a certain first-order difference value is less than the threshold, reassign it to 0; Sort the absolute values of the first-order difference values of each row, find the maximum value among the absolute values, determine the position index of the maximum value in that row to obtain the index value, and subtract the index value from the width n of the ROI region image, and then set the number of search points; Perform a second-order difference on all the searched points. In the vertical direction, subtract the X coordinate value of the previous point in the image from the X coordinate value of the next point to obtain the second-order difference values. Take the absolute value of the second-order difference values, form an array with these absolute values of the second-order difference values, and find the median Med of the array; Divide all the absolute values in the array by the median to obtain a set of ratio values. Set a ratio threshold th1. If the ratio values in the array are greater than 1 - th1 and less than 1 + th1, retain the points corresponding to the ratio values, and delete the remaining points; The retained points after screening are successively differentiated to obtain three - order difference values by subtracting the X - coordinate value of the previous point from the X - coordinate value of the next point, and the number of positive values num_op and the number of negative values num_ne among these difference values are counted; a fluctuation threshold th3 is set. If there are both positive and negative values among the difference values, but the maximum value among the difference values is less than th3 and the minimum value is greater than - 1*th3, these points are retained as target points. If the difference values are all positive or all negative, these points are also retained as target points. However, if there are both positive and negative values among the difference values, and the maximum value is greater than th3 or the minimum value is less than - 1*th3, the next round of screening is performed; A while loop is set. If num_op*num_ne!= 0, it means that there are always both positive and negative values among the difference values, and the loop continues. Otherwise, the loop is exited. In the loop, if num_op≥num_ne, the previous point corresponding to the negative difference value is deleted. On the contrary, if num_op < num_ne, the previous point corresponding to the positive difference value is deleted. When there are no longer both positive and negative values among the difference values, the remaining points are used as target points.

5. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, the top - down search strategy includes: Starting from the upper edge of the ROI region image, each column of pixel values is successively differentiated once by subtracting the pixel value of the upper point from the pixel value of the lower point to obtain first - order difference values. The absolute values of the first - order difference values are taken, and a threshold is set. If the absolute value of a certain first - order difference value is less than the threshold, it is re - assigned a value of 0; The absolute values of the first - order difference values of each column are sorted to find the position index of the maximum value in the absolute values, and the number of search points is set; All the searched points are second - order differentiated. Horizontally, the Y - coordinate value of the right point in the image is subtracted from the Y - coordinate value of the left point to obtain second - order difference values. The absolute values of the second - order difference values are taken, and these absolute values of the second - order difference values form an array, and the median Med of the array is found; All the absolute values in the array are divided by the median to obtain a set of ratio values; a ratio threshold th1 is set. If the ratio values in the array are greater than 1 - th1 and less than 1 + th1, the points corresponding to the ratio values are retained, and the rest of the points are deleted; The retained points after screening are successively differentiated to obtain three - order difference values by subtracting the Y - coordinate value of the left point from the Y - coordinate value of the right point, and the number of positive values num_op and the number of negative values num_ne among these difference values are counted. A fluctuation threshold th3 is set. If there are both positive and negative values among the difference values, but the maximum value among the difference values is less than th3 and the minimum value is greater than - 1*th3, these points are retained as target points. If the difference values are all positive or all negative, these points are also retained as target points. However, if there are both positive and negative values among the difference values, and the maximum value is greater than th3 or the minimum value is less than - 1*th3, the next round of screening is performed; Set up a while loop. If num_op * num_ne != 0, it means that there are always both positive and negative values in the difference values, so the loop continues; otherwise, the loop is exited. In the loop, if num_op >= num_ne, the previous point corresponding to the negative difference value is deleted; conversely, if num_op < num_ne, the previous point corresponding to the positive difference value is deleted. When there are no longer both positive and negative values in the difference values, the remaining points are used as target points.

6. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, the bottom-up search strategy includes: Starting from the lower edge of the ROI region image, perform a difference operation on the pixel values of each column in turn by subtracting the pixel value of the lower point from the pixel value of the upper point to obtain the first difference value. Take the absolute value of the first difference value and set a threshold. If the absolute value of a certain first difference value is less than the threshold, reassign it to 0; Sort the absolute values of the first difference values of each column, find the maximum value among the absolute values, determine the position index of the maximum value in that row to obtain the index value, and subtract the index value from the width n of the ROI region image, and then set the number of search points; Perform a second difference operation on all the searched points. Horizontally, subtract the Y coordinate value of the left point in the image from the Y coordinate value of the right point to obtain the second difference value. Take the absolute value of the second difference value, form an array of these absolute values of the second difference values, and find the median Med of the array; Divide all the absolute values in the array by the median to obtain a set of ratio values; set a ratio threshold th1. If the ratio value in the array is greater than 1 - th1 and less than 1 + th1, retain the point corresponding to the ratio value, and delete the remaining points; Perform a difference operation on the points retained after screening in turn by subtracting the Y coordinate value of the left point from the Y coordinate value of the right point to obtain the third difference value, and count the number of positive values num_op and the number of negative values num_ne in these difference values. Set a fluctuation threshold th3. If there are both positive and negative values in the difference values, but the maximum value in the difference values is less than th3 and the minimum value is greater than -1 * th3, retain these points as target points. If the difference values are all positive or negative, also retain these points as target points. If there are both positive and negative values in the difference values, and the maximum value is greater than th3 or the minimum value is less than -1 * th3, then perform the next round of screening; Set up a while loop. If num_op * num_ne != 0, it means that there are always both positive and negative values in the difference values, so the loop continues; otherwise, the loop is exited. In the loop, if num_op >= num_ne, the previous point corresponding to the negative difference value is deleted; conversely, if num_op < num_ne, the previous point corresponding to the positive difference value is deleted. When there are no longer both positive and negative values in the difference values, the remaining points are used as target points.

7. The positioning measurement method based on the differential search algorithm according to claim 1, characterized in that, Fitting the multiple target points obtained by searching into a target straight line and outputting the slope value and offset value of the straight line includes: Find the two parameters of the straight line, the slope K and the offset B, by the least squares method, as shown in Equation (1), where x i is the X coordinate value of the i-th point among the N points finally searched on the image, and y i is its Y coordinate value. Take the partial derivatives of K and B respectively using Equation (1) to obtain the partial derivative equations, and set them equal to 0 to solve for K and B:

8. A positioning measurement method based on a differential search algorithm, suitable for circular positioning measurement, Characterized in that, It includes: Obtain the target image of the workpiece to be detected collected by the vision camera and read the target image in grayscale format; Intercept the ROI region image in the target image; Select a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image to obtain multiple target points; Fit the multiple target points obtained by searching into a target circle and output the center coordinates and radius of the circle; Among them, selecting a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image includes: When the circle in the ROI region image is in a complete state, perform four search strategies from left to right, from right to left, from top to bottom, and from bottom to top simultaneously; when the circle in the ROI region image is in a partially missing state, close the search strategy on the side where the missing part is located.

9. The positioning measurement method based on the differential search algorithm according to claim 8, Characterized in that, Before selecting a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image, it further includes: Performing filtering processing on the ROI region image.

10. The positioning measurement method based on the differential search algorithm according to claim 8, Characterized in that, The search strategy from left to right includes: Set the proportional size r1 of the search direction, perform a differential operation on the pixel values of each row of the ROI region image in sequence by subtracting the pixel value of the left point from the pixel value of the right point to obtain a first differential value, and take the absolute value of the first differential value; create an array A with a length of m, where m is the image height, the first column is the i value, and the second column is the position index in that row of the maximum value among the absolute values of the first differential values in that i row to obtain an index value. If the index value is 0, reset it to 10000; Taking the elements in the second column of array A as the benchmark, sort array A in ascending order to obtain array A_Sort. Set the search range parameter Range, where Range > 0, and perform a for loop starting from the first row of array A_Sort. If A_Sort[i, 0] ≥ Range, create a new array A_Cut such that A_Cut = A[A_Sort[i, 0] - Range : A_Sort[i, 0] + Range, :]; if A_Sort[i, 0] < Range, then A_Cut = A[0 : A_Sort[i, 0] + Range, :]. The role of array A_Cut is to intercept a continuous arc region in the vertical direction. Subtract the elements in the previous row from the elements in the next row of the second column in array A_Cut, that is, take the difference of the X coordinate values of the arc edge points obtained by searching each row in turn, and add the obtained difference values to vector V. Set the arc threshold C1, where C1 > 0. If the maximum value in vector V is less than C1 and the minimum value is greater than -1 * C1, then save the point [A_Sort[i, 0], A_Sort[i, 1]] to array B as the target point; if the maximum value in vector V is greater than C1 or the minimum value is less than -1 * C1, then ignore this point and continue the for loop to judge each row of points. When A_Sort[i, 1] = 10000, terminate the for loop; Taking the second column of array B as the benchmark, sort array B in ascending order, intercept several points with the same X coordinate value at the top of array B, and then select the point with the row number in the middle position from these points as the topmost point P_Top of the left half of the arc; Set the search step parameter L, where L is a positive integer, and at the same time set the number of search points num1. Perform a for loop with the number of loops being num1. Taking the point P_Top as the reference point, select the following points from array A: [P_Top.Y + (1 + k) * L, A[P_Top.Y + (1 + k) * L, 1]], [P_Top.Y - (1 + k) * L, A[P_Top.Y - (1 + k) * L, 1]], where P_Top.Y is the Y coordinate value of point P_Top in the image, that is, the row number where the point is located, k = 0, 1,..., num1 - 1. [P_Top.Y + (1 + k) * L, A[P_Top.Y + (1 + k) * L, 1]] and [P_Top.Y - (1 + k) * L, A[P_Top.Y - (1 + k) * L, 1]] are a pair of points symmetric about P_Top. Then set the arc threshold C2, where C2 > 0. Let diff = abs(A[P_Top.Y + (1 + k) * L, 1] - A[P_Top.Y - (1 + k) * L, 1]). If diff < C2, then select a pair of points as the target points for the final fitted circle. If diff ≥ C2, ignore the corresponding points. Normally, the number of points finally searched is 2 * num1 + 1.

11. The positioning measurement method based on the differential search algorithm according to claim 8, characterized in that, the search strategy from right to left includes: Set the proportional dimension r2 of this search direction, perform a differential operation on the pixel values of each row of the ROI region image in turn by subtracting the pixel value of the right point from the pixel value of the left point to obtain a first differential value, and take the absolute value of the first differential value; create an array A with a length of m, where m is the image height, the first column is the i value, and the second column is the position index in that row of the maximum value among the absolute values of the first differential values in that i row to obtain an index value. If the index value is 0, reset it to 10000; Based on the elements in the second column of array A, sort array A from smallest to largest to obtain array A_Sort. Set the search range parameter Range, where Range > 0, and perform a for loop starting from the first row of array A_Sort. If A_Sort[i,0] ≥ Range, create a new array A_Cut such that A_Cut = A[A_Sort[i,0] - Range:A_Sort[i,0] + Range,:]; if A_Sort[i,0] < Range, then A_Cut = A[0:A_Sort[i,0] + Range,:]. The function of array A_Cut is to intercept a continuous arc region in the vertical direction, subtract the previous row element from the next row element in the second column of array A_Cut in turn, that is, perform a differential operation on the X coordinate values of the arc edge points obtained by searching each row in turn, and add the obtained differential values to vector V. Set the arc threshold C1, where C1 > 0. If the maximum value in vector V is less than C1 and the minimum value is greater than -1*C1, then save the point [A_Sort[i,0], n - A_Sort[i,1]] to array B as the target point, where n is the width of the image; if the maximum value in vector V is greater than C1 or the minimum value is less than -1*C1, then ignore this point and continue the for loop to judge each row of points. When A_Sort[i,1] = 10000, terminate the for loop; Based on the second column of array B, sort array B from smallest to largest, intercept several points with the same X coordinate value at the top of array B, and then select the point with the middle row number from these points as the topmost point P_Top of the right half of the arc; Set the search step parameter L, where L is a positive integer. At the same time, set the number of search points num2, and perform a for loop with the number of loops being num2. Taking the P_Top as the reference point, select the following points from the array A: [P_Top.Y+(1+k)*L, A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, A[P_Top.Y-(1+k)*L, 1]], where P_Top.Y is the Y coordinate value of the point P_Top in the image, that is, the row number where the point is located, k = 0, 1,..., num2-1. Then set the arc threshold C2, where C2>0. Let diff = abs(A[P_Top.Y+(1+k)*L, 1]-A[P_Top.Y-(1+k)*L, 1]). If diff<C2, then change a pair of points to [P_Top.Y+(1+k)*L, n-A[P_Top.Y+(1+k)*L, 1]] and [P_Top.Y-(1+k)*L, n-A[P_Top.Y-(1+k)*L, 1]], where n is the image width, and select them as the target points for the final fitted circle. If diff≥C2, ignore the corresponding points.

12. The positioning measurement method based on the differential search algorithm according to claim 8, characterized in that the top-down search strategy includes: Set the proportional dimension r3 of the search direction. Perform a first-order difference on the pixel values of each column of the ROI region image in turn by subtracting the pixel value of the upper point from the pixel value of the lower point to obtain the first-order difference value, and take the absolute value of the first-order difference value; create an array A with a length of n, where n is the image width, the second column is the j value, and the first column is the position index of the maximum value among the absolute values of the first-order difference values in the j-th column in that row to obtain the index value. If the index value is 0, reset it to 10000; Taking the elements in the first column of array A as the benchmark, sort array A in ascending order to obtain array A_Sort. Set the search range parameter Range, where Range > 0, and perform a for loop. Starting from the first row of array A_Sort, if A_Sort[i,1] ≥ Range, create a new array A_Cut such that A_Cut = A[:, A_Sort[i,1] - Range : A_Sort[i,1] + Range]; if A_Sort[i,1] < Range, then A_Cut = A[:, 0 : A_Sort[i,1] + Range]. The function of array A_Cut is to intercept a continuous arc region horizontally. Subtract the elements in the previous row from the elements in the next row of the first column in the Cut array in turn, that is, take the difference of the Y coordinate values of the arc edge points obtained by searching each column in the image in turn, and add the obtained difference values to vector V. Set the arc threshold C1, where C1 > 0. If the maximum value in vector V is less than C1 and the minimum value is greater than -1*C1, save the point [A_Sort[i,0], A_Sort[i,1]] to array B; if the maximum value in vector V is greater than C1 or the minimum value is less than -1*C1, ignore the point and continue the for loop to perform this judgment for each row of points. When A_Sort[i,0] = 10000, terminate the for loop. Taking the first column of array B as the benchmark, sort array B in ascending order, intercept several points with the same Y coordinate value at the top of array B, and then select the point with the middle column number among these points as the topmost point P_Top of the upper half of the arc. Set the search step parameter L, where L is a positive integer, and at the same time set the number of search points num3. Perform a for loop with the number of loops being num3. Taking the P_Top as the reference point, select the following points from array A: [A[0, P_Top.X + (1 + k)*L], P_Top.X + (1 + k)*L] and [A[0, P_Top.X + (1 - k)*L], P_Top.X + (1 - k)*L], where P_Top.X is the X coordinate value of point P_Top in the image, that is, the column number where the point is located, and k = 0, 1,..., num3 - 1. Then set the arc threshold C2, where C2 > 0. Let diff = abs(A[0, P_Top.X + (1 + k)*L] - A[0, P_Top.X + (1 - k)*L]). If diff < C2, select this pair of points as the target points for the final fitted circle; if diff ≥ C2, ignore the corresponding points.

13. The positioning and measurement method based on the differential search algorithm according to claim 8, characterized in that, the bottom-up search strategy includes: Set the proportional dimension r4 of the search direction, perform a first-order difference on the pixel values of each column of the ROI region image in turn by subtracting the pixel value of the lower point from the pixel value of the upper point to obtain the first-order difference value, and take the absolute value of the first-order difference value; create an array A with a length of n, where n is the image width, the second column is the j value, and the first column is the position index of the maximum value among the absolute values of the first-order difference values in the j-th column in that row to obtain the index value. If the index value is 0, reset it to 10000; Based on the elements in the first column of the array A, sort the array A from smallest to largest to obtain the array A_Sort. Set the search range parameter Range, where Range>0, and perform a for loop. Starting from the first row of the array A_Sort, if A_Sort[i,1]≥Range, create a new array A_Cut such that A_Cut = A[:,A_Sort[i,1]-Range:A_Sort[i,1]+Range]; if A_Sort[i,1]<Range, then A_Cut = A[:,0:A_Sort[i,1]+Range]. The role of the array A_Cut is to intercept a continuous arc region in the horizontal direction, subtract the previous row element from the next row element in the first column of the Cut array in turn, that is, perform a difference on the Y coordinate values of the arc edge points obtained by searching each column in the image, and add the obtained difference values to the vector V. Set the arc threshold C1, where C1>0. If the maximum value in the vector V is less than C1 and the minimum value is greater than -1*C1, save the point [m - A_Sort[i,0], A_Sort[i,1]] to the array B, where m is the height of the image; if the maximum value in the vector V is greater than C1 or the minimum value is less than -1*C1, ignore this point and continue the for loop to make this judgment for each row of points. When A_Sort[i,0] = 10000, terminate the for loop; Based on the first column of the array B, sort the array B from smallest to largest, intercept several points with the same Y coordinate value at the top of the array B, and then select the point with the column number in the middle position from these points as the topmost point P_Top of the lower half of the arc; Set the search step parameter L, where L is a positive integer. At the same time, set the number of search points num4, and perform a for loop with the number of loops being num4. Taking the P_Top as the reference point, select the following points from the array A: [A[0, P_Top.X+(1+k)*L], P_Top.X+(1+k)*L] and [A[0, P_Top.X+(1-k)*L], P_Top.X+(1-k)*L], where P_Top.X is the X coordinate value of the point P_Top in the image, that is, the column number where the point is located, k = 0, 1, ……, num4-1. Then set the arc threshold C2, where C2>0. Let diff = abs(A[0, P_Top.X+(1+k)*L]-A[0, P_Top.X+(1-k)*L]). If diff<C2, then change this pair of points to [m-A[0, P_Top.X+(1+k)*L], P_Top.X+(1+k)*L] and [m-A[0, P_Top.X+(1-k)*L], P_Top.X+(1-k)*L], and select them as the target points of the final fitted circle. If diff≥C2, ignore the corresponding points.

14. The positioning measurement method based on the differential search algorithm according to claim 8, characterized in that fitting the multiple target points obtained by the search into a target circle and outputting the center coordinates and radius of the circle includes: Find the three parameters α, b, and c of the circle by the least squares method, as shown in Equation (2), where x i is the X coordinate value of the i-th point among the N arc edge points finally searched on the image, and y i is its Y coordinate value. Use this Equation (2) to take partial derivatives of α, b, and c respectively to obtain the partial derivative equations and set them equal to 0. Finally, solve for α, b, and c, and then the center coordinates are equal to [-α / 2, -b / 2], and the circle radius 15. A positioning measurement device based on the differential search algorithm, suitable for linear positioning measurement, characterized in that it includes: An acquisition unit for acquiring the target image of the workpiece to be detected collected by the vision camera and reading the target image in grayscale format; A cropping unit for cropping the ROI region image in the target image; A differential search unit for performing differential search according to the direction of the straight line and the background state in the ROI region image to select a predetermined search strategy to obtain multiple target points; A fitting unit for fitting the multiple target points obtained by the search into a target straight line and outputting the slope value and offset value of the straight line; wherein, the differential search unit is specifically used for: When the direction of the straight line in the ROI region image is close to a vertical straight line and the background part is located on the left side of the ROI region image, search according to the left-to-right search strategy to obtain multiple target points. When the background part is located on the right side of the ROI region image, search according to the right-to-left search strategy to obtain multiple target points; When the direction of the straight line in the ROI region image is close to a horizontal straight line and the background part is located on the upper side of the ROI region image, search according to the top-to-bottom search strategy to obtain multiple target points. When the background part is located on the lower side of the ROI region image, search according to the bottom-to-top search strategy to obtain multiple target points.

16. A positioning measurement device based on the differential search algorithm, suitable for circular positioning measurement, characterized in that it includes: An acquisition unit, configured to acquire a target image of a workpiece to be detected collected by a vision camera, and read the target image in grayscale format; An interception unit, configured to intercept an ROI region image in the target image; A differential search unit, which selects a predetermined search strategy for differential search according to the integrity of the circle in the ROI region image to obtain a plurality of target points; A fitting unit, configured to fit the plurality of target points obtained by the search into a target circle, and output the center coordinates and radius of the circle; Wherein, the differential search unit specifically includes: When the circle in the ROI region image is in a complete state, it performs simultaneously according to four search strategies: from left to right, from right to left, from top to bottom, and from bottom to top; when the circle in the ROI region image is in a partially missing state, the search strategy on the side where the missing part is located is turned off.

Citation Information

Patent Citations

  • Round Mark point positioning method based on connected region filtering

    CN103729632A

  • Detection method for quality of electric power pipe gallery reinforcing steel bar mesh based on machine vision and detection device

    CN105956942A