[0038] The machine vision-based twisted pair pitch measurement method of the present invention will be described in detail below with reference to the accompanying drawings:

[0039] Step 1: Use the camera to collect the twisted pair image;

[0040] Step 2: Perform anti-shake processing on the video of step 1, and the algorithm is based on feature matching and affine transformation to obtain each frame of image after anti-shake processing;

[0041] Step 2-1: Read the previous frame of image as a reference image, and extract scale-invariant feature points;

[0042] Step 2-2: Read the current frame and calculate the feature points, use the affine transformation model to register with the reference image, and use the registered image as the new current frame.

[0043] Step 3: Binarize the image obtained in step 2 according to the set gray threshold to obtain a binary image;

[0044] Step 3-1: Set the gray threshold value in the binarization process to the gray threshold obtained by using the maximum between-class variance method on the gray image;

[0045] Step 3-2: Compare the gray value of each pixel of the gray image with the gray threshold. If it is greater than the threshold, assign a value of 0 to the point. If it is less than the threshold, assign a value of 255 to the point to obtain the inverted value. Binary image.

[0046] Step 4: Mark the white connected areas in the binary image obtained in Step 3, record the position of each connected area, and obtain a marked image;

[0047] Step 5: Calculate the connected area to calculate the area of the marked image obtained in step 4, find the area with the largest area, and obtain the binary image of the twisted pair;

[0048] Step 5-1: Calculate the area of all marked connected areas, that is, count the number of pixels, and find the connected area with the largest area;

[0049] Step 5-2: Assign a value of 255 to the pixel value at the position of the largest connected area in the image, and assign a value of 0 to the pixel values of all other points to obtain a binary image of the twisted pair.

[0050] Step 6: Perform a morphological opening operation on the binary image of the twisted pair obtained in Step 5, that is, firstly etch and then expand, smooth the edge burrs, and obtain the binary image after smoothing the edge;

[0051] Step 7: Perform edge tracking on the smoothed-edge binary image obtained in Step 6 to obtain the position of the edge pixel of the connected area in the image;

[0052] Step 8: Perform pit detection judgment on the edge pixels obtained in Step 7 to obtain the coordinates of the pits in the image;

[0053] Step 8-1: Calculate the midpoint coordinates of the line connecting the 10th pixel point before and the 10th pixel point on the edge contour coordinates. If the midpoint pixel is black, the corresponding contour point is located on the edge On the concave position of the contour;

[0054] Step 8-2: Calculate the distance from each contour point on the same segment of the concave position to the line connecting the 10th pixel point before and the 10th pixel point behind. The contour point corresponding to the maximum distance is the concave point.

[0055] Step 9: Group the concave point coordinates obtained in step 8 into two groups, the upper edge concave point and the lower edge concave point, to obtain the grouped concave point coordinates;

[0056] Step 9-1: Obtain the coordinates of the concave point in the image, and calculate the slope between two adjacent concave points in turn;

[0057] Step 9-2: When the slope value of the two points is greater than 0.1, the two concave points are located at the upper edge and the lower edge respectively. The smaller vertical coordinate is the upper edge concave point, and the larger vertical coordinate is the lower edge concave point. When the point slope value is less than 0.1, two concave points are located at the upper or lower edge at the same time;

[0058] Step 9-3: Divide the concave points into two groups of upper edge and lower edge, and save the coordinate values of the two groups of concave points respectively.

[0059] Step 10: Calculate the nodes from the grouped concave point coordinates obtained in Step 9, and then calculate the distance between the nodes to be the pitch of the twisted pair.

[0060] Step 10-1: Match the top edge concave point with the bottom edge concave point. When the distance between an upper edge concave point and a lower edge concave point is less than 20 pixels, take the midpoint of the upper edge concave point and the lower edge concave point It is a node. When there is no lower edge concave point that meets the conditions, the upper edge concave point is discarded if the node is incompletely photographed, and a set of node coordinates is calculated;

[0061] Step 10-2: Calculate the distance between two adjacent nodes according to the obtained set of node coordinates, and the calculated distance is the pitch of the twisted pair.