Complex-shape guide rail sliding block size measurement method based on intelligent vision

Through intelligent vision technology and advanced image processing algorithms, the problems of low accuracy and slow efficiency in slider size measurement are solved, and high-precision size measurement of complex-shaped sliders are realized, which improves production efficiency and product quality.

CN119984033APending Publication Date: 2025-05-13SOUTH CHINA AGRICULTURAL UNIVERSITY +1
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202411885028.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

The prior art has problems such as low accuracy, slow efficiency and susceptible to ambient light and camera shake in slide size measurement, which is difficult to meet the high-precision size measurement requirements of complex-shaped slides.

Method used

The complex external guide rail slide size measurement method is adopted based on intelligent vision. Through steps such as DXF file data acquisition, image acquisition and preprocessing, hole detection and measurement, edge detection and measurement, and detection and measurement results visualization, combined with sub-pixel counting technology, Hough transformation algorithm and Canny edge detection technology, high-precision size measurement is achieved.

Benefits of technology

It improves the accuracy and efficiency of slider size measurement, reduces measurement errors caused by light fluctuations and camera shake, and meets the high-precision size measurement requirements of complex-shaped sliders.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119984033A_ABST
    Figure CN119984033A_ABST
Patent Text Reader

Abstract

A method for measuring the size of a slide block of a guide rail with a complex shape based on intelligent vision belongs to the field of machine vision, and comprises the following steps: DXF file data acquisition: reading by using Python; image acquisition and preprocessing: acquiring image data in real time by using an industrial camera, and performing image preprocessing; hole detection and measurement: adopting a Hough transform algorithm to realize sliding block hole detection, introducing a sub-pixel counting method to improve the algorithm, and realizing aperture high-precision measurement; edge line detection and measurement: extracting edge and line segment features of the sliding block image by adopting Canny edge detection and LSD line segment detection technologies, automatically removing invalid line segments, determining an optimal fitting line segment, and realizing accurate detection and measurement of a target edge line; and detection and measurement result visualization: displaying a sliding block size measurement result in an image, comparing the sliding block size measurement result with a standard parameter of a DXF file, judging the qualification of the sliding block, constructing a visual interface by adopting Pyside2 to record the measurement result, and supporting a plurality of input source detection functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of machine vision, and in particular to a method for measuring the dimensions of a guide rail slider with a complex shape based on intelligent vision. Background Art

[0002] As a key component in the field of mechanical manufacturing and automated production, the importance of guide rail sliders is self-evident. With the continuous improvement of industrial manufacturing technology, the requirements for the processing accuracy of parts are becoming increasingly stringent; the slider moves along the preset track in the guide rail system, and is responsible for the accurate positioning of parts or equipment, which puts forward higher standards for the processing quality of the slider, and the shaping and positioning dimensional errors must be strictly controlled to ensure its high-precision motion characteristics. In view of this, strict dimensional inspection of the processed slider is a necessary link, aiming to eliminate unqualified products and ensure product quality.

[0003] However, the current slider size measurement generally adopts traditional manual methods, such as vernier calipers and micrometers. Although the above methods basically meet the product tolerance requirements in terms of accuracy, they have disadvantages such as time-consuming and labor-intensive, low efficiency, and high labor costs, which are difficult to match the efficiency requirements of large-scale production of sliders.

[0004] In order to overcome the above limitations, the introduction of machine vision technology in the field of slider size measurement has become an effective way to improve production efficiency. As a non-contact measurement method, this technology not only significantly improves measurement efficiency, but also avoids the surface damage of the slider that may be caused by contact measurement. It is of great significance to ensure product quality and reduce production costs, and is an important manifestation of the intelligent transformation of modern manufacturing industry.

[0005] Traditional visual measurement methods are only applicable to workpieces with simple appearance and structure and low precision requirements, and the algorithm has weak anti-interference ability. The slider is easily affected by the surrounding lighting conditions and the imaging quality of the camera itself during the measurement process, which leads to large fluctuations in the error value of the measurement result. The algorithm accuracy and running speed are generally low, and the robustness is poor. In severe cases, misjudgment may occur, resulting in product waste. It is difficult to meet the high-precision dimensional measurement needs of sliders with complex appearances. Summary of the invention

[0006] In view of the technical problems existing in the prior art, the purpose of the present invention is to provide a method for measuring the dimensions of a guide rail slider with a complex shape based on intelligent vision, applying machine vision technology to the field of non-contact measurement of slider dimensions, with the aim of solving the problem of poor measurement accuracy of sliders with complex shapes when light fluctuations and slight camera shake interfere with imaging.

[0007] In order to achieve the above object, the present invention adopts the following technical solution:

[0008] A method for measuring the size of a guide rail slider with a complex shape based on intelligent vision comprises the following steps:

[0009] S1. DXF file data acquisition: Use the ezdxf library in the Python programming language to automatically acquire DXF drawing data, automatically parse the DXF file, and use the OpenCV library to draw images for visualization;

[0010] S2, image acquisition and preprocessing of the guide rail slider to be tested;

[0011] S3, hole detection and measurement, using sub-pixel counting technology to optimize the circle fitting method and obtain sub-pixel level edge detection accuracy;

[0012] S4, edge detection and measurement, automatically remove invalid line segments, determine the best fitting line segments, and achieve accurate extraction of target edges;

[0013] S5. Visualization of detection and measurement results. Calculate the difference between the standard slider DXF value in step S1 and the parameters obtained in steps S3 and S4 as the deviation value, and compare it with the tolerance requirement. If the deviation value is within the tolerance, the slider is qualified, otherwise it is unqualified. Use Pyside2 to build a visualization interface to present real-time visualization information of image processing, measurement results and key indicators at each stage of detection.

[0014] Preferably, step S1 comprises the following steps:

[0015] S11, using the ezdxf library in the Python programming language to read the standard slider DXF file, and traverse all entities in the model space, and extract the design information of the circle radius, circle center coordinates, straight line end point coordinates, arc radius, arc center coordinates, and arc rotation starting angle according to the standard slider feature type;

[0016] S12, determining the edge lines and holes to be measured according to the relative position relationship of each element of the standard slider and numbering them;

[0017] S13, reading various standard parameters and tolerance requirements of the elements to be measured and storing them in a dictionary, including hole radius, positioning dimensions of holes and edges, and numbering the elements to be measured;

[0018] S14. Calculate the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system; assume that A is the image pixel coordinate system and B is the part coordinate system. The two are associated only through translation and rotation, and do not involve scaling. Therefore, the translation matrix T and the rotation matrix R between the two coordinate systems are:

[0019]

[0020] Where, (x0, y0): the coordinates of the origin of the part coordinate system in the image pixel coordinate system, where the origin of the part coordinate system is the intersection of the left line and the upper line in the front view, and the intersection of the left line and the lower line in the top view; θ: the rotation angle, that is, the angle from the x-axis of the pixel coordinate system to the x-axis of the part coordinate system, where the x-axis of the part coordinate system is the upper and lower lines in the front and top views respectively;

[0021] The above two matrices are combined into a homogeneous transformation matrix M = T × R, and the coordinates P of the image pixel coordinate system are A =(x A ,y A , 1) Convert to coordinate P in the part coordinate system B =(x B ,y B , 1), expressed as:

[0022] P B =M×P A

[0023] Right now:

[0024]

[0025] According to the above coordinate transformation principle, the pixel coordinates of the key points of the slider in the image coordinate system are converted into the corresponding coordinates of the part coordinate system and stored in the dictionary. The key points of the slider include the center of the circle, the center of the arc, and the two end points of the edge line.

[0026] S15. Use the OpenCV library to draw the DXF file design information and the elements and parameters to be measured into the image for visualization; calculate the relative position and size of each element, and reasonably set the position and scaling factor of each element in the image to avoid overlap, confusion, and problems such as occupying too large or too small an image area; use different colors, line types, and marks to distinguish different types of elements and parameters to improve recognition.

[0027] Preferably, step S2 comprises the following steps:

[0028] S21. Build a hardware platform for slider image acquisition, place the industrial camera and light source parallel to and directly above the slider, make the imaging plane parallel to the slider measurement surface, set a pure white background, and acquire a color image of the slider to be tested;

[0029] S22, extracting corners of the slider image using Harris corner detection algorithm;

[0030] S23, using a k-means clustering algorithm to calculate the area with the largest corner point density as the area where the slider is located, and cutting the area as the area to be tested for detecting the elements to be tested and measuring the size of the slider;

[0031] S24. Use OpenCV to calibrate the camera and obtain the intrinsic parameter matrix and distortion coefficient. Use the built-in findChessboardCorners function of OpenCV to extract the pixel coordinates of the calibration board corner points for solving the camera's internal and external parameters. Use the calibrateCamera function to solve the camera's internal distortion coefficients based on the proposed corner point coordinates and the least squares optimization algorithm. The camera's internal parameters include focal length f, pixel physical size (d x ,d y ), pixel coordinates of the center point of the image (u0, v0), the distortion coefficients include radial distortion coefficients (k1, k2, k3) and tangential distortion coefficients (p1, p2);

[0032] S25, using the distortion coefficient in the camera to perform distortion correction on the acquired slider image, eliminating image distortion, and ensuring that the image geometric information can accurately reflect the actual object size; the radial distortion correction calculation process is as follows:

[0033] x corrected =x distorted (1+k1r 2 +k2r 4 +k3r 6 )

[0034] y corrected =y distorted (1+k1r 2 +k2r 4 +k3r 6 )

[0035] In the formula, x corrected ,y corrected : coordinates of the point in the corrected image; x distorted ,y distorted : coordinates of distorted image points; k1, k2, k3: radial distortion coefficients; r: distance between the point and the image center;

[0036] For tangential distortion correction:

[0037] x corrected =x distorted [2p1x distorted y distorted +p2(r 2 +2x distorted 2 )]

[0038] y corrected =y distorted [p1(r 2 +2y distorted 2 )+2p2x distorted y distorted]

[0039] Where, p1, p2: tangential distortion coefficients;

[0040] S26, converting the distortion-corrected image into a single-channel grayscale image;

[0041] S27, using the spatial proximity and pixel value similarity in edge-preserving filtering to eliminate the internal noise of the image, highlight the edge information of the slider, and then retain the complete complex shape features of the slider to improve the overall quality of the slider image; the calculation process is as follows: first, set the spatial domain standard deviation σ d is 7, and the range standard deviation is σ r is 100, the neighborhood size is 9×9, where the neighborhood is an area within a square or circle, and then the spatial domain weight determined by the Euclidean distance of the pixel position is calculated:

[0042]

[0043] Where, p(k,l): coordinates of the center point of the neighborhood; q(i,j): coordinates of pixels in the neighborhood except the center point;

[0044] Next, calculate the range weight determined by the pixel value difference:

[0045]

[0046] Where, f(i,j), f(k,l): pixel values ​​at corresponding positions in the image;

[0047] Multiply the above two weights to output the weight coefficient of the edge-preserving filter:

[0048]

[0049]

[0050] S28, use the normalized weights to perform weighted averaging on all pixels in the neighborhood, and output the filtered pixel value:

[0051]

[0052] Applying a filter to the slider image can ensure that the change of the pixel value far from the edge does not interfere with the edge pixel value, thereby effectively suppressing the internal and external noise of the slider.

[0053] Preferably, step S3 comprises the following steps:

[0054] S31, using the Hough transform method to detect the preprocessed slider image to obtain an image containing a circle element area;

[0055] S32, according to the pixel radius and position information of the slider hole, remove the redundant circles, and perform secondary circle detection on the area where the retained circles are located to accurately determine the slider hole area; this area is used as the region of interest ROI closest to the slider hole to achieve slider hole positioning, and the pixel coordinates and radius of the corresponding circle center are recorded, and at the same time, each ROI is numbered;

[0056] S33. The sub-pixel counting method is used to improve the Hough transform algorithm. The hole radius is estimated by accurately counting the sub-pixel area of ​​the target hole area, thereby improving the measurement accuracy. The hole ROI to be measured is subdivided into three sub-areas: A, B, and C. Area A is the shadow area inside the slider hole, which contains black pixels and represents the complete part of the hole. Area B is the bright area outside the slider hole, which is mainly white pixels and is not included in the measurement range. Area C is a transition zone, located between A and B, and contains blurred pixels caused by camera focus errors. Its pixel value is also between A and B, and smoothly transitions along the direction of the two areas. The pixel area of ​​the hole is determined by a comprehensive calculation of the pixel areas of areas A and C according to a specific weight ratio, as shown in the following formula:

[0057] Area=Area A +Area C *t

[0058] Where, Area: hole pixel area; Area A 、Area C : Pixel area of ​​regions A and C; t: Weight coefficient, the value varies depending on the pixel position in region C, ranging from 0 to 1. The larger the value, the greater the overall contribution of the pixel to the slider hole area;

[0059] Among them, the calculation method of the contribution of each pixel position in the A and C areas to the pixel area of ​​the slider hole is:

[0060]

[0061]

[0062] In the formula, I A (i,j),I C (i, j): the contribution of the pixel at (i, j) to the pixel area of ​​the slider hole, which has been normalized between 0 and 1; I(i, j): the pixel value at (i, j); th L ,th H : Boundary thresholds between regions A and C and between regions B and C;

[0063] S34, sum up the contribution values ​​calculated from each pixel in the A and C regions, and further obtain the sub-pixel area of ​​the slider hole as:

[0064]

[0065] S35, using a radius measurement method based on pixel area to obtain the pixel radius of the slider hole, as shown in the following formula:

[0066]

[0067] Using the above method to calculate the pixel radius of the slider hole can achieve more accurate measurement and minimize the influence of noise interference in the blurred area of ​​the hole edge;

[0068] S36, storing the calculated hole pixel radius and hole center pixel coordinates into a dictionary.

[0069] Preferably, step S4 comprises the following steps:

[0070] S41, using the Canny edge detection technology to extract the edge features of the preprocessed slider image; then, calculating the gradient values ​​of each pixel of the image on the x-axis and the y-axis, the gradient value directly reflects the rate and direction of change of the gray value of the image; and further determining the direction in which the gray value changes most dramatically, that is, the direction perpendicular to the edge of the slider contour, the specific calculation process is shown in the following formula:

[0071]

[0072] θ(i,j)=arctan(Q(i,j) / P(i,j))

[0073] Where, P(i,j), Q(i,j): the amplitude of the image pixel along the x and y directions, M(i,j) is the synthesis of the two, that is, the gradient size; f(i,j): the gray value of the pixel at the (i,j) coordinate; θ: the gradient direction expressed as an angle;

[0074] S42, performing non-maximum suppression processing on the calculated gradient to improve the contour clarity and eliminate redundant edge points; in this process, a linear interpolation method is used to calculate the gradient value of the intersection point c and its eight neighborhoods:

[0075] w=distance(p,g2) / distance(g1,g2)

[0076] M(p)=w×M(g2)+(1-w)×M(g1)

[0077] Where, M: gradient value; w: proportional coefficient; g: i : eight neighborhood endpoints; distance: the distance formula between two points; if M(c)>=M(p), then c is the maximum value, that is, the edge point;

[0078] S43, using a line segment detector to fit and extract all line segments in the edge image, forming a line segment set including line segment geometric features, and storing the line segment set in a line segment list data structure, wherein the line segment geometric features include endpoint coordinates, direction, and length; if the number of detected line segments does not meet the standard or the line segment geometric attributes, i.e., direction and length, deviate from expectations, iteratively adjusting the line segment fitting parameters to enhance the sensitivity and accuracy of line segment detection until a line segment detection result that meets the requirements is obtained;

[0079] S44. When processing the slider image line segment cluster data, accurately extract the target edge line of the complex shape slider.

[0080] Preferably, step S44 includes the following steps:

[0081] S441, line segment screening; traversing the line segment cluster, checking whether the coordinates of the midpoint and the endpoint of each line segment are located in the vicinity of the image slider; at the same time, evaluating the length of the line segment, and eliminating the line segments that are too short and cannot provide valid information;

[0082] S442, line segment feature extraction and direction classification; feature extraction is performed on the line segments retained after screening; each line segment is represented by a specific number, and its length, angle, endpoint and midpoint coordinates are recorded; based on the angle feature, the line segments are divided into two groups: a horizontal line group and a vertical line group, wherein the angle of the horizontal line group is between -45.0° and 45.0°, and the angle of the vertical line group is between 45.0° and 90.0° or -90.0° and -45.0°;

[0083] S443, determining the number of cluster centers; determining the k value, i.e., the number of cluster centers, before using the k-means clustering algorithm;

[0084] S444, line segment clustering and optimal cluster determination; based on the k value determined above and the extracted line segment features, k-means clustering is performed to further divide the line segment cluster into multiple clusters, each cluster corresponding to a sideline in the slider image; after clustering is completed, the line segments in each cluster are compared with the target sideline length and relative position relationship, and the cluster with the highest overlap with the target sideline is determined as the optimal cluster;

[0085] S445, optimal cluster line segment fitting and target edge determination; traverse the line segments in the optimal cluster, record the coordinate values ​​of their respective two end points, form the subsequent straight line fitting data source, use the least squares method to fit the coordinate points of the optimal cluster discontinuous straight line segments, and use the minimized sum of squares of the error to find the best function parameters of the data, and finally obtain a best fitting straight line, which is used as the result of the target edge; in this step, it is necessary to find a straight line with the minimum total error between all coordinate points, that is, the sum of squares of the vertical distances from the point to the straight line, and its equation is as follows:

[0086] y=mx+b

[0087] In the formula, m: slope; b: intercept;

[0088] In order to find the best fit line, we need to calculate the slope m and intercept b. First, we calculate the average values ​​of x and y, which are respectively and The slope m is calculated by the following formula:

[0089]

[0090] Where n: number of coordinate points; (x i ,y i ): coordinate values; The average of x and y;

[0091] Next, calculate the intercept b using the following formula:

[0092]

[0093] Through the above calculation method, a best fitting straight line equation y=mx+b is obtained;

[0094] In addition, the two endpoints of the straight line segment are determined according to the distribution of the coordinate points and the direction of the straight line segment; the minimum and maximum x values ​​of the coordinate points, as well as the minimum and maximum y values, are found to intercept the corresponding part of the straight line equation y=mx+b as the best fitting straight line segment, that is, the target edge detection result;

[0095] S446. Number the line segments whose lengths and positions meet the requirements, and store their lengths and endpoint coordinate pixel values ​​in a dictionary for subsequent analysis.

[0096] Preferably, step S5 comprises the following steps:

[0097] S51, in step S1, the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system is calculated, the pixel coordinates of the key points of the slider are converted into corresponding coordinates in the part coordinate system, and the coordinates are stored in the dictionary;

[0098] S52, calculating the pixel location size of each key point of each element to be measured based on the pixel coordinates;

[0099] S53, using a vernier caliper to measure the actual parameter values ​​of each element to be measured, and combining the obtained pixel parameters of the hole to be measured and the edge line to be measured to calculate the conversion formula between the two:

[0100]

[0101] Where, k is the average pixel conversion ratio, that is, the actual size value represented by the unit pixel, including length, diameter and coordinate position, in units of mm / pixel; n is the number of slider image detections; d ...r ,d pixel : The actual size of the slider and the pixel size obtained by fitting;

[0102] S54, converting the shaping and positioning pixel parameters of each element to be measured in the image of the slider to be measured into actual parameters, and visualizing the dimension measurement results; superimposing the shaping and positioning dimensions of the edge line and circle to be measured on the slider image, and comparing them with the DXF value of the standard slider, calculating the deviation value between the two, and judging whether the slider is a qualified product according to the tolerance requirements;

[0103] S55. Use Pyside2 to build a visualization interface, create an exe executable program, visualize the measurement process, and record the generated measurement results.

[0104] Preferably, the step S55 includes:

[0105] S551. The left area of ​​the main interface is the input source button. There are three main function buttons arranged from top to bottom: "Image Source", "Video Source" and "Camera Source". They correspond to different input sources, namely static images, dynamic videos and pictures captured by real-time cameras. They only differ in input sources, while the core algorithms and processing procedures called to perform measurement tasks are consistent. Users can select the most appropriate input source for measurement according to actual needs.

[0106] S552. Trigger the function button at the bottom center of the main interface to enable multiple functions. "DXF file reading" is used to load local DXF files as a measurement reference. Activate the "Get and detect the source to be measured" function, and the user can choose to load local slider images or video files for frame-by-frame analysis, or detect the dynamic images captured by the camera in real time. During the detection process, click the "Detection Process" button, and the system will display the image processing visualization results of each stage of the detection in real time, including DXF files, input sources, corner point detection, area to be measured, grayscale conversion, filtering, edge detection, circle element detection, hole ROI to be measured, line segment fitting, target edge detection results, and hole and edge detection results. Test results; Activate the "Key point coordinate measurement results" function, the main interface will mark the key point positions measured based on the DXF file and the slider image in the image, and display the coordinate calculation results, including the actual coordinate standard value and measured value in mm; Click the "Dimension measurement results" button, the system will mark the number, standard value, tolerance zone, measured value and deviation value of the dimensions to be measured in the slider image one by one, and mark the qualified and unqualified dimensions in green and red respectively; In addition, the DXF file visualization information is superimposed on the measurement result image for intuitive comparison; Users can click the "Start / Pause" button at any time to start or interrupt the current inspection and measurement process;

[0107] S553. The right area of ​​the main interface displays the running time and key indicators of the current image detection; the coordinate measurement result label lists in detail the key point numbers, coordinate standard values, and actual coordinate measurement values ​​of the image slider to be tested obtained from the standard slider DXF file in the form of a list; the dimension measurement result label lists the number, standard value, tolerance range, actual measurement value, deviation value and qualified judgment result of each dimension to be tested, and the qualified and unqualified dimensions are marked as "good" and "bad" respectively; the system displays the final state result of the dimension comparison of the slider to be tested in real time in the lower right corner of the main interface. The result is comprehensively judged based on the degree of fit between the dimensions of all elements to be tested and the requirements of the standard DXF file; only when all elements meet the standards, the slider is identified as a qualified product by the system; this judgment is a key indicator, which comprehensively reflects the previous dimension measurement results and directly reflects the final quality of the slider product;

[0108] S554. When only one of the options "DXF Visualization" and "Measurement Result Visualization" on the right is selected, the system main interface displays the DXF design data visualization and the annotations of each measurement result on the slider image respectively; if both are selected, the system will superimpose the above two types of images for intuitive comparison; if the "Optimal Result" option is checked, the system will calculate the average measurement value of multiple frames of images of the slider to be measured to enhance measurement accuracy and stability; in addition, by enabling the "Save Result" function, the input image, measurement result image and key parameter information can be saved as a txt file to provide a basis for measurement and facilitate subsequent analysis and archiving.

[0109] The principle of the present invention is to achieve fast and accurate non-contact dimension measurement on the slider automation production line; the method includes five main steps: DXF file data acquisition: using Python to read the standard slider DXF file data; image acquisition and preprocessing of the guide rail slider to be tested: using an industrial camera and under specific light source conditions to collect the image data of the slider to be tested in real time, and perform a series of image preprocessing operations on it; hole detection and measurement: using the Hough transform algorithm to realize slider hole detection, and introducing the sub-pixel counting method to improve the algorithm to achieve high-precision aperture measurement; edge line detection and measurement: using Canny edge detection and LSD line segment detection technology to extract the edge and line segment features of the slider image, and proposing a line segment cluster processing strategy to automatically eliminate invalid line segments, determine the best fitting line segment, and achieve accurate detection and measurement of the target edge line; visualization of detection and measurement results: displaying the slider size measurement results in the image, and comparing them with the standard parameters of the DXF file to judge the slider eligibility. At the same time, using Pyside2 to build a visualization interface to record the measurement results, supporting multiple input source detection functions.

[0110] The present invention has the following advantages:

[0111] 1. Automatic acquisition of slider processing DXF drawing data, high production efficiency: The present invention introduces the ezdxf library in the Python programming language in the link of obtaining the standard size and tolerance requirements of the slider, which can directly read and analyze the detailed design data in the slider DXF file, including geometric elements and their sizes; through automatic parsing of DXF files, the tedious process of manual data extraction is avoided, and the errors caused by human factors are significantly reduced; in addition, the automation level of the production process is greatly improved.

[0112] 2. The slider hole measurement link introduces a sub-pixel counting method to improve the Hough transform algorithm and improve the detection accuracy of the blurred hole edge: Because the camera cannot achieve accurate focus, a blurring effect occurs in the area near the edge of the slider hole. Therefore, the present invention introduces a sub-pixel counting technology to optimize the circle fitting method in this link to obtain sub-pixel level edge detection accuracy, effectively reducing the measurement error introduced by the change of pixel grayscale value and pixel size limitation in the transition area.

[0113] 3. A line segment cluster processing strategy is proposed in the slider edge measurement link to accurately extract the target edge of the complex-shaped slider: this strategy automatically eliminates invalid line segments and determines the best fitting line segment through the steps of line segment screening, line segment feature extraction and direction classification, determination of the number of cluster centers, line segment clustering and optimal cluster determination, optimal cluster line segment fitting and target edge determination, thereby achieving accurate extraction of the target edge.

[0114] 4. An intuitive, concise and fully functional visual interface has been built to facilitate engineering applications: Pyside2 is used for graphical interface development, so that the computer is separated from the source code environment and runs the exe program independently; users only need to perform simple operations on various controls to achieve automatic dimension measurement, and the encapsulated program will automatically perform complex calculations and output measurement results. The program has complete functions and a user-friendly operation process, which is convenient for users to debug. BRIEF DESCRIPTION OF THE DRAWINGS

[0115] Figure 1 The figure is a flow chart of a method for measuring the dimensions of a guide rail slider with a complex shape based on intelligent vision.

[0116] Figure 2 Visualize the renderings for DXF files.

[0117] Figure 3 Schematic diagram for building the image acquisition hardware platform.

[0118] Figure 4 This is the corner detection effect diagram.

[0119] Figure 5 This is the filtering effect diagram.

[0120] Figure 6 This is the effect diagram of circle element detection.

[0121] Figure 7 Filter the resulting graph for extra circle elements.

[0122] Figure 8 This is the edge detection effect diagram.

[0123] Fig. 9 This is the effect diagram of line segment detection.

[0124] Fig.10 This is the target edge detection result diagram.

[0125] Fig.11 Visualize the size measurements.

[0126] Fig.12 This is a visual interface diagram of the detection process.

[0127] Fig.13 This is a visualization interface diagram for measuring key point coordinates.

[0128] Fig.14 This is a visualization interface diagram for size measurement. DETAILED DESCRIPTION

[0129] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0130] See also Figure 1-Figure 14 , the present invention provides a technical solution.

[0131] The present invention provides a method for measuring the dimensions of a guide rail slider with a complex shape based on intelligent vision, and applies machine vision technology to the field of non-contact measurement of slider dimensions. The purpose of the method is to solve the problem of poor measurement accuracy of sliders with complex shapes when imaging is disturbed by light fluctuations and slight camera shake.

[0132] like Figure 1 As shown, the method comprises the following steps:

[0133] S1. DXF file data acquisition: Use the ezdxf library in the Python programming language to automatically acquire DXF drawing data, automatically parse the DXF file, and use the OpenCV library to draw images for visualization;

[0134] S2, image acquisition and preprocessing of the guide rail slider to be tested;

[0135] S3, hole detection and measurement, using sub-pixel counting technology to optimize the circle fitting method and obtain sub-pixel level edge detection accuracy;

[0136] S4, edge detection and measurement, automatically remove invalid line segments, determine the best fitting line segments, and achieve accurate extraction of target edges;

[0137] S5. Visualization of detection and measurement results. Calculate the difference between the standard slider DXF value in step S1 and the parameters obtained in steps S3 and S4 as the deviation value, and compare it with the tolerance requirement. If the deviation value is within the tolerance, the slider is qualified, otherwise it is unqualified. Use Pyside2 to build a visualization interface to present real-time visualization information of image processing, measurement results and key indicators at each stage of detection.

[0138] The step S1 comprises the following steps:

[0139] S11. Use the ezdxf library in the Python programming language to read the standard slider DXF file, traverse all entities in the model space, and extract the included circle radius, circle center coordinates, line end point coordinates and arc radius, arc center coordinates, and arc rotation start angle design information according to the standard slider feature type (CIRCLE, LINE, ARC);

[0140] S12, determining and numbering the edges and holes to be measured according to the relative position relationship of each element of the standard slider, the elements to be measured in the front view are 7 edges and 8 holes, and the elements to be measured in the top view are 4 edges and 4 holes;

[0141] S13, read various standard parameters and tolerance requirements of the elements to be measured and store them in the dictionary, including hole radius, positioning dimensions of holes and edges, and number the elements to be measured; among them, the dimensions to be measured in the front view are 8 hole radii (r1-r4, R1-R4), 10 positioning dimensions (l1-l10); the dimensions to be measured in the top view are 4 hole radii (R1-R4), 6 positioning dimensions (W, L, l1-l4);

[0142] S14. Calculate the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system; assume that A is the image pixel coordinate system and B is the part coordinate system. The two are associated only through translation and rotation, and do not involve scaling. Therefore, the translation matrix T and the rotation matrix R between the two coordinate systems are:

[0143]

[0144] Where, (x0, y0): the coordinates of the origin of the part coordinate system in the image pixel coordinate system, where the origin of the part coordinate system is the intersection of the left line and the upper line in the front view, and the intersection of the left line and the lower line in the top view; θ: the rotation angle, that is, the angle from the x-axis of the pixel coordinate system to the x-axis of the part coordinate system, where the x-axis of the part coordinate system is the upper and lower lines in the front and top views respectively;

[0145] The above two matrices are combined into a homogeneous transformation matrix M = T × R, and the coordinates P of the image pixel coordinate system are A =(x A ,y A , 1) Convert to coordinate P in the part coordinate system B =(x B ,y B , 1), expressed as:

[0146] P B =M×P A

[0147] Right now:

[0148]

[0149] According to the above coordinate transformation principle, the pixel coordinates of the key points of the slider in the image coordinate system are converted into the corresponding coordinates of the part coordinate system and stored in the dictionary. The key points of the slider include the center of the circle, the center of the arc, and the two end points of the edge line.

[0150] S15. Use the OpenCV library to draw the DXF file design information and the elements and parameters to be measured into the image to achieve visualization, such as Figure 2 As shown; calculate the relative position and size of each element, reasonably set the position and scaling factor of each element in the image to avoid overlapping, confusion, and occupying too large or too small an image area; use different colors, line types, and marks to distinguish different types of elements and parameters to improve recognition.

[0151] The step S2 comprises the following steps:

[0152] S21. Build a slider image acquisition hardware platform ( Figure 3 ), place an industrial camera with model MV-CA050-11UM and a resolution of 2448×2048 (5 million pixels) and a white LED ring light source parallel to the slider and 200 mm above the slider, make the imaging plane parallel to the measurement surface of the slider, set a pure white background, and collect a color image of the slider to be tested;

[0153] S22, use Harris corner detection algorithm to extract corners of the slider image ( Figure 4), set the detection neighborhood size to 2, the Sobel operator size to 3, and the free parameter k to 0.04;

[0154] S23, using a k-means clustering algorithm to calculate the area with the largest corner point density as the area where the slider is located, and cutting the area as the area to be tested for detecting the elements to be tested and measuring the size of the slider;

[0155] S24. Use OpenCV to calibrate the camera and obtain the intrinsic parameter matrix and distortion coefficient. Make a set of chessboard calibration plate images with a grid size of 17mm×17mm and a grid number of 7×10. Use the camera to be calibrated to shoot the above images at different angles and positions, and ensure that the calibration plate is clearly visible in the image and occupies different areas of the image. Use the built-in findChessboardCorners function of OpenCV to extract the pixel coordinates of the corner points of the calibration plate for solving the camera's internal and external parameters. Use the calibrateCamera function to solve the camera's internal distortion coefficients based on the proposed corner point coordinates combined with the least squares optimization algorithm. The camera's internal parameters include focal length f, pixel physical size (d x ,d y ), pixel coordinates of the center point of the image (u0, v0), the distortion coefficients include radial distortion coefficients (k1, k2, k3) and tangential distortion coefficients (p1, p2);

[0156] S25. The collected slider image is subjected to distortion correction using the distortion coefficient in the camera to eliminate image distortion (radial distortion, tangential distortion) caused by physical factors such as the camera lens and sensor, and ensure that the image geometric information (length, width) can accurately reflect the actual object size. The radial distortion correction calculation process is as follows:

[0157] x corrected =x distorted (1+k1r 2 +k2r 4 +k3r 6 )

[0158] y corrected =y distorted (1+k1r 2 +k2r 4 +k3r 6 )

[0159] In the formula, x corrected ,y corrected : coordinates of the point in the corrected image; x distorted ,y distorted : coordinates of distorted image points; k1, k2, k3: radial distortion coefficients; r: distance between the point and the image center;

[0160] For tangential distortion correction:

[0161] x corrected =x distorted [2p1x distorted y distorted +p2(r 2 +2x distorted 2 )]

[0162] y corrected =y distorted [p1(r 2 +2y distorted 2 )+2p2x distorted y distorted ]

[0163] Where, p1, p2: tangential distortion coefficients;

[0164] S26, converting the distortion-corrected image into a single-channel grayscale image;

[0165] S27, using the spatial proximity and pixel value similarity in edge-preserving filtering to eliminate the internal noise of the image, highlight the edge information of the slider, and thus retain the complete complex shape features of the slider, thereby improving the overall quality of the slider image ( Figure 5 ); The calculation process is as follows: First, set the spatial domain standard deviation σ d is 7, and the range standard deviation is σ r is 100, the neighborhood size is 9×9, where the neighborhood is an area within a square or circle, and then the spatial domain weight determined by the Euclidean distance of the pixel position is calculated:

[0166]

[0167] Where, p(k,l): coordinates of the center point of the neighborhood; q(i,j): coordinates of pixels in the neighborhood except the center point;

[0168] Next, calculate the range weight determined by the pixel value difference:

[0169]

[0170] Where, f(i,j), f(k,l): pixel values ​​at corresponding positions in the image;

[0171] Multiply the above two weights to output the weight coefficient of the edge-preserving filter:

[0172]

[0173] S28, use the normalized weights to perform weighted averaging on all pixels in the neighborhood, and output the filtered pixel value:

[0174]

[0175] Applying a filter to the slider image can ensure that the change of the pixel value far from the edge does not interfere with the edge pixel value, thereby effectively suppressing the internal and external noise of the slider.

[0176] The step S3 comprises the following steps:

[0177] S31, using the Hough transform method to detect the pre-processed slider image, and obtain an image containing a circle element area ( Figure 6 ); the high threshold and accumulator threshold of the edge detector are 150 and 30 respectively, and the detection radius range is 0px to 80px; then, the detection result is judged, if the required number of circles is not detected (the number of circles in the front and top views is 8 and 4 respectively), the above parameter range is continuously readjusted and expanded until the circle element is detected;

[0178] S32, according to the pixel radius and position information of the slider hole, remove the redundant circles, and perform secondary circle detection on the area where the retained circles are located to accurately determine the slider hole area; use this area as the region of interest ROI closest to the slider hole to achieve slider hole positioning, and record the pixel coordinates and radius of the corresponding circle center, and at the same time, number each ROI ( Figure 7 );

[0179] S33. The sub-pixel counting method is used to improve the Hough transform algorithm. The hole radius is estimated by accurately counting the sub-pixel area of ​​the target hole area, thereby improving the measurement accuracy. The hole ROI to be measured is subdivided into three sub-areas: A, B, and C. Area A is the shadow area inside the slider hole (the ROI boundary is shrunk by 1px), which contains black pixels and represents the complete part of the hole. Area B is the bright area outside the slider hole (the ROI boundary is expanded by 1px), which is mainly white pixels and is not included in the measurement range. Area C is a transition zone located between A and B, containing blurred pixels caused by camera focus errors, and its pixel value is also between A and B, and smoothly transitions along the direction of the two areas with a thickness of 1 to 3px. The pixel area of ​​the hole is determined by a comprehensive calculation of the pixel areas of areas A and C according to a specific weight ratio, as shown in the following formula:

[0180] Area=Area A +Area C *t

[0181] Where, Area: hole pixel area; Area A 、Area C : Pixel area of ​​regions A and C; t: Weight coefficient, the value varies depending on the pixel position in region C, ranging from 0 to 1. The larger the value, the greater the overall contribution of the pixel to the slider hole area;

[0182] Among them, the calculation method of the contribution of each pixel position in the A and C areas to the pixel area of ​​the slider hole is:

[0183]

[0184] In the formula, I A (i,j),I C (i, j): the contribution of the pixel at (i, j) to the pixel area of ​​the slider hole, which has been normalized between 0 and 1; I(i, j): the pixel value at (i, j); th L ,th H : Boundary thresholds between regions A and C and between regions B and C;

[0185] S34, sum up the contribution values ​​calculated from each pixel in the A and C regions, and further obtain the sub-pixel area of ​​the slider hole as:

[0186]

[0187] S35, using a radius measurement method based on pixel area to obtain the pixel radius of the slider hole, as shown in the following formula:

[0188]

[0189] Using the above method to calculate the pixel radius of the slider hole can achieve more accurate measurement and minimize the influence of noise interference in the blurred area of ​​the hole edge;

[0190] S36, storing the calculated hole pixel radius and hole center (key point) pixel coordinates into a dictionary.

[0191] The step S4 comprises the following steps:

[0192] S41, using Canny edge detection technology to extract edge features of the preprocessed slider image ( Figure 8 ); to ensure edge integrity and continuity, the high and low thresholds are set to 100 and 50 respectively; then, the gradient values ​​of each pixel of the image on the x-axis and y-axis are calculated. The gradient value directly reflects the rate and direction of change of the grayscale value of the image; and the direction in which the grayscale value changes most drastically is further determined, that is, the direction perpendicular to the edge of the slider contour. The specific calculation process is shown in the following formula:

[0193]

[0194] θ(i,j)=arctan(Q(i,j) / P(i,j))

[0195] Where, P(i,j), Q(i,j): the amplitude of the image pixel along the x and y directions, M(i,j) is the synthesis of the two, that is, the gradient size; f(i,j): the gray value of the pixel at the (i,j) coordinate; θ: the gradient direction expressed as an angle;

[0196] S42, performing non-maximum suppression processing on the calculated gradient to improve the contour clarity and eliminate redundant edge points; in this process, a linear interpolation method is used to calculate the gradient value of the intersection point c and its eight neighborhoods:

[0197] w=distance(p,g2) / distance(g1,g2)

[0198] M(p)=w×M(g2)+(1-w)×M(g1)

[0199] Where, M: gradient value; w: proportional coefficient; g: i : eight neighborhood endpoints; distance: the distance formula between two points; if M(c)>=M(p), then c is the maximum value, that is, the edge point;

[0200] S43, using a line segment detector (LSD) to fit and extract all line segments in the edge image ( Fig. 9 ), forming a line segment set containing line segment geometric features and storing them in a line segment list data structure. The line segment geometric features include endpoint coordinates, direction and length; if the number of detected line segments does not meet the standard or the line segment geometric properties, that is, the direction and length, deviate from expectations, the line segment fitting parameters (such as gradient calculation tolerance, region growth threshold, rectangle approximation accuracy, etc.) are iteratively adjusted to enhance the sensitivity and accuracy of line segment detection until a line segment detection result that meets the requirements is obtained;

[0201] S44. When processing the line segment cluster data of the slider image, a line segment cluster processing strategy is proposed to accurately extract the target edge line of the slider with a complex shape.

[0202] The line segment cluster processing strategy in step S44 includes the following steps:

[0203] S441, line segment screening; traverse the line segment cluster, check whether the midpoint and endpoint coordinates of each line segment are located in the vicinity of the image slider; at the same time, evaluate the line segment length, exclude the line segments with lengths less than 15px and 5px in the front view and top view respectively, so as to eliminate the line segments that are too short and cannot provide effective information, in order to reduce the complexity of subsequent processing and improve the measurement accuracy;

[0204] S442, line segment feature extraction and direction classification; feature extraction is performed on the line segments retained after screening; each line segment is represented by a specific number, and its length, angle, endpoint and midpoint coordinates are recorded; based on the angle feature, the line segments are divided into two groups: a horizontal line group and a vertical line group, wherein the angle of the horizontal line group is between -45.0° and 45.0°, and the angle of the vertical line group is between 45.0° and 90.0° or -90.0° and -45.0°;

[0205] S443, determining the number of cluster centers; determining the k value, i.e., the number of cluster centers, before using the k-means clustering algorithm; according to the characteristics of the front and top views of the guide rail slider, there are 3 and 2 horizontal sidelines, respectively, and 2 and 6 vertical sidelines, respectively; therefore, when clustering in the horizontal direction, the k value is set to 3 and 2, respectively, and when clustering in the vertical direction, the k value is set to 2 and 6; this setting ensures that the clustering result is completely consistent with the actual number of sidelines of the guide rail slider;

[0206] S444, line segment clustering and optimal cluster determination; based on the k value determined above and the extracted line segment features (midpoint coordinates and angles), k-means clustering is performed to further divide the line segment cluster into multiple clusters, each cluster corresponding to a sideline in the slider image; after clustering is completed, the line segments in each cluster are compared with the target sideline length (the deviation range is within ±5px) and the relative position relationship (the order relationship between the line segments), and the cluster with the highest overlap with the target sideline is determined as the optimal cluster;

[0207] S445, optimal cluster line segment fitting and target edge determination; traverse the line segments in the optimal cluster, record the coordinate values ​​of their respective two end points, form the subsequent straight line fitting data source, use the least squares method to fit the coordinate points of the optimal cluster discontinuous straight line segments, and use the minimized sum of squares of the error to find the best function parameters of the data, and finally obtain a best fitting straight line, which is used as the result of the target edge; in this step, it is necessary to find a straight line with the minimum total error between all coordinate points, that is, the sum of squares of the vertical distances from the point to the straight line, and its equation is as follows:

[0208] y=mx+b

[0209] In the formula, m: slope; b: intercept;

[0210] In order to find the best fit line, we need to calculate the slope m and intercept b. First, we calculate the average values ​​of x and y, which are respectively and The slope m is calculated by the following formula:

[0211]

[0212] Where n: number of coordinate points; (x i ,y i): coordinate values; The average of x and y;

[0213] Next, calculate the intercept b using the following formula:

[0214]

[0215] Through the above calculation method, a best fitting straight line equation y=mx+b is obtained;

[0216] In addition, the two endpoints of the straight line segment are determined according to the distribution of coordinate points and the direction of the straight line segment; the minimum and maximum x values ​​of the coordinate points, as well as the minimum and maximum y values, are found to intercept the corresponding part of the straight line equation y = mx + b as the best fitting straight line segment, that is, the target edge detection result ( Fig.10 );

[0217] S446. Number the line segments whose length and position meet the conditions, and store their lengths and endpoint (key point) coordinate pixel values ​​in a dictionary for subsequent analysis.

[0218] The step S5 comprises the following steps:

[0219] S51, in step S14 of step S1, the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system is calculated, and according to the coordinate transformation principle, the pixel coordinates of the key points of the slider are converted into corresponding coordinates in the part coordinate system, and stored in the dictionary;

[0220] S52, calculating the pixel location size of each key point of each element to be measured based on the pixel coordinates;

[0221] S53, using a vernier caliper with an accuracy of 0.02 mm to measure the actual parameter values ​​of each element to be measured, and combining the pixel parameters of the hole to be measured and the edge line to be measured obtained in the above steps to calculate the conversion formula between the two:

[0222]

[0223] Where, k is the average pixel conversion ratio, that is, the actual size value represented by the unit pixel, including length, diameter and coordinate position, in units of mm / pixel; n is the number of slider image detections; d ... r ,d pixel : The actual size of the slider and the pixel size obtained by fitting;

[0224] S54, converting the shaping and positioning pixel parameters of each element to be measured in the image of the slider to be measured into actual parameters, and visualizing the size measurement results ( Fig.11 ); superimpose the shape and positioning dimensions of the edge line and circle to be measured on the slider image, and compare them with the DXF value of the standard slider, calculate the deviation value between the two, and judge whether the slider is a qualified product according to the tolerance requirements;

[0225] S55, use Pyside2 to build a visual interface ( Figure 12-14 ), create an exe executable program to visualize the above measurement process and record the generated measurement results.

[0226] The step S55 comprises:

[0227] S551. The left area of ​​the main interface is the input source button. There are three main function buttons arranged from top to bottom: "Image Source", "Video Source" and "Camera Source". They correspond to different input sources, namely static images, dynamic videos and pictures captured by real-time cameras. They only differ in input sources, while the core algorithms and processing procedures called to perform measurement tasks are consistent. Users can select the most appropriate input source for measurement according to actual needs.

[0228] S552. Trigger the function button at the bottom center of the main interface to enable multiple functions. "DXF file reading" is used to load local DXF files as a measurement reference. Activate the "Get and detect the source to be measured" function, and the user can choose to load local slider images or video files for frame-by-frame analysis, or detect the dynamic images captured by the camera in real time. During the detection process, click the "Detection Process" button, and the system will display the image processing visualization results of each stage of the detection in real time ( Fig.12 ), including DXF file, input source, corner point detection, area to be measured, grayscale conversion, filtering, edge detection, circle element detection, hole ROI to be measured, line segment fitting, target edge detection results and hole and edge detection results; activate the "key point coordinate measurement results" function, the main interface will mark the key point positions measured based on the DXF file and slider image in the image, and display its coordinate calculation results, including the actual coordinate standard value and measured value in mm ( Fig.13 ); Click the "Dimension Measurement Result" button, and the system will mark the number, standard value, tolerance zone, measurement value and deviation value of the dimension to be measured in the slider image one by one, and mark the qualified and unqualified dimensions in green and red respectively; in addition, the DXF file visualization information (light blue line) is superimposed on the measurement result image for intuitive comparison ( Fig.14 ) The user can click the "Start / Pause" button at any time to start or interrupt the current detection and measurement process;

[0229] S553. The right area of ​​the main interface displays the running time and key indicators of the current image detection; the coordinate measurement result label lists in detail the key point numbers, coordinate standard values, and actual coordinate measurement values ​​of the image slider to be tested obtained from the standard slider DXF file in the form of a list; the dimension measurement result label lists the number, standard value, tolerance range, actual measurement value, deviation value and qualified judgment result of each dimension to be tested, and the qualified and unqualified dimensions are marked as "good" and "bad" respectively; the system displays the final state result of the dimension comparison of the slider to be tested in real time in the lower right corner of the main interface. The result is comprehensively judged based on the degree of fit between the dimensions of all elements to be tested and the requirements of the standard DXF file; only when all elements meet the standards, the slider is identified as a qualified product by the system; this judgment is a key indicator, which comprehensively reflects the previous dimension measurement results and directly reflects the final quality of the slider product;

[0230] S554. When only one of the options "DXF Visualization" and "Measurement Result Visualization" on the right is selected, the system main interface displays the DXF design data visualization and the annotations of each measurement result on the slider image respectively; if both are selected, the system will superimpose the above two types of images for intuitive comparison; if the "Optimal Result" option is checked, the system will calculate the average measurement value of multiple frames of images of the slider to be measured to enhance measurement accuracy and stability; in addition, by enabling the "Save Result" function, the input image, measurement result image and key parameter information can be saved as a txt file to provide a basis for measurement and facilitate subsequent analysis and archiving.

[0231] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A method for measuring the size of a guide rail slider with a complex shape based on intelligent vision, characterized in that: The following steps are involved: S1. DXF file data acquisition: Use the ezdxf library in the Python programming language to automatically acquire DXF drawing data, automatically parse the DXF file, and use the OpenCV library to draw images for visualization; S2, image acquisition and preprocessing of the guide rail slider to be tested; S3, hole detection and measurement, using sub-pixel counting technology to optimize the circle fitting method and obtain sub-pixel level edge detection accuracy; S4, edge detection and measurement, automatically remove invalid line segments, determine the best fitting line segments, and achieve accurate extraction of target edges; S5. Visualization of detection and measurement results. Calculate the difference between the standard slider DXF value in step S1 and the parameters obtained in steps S3 and S4 as the deviation value, and compare it with the tolerance requirement. If the deviation value is within the tolerance, the slider is qualified, otherwise it is unqualified. Use Pyside2 to build a visualization interface to present real-time visualization information of image processing, measurement results and key indicators at each stage of detection.

2. A method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 1, characterized in that: The step S1 comprises the following steps: S11, using the ezdxf library in the Python programming language to read the standard slider DXF file, and traverse all entities in the model space, and extract the design information of the circle radius, circle center coordinates, straight line end point coordinates, arc radius, arc center coordinates, and arc rotation starting angle according to the standard slider feature type; S12, determining the edge lines and holes to be measured according to the relative position relationship of each element of the standard slider and numbering them; S13, reading various standard parameters and tolerance requirements of the elements to be measured and storing them in a dictionary, including hole radius, positioning dimensions of holes and edges, and numbering the elements to be measured; S14. Calculate the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system; assume that A is the image pixel coordinate system and B is the part coordinate system. The two are associated only through translation and rotation, and do not involve scaling. Therefore, the translation matrix T and the rotation matrix R between the two coordinate systems are: Where, (x0, y0): the coordinates of the origin of the part coordinate system in the image pixel coordinate system, where the origin of the part coordinate system is the intersection of the left line and the upper line in the front view, and the intersection of the left line and the lower line in the top view; θ: rotation angle, that is, the angle from the x-axis of the pixel coordinate system to the x-axis of the part coordinate system, where the x-axis of the part coordinate system selects the upper and lower edges in the front and top views respectively; The above two matrices are combined into a homogeneous transformation matrix M = T × R, and the coordinates P of the image pixel coordinate system are A =(x A ,y A , 1) Convert to coordinate P in the part coordinate system B =(x B ,y B , 1), expressed as: P B =M×P A Right now: According to the above coordinate transformation principle, the pixel coordinates of the key points of the slider in the image coordinate system are converted into the corresponding coordinates of the part coordinate system and stored in the dictionary. The key points of the slider include the center of the circle, the center of the arc, and the two end points of the edge line. S15. Use the OpenCV library to draw the DXF file design information and the elements and parameters to be measured into the image for visualization; calculate the relative position and size of each element, and reasonably set the position and scaling factor of each element in the image to avoid overlap, confusion, and problems such as occupying too large or too small an image area; use different colors, line types, and marks to distinguish different types of elements and parameters to improve recognition.

3. The method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 1, characterized in that: The step S2 comprises the following steps: S21. Build a hardware platform for slider image acquisition, place the industrial camera and light source parallel to and directly above the slider, make the imaging plane parallel to the slider measurement surface, set a pure white background, and acquire a color image of the slider to be tested; S22, extracting corners of the slider image using Harris corner detection algorithm; S23, using a k-means clustering algorithm to calculate the area with the largest corner point density as the area where the slider is located, and cutting the area as the area to be tested for detecting the elements to be tested and measuring the size of the slider; S24, using OpenCV to calibrate the camera, obtain the intrinsic parameter matrix and distortion coefficient; using the built-in findChessboardCorners function of OpenCV to extract the pixel coordinates of the corner points of the calibration board, which are used to solve the internal and external parameters of the camera; Using the calibrateCamera function, according to the proposed corner point coordinates, combined with the least squares optimization algorithm, the camera internal distortion coefficient is solved. The camera internal parameters include focal length f, pixel physical size (d x d y ), pixel coordinates of the center point of the image (u0, v0), the distortion coefficients include radial distortion coefficients (k1, k2, k3) and tangential distortion coefficients (p1, p2); S25, using the distortion coefficient in the camera to perform distortion correction on the acquired slider image, eliminating image distortion, and ensuring that the image geometric information can accurately reflect the actual object size; the radial distortion correction calculation process is as follows: x corrected =x distorted (1+k1r 2 +k2r 4 +k3r 6 ) and corrected =and distorted (1+k1r 2 +k2r 4 +k3r 6 ) In the formula, x corrected ,y corrected : coordinates of the point in the corrected image; x distorted ,y distorted : coordinates of distorted image points; k1, k2, k3: radial distortion coefficients; r: distance between the point and the image center; For tangential distortion correction: x corrected =x distorted [2p1x distorted y distorted +p2(r 2 +2x distorted 2 )] y corrected =y distorted [p1(r 2 +2y distorted 2 )+2p2x distorted y distorted ] Where, p1, p2: tangential distortion coefficients; S26, converting the distortion-corrected image into a single-channel grayscale image; S27, using the spatial proximity and pixel value similarity in edge-preserving filtering to eliminate the internal noise of the image, highlight the edge information of the slider, and then retain the complete complex shape features of the slider to improve the overall quality of the slider image; the calculation process is as follows: first, set the spatial domain standard deviation σ d is 7, and the range standard deviation is σ r is 100, the neighborhood size is 9×9, where the neighborhood is an area within a square or circle, and then the spatial domain weight determined by the Euclidean distance of the pixel position is calculated: Where, p(k,l): coordinates of the center point of the neighborhood; q(i,j): coordinates of pixels in the neighborhood except the center point; Next, calculate the range weight determined by the pixel value difference: Where, f(i,j), f(k,l): pixel values ​​at corresponding positions in the image; Multiply the above two weights to output the weight coefficient of the edge-preserving filter: S28, use the normalized weights to perform weighted averaging on all pixels in the neighborhood, and output the filtered pixel value: Applying a filter to the slider image can ensure that the change of the pixel value far from the edge does not interfere with the edge pixel value, thereby effectively suppressing the internal and external noise of the slider.

4. The method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 1, characterized in that: The step S3 comprises the following steps: S31, using the Hough transform method to detect the preprocessed slider image to obtain an image containing a circle element area; S32, according to the pixel radius and position information of the slider hole, remove the redundant circles, and perform secondary circle detection on the area where the retained circles are located, so as to accurately determine the slider hole area; this area is used as the region of interest ROI closest to the slider hole to realize the positioning of the slider hole, and the pixel coordinates and radius of the corresponding circle center are recorded, and at the same time, each ROI is numbered; S33. The sub-pixel counting method is used to improve the Hough transform algorithm. The hole radius is estimated by accurately counting the sub-pixel area of ​​the target hole area, thereby improving the measurement accuracy. The hole ROI to be measured is subdivided into three sub-areas: A, B, and C. Area A is the shadow area inside the slider hole, which contains black pixels and represents the complete part of the hole. Area B is the bright area outside the slider hole, which is mainly white pixels and is not included in the measurement range. Area C is a transition zone, located between A and B, and contains blurred pixels caused by camera focus errors. Its pixel value is also between A and B, and smoothly transitions along the direction of the two areas. The pixel area of ​​the hole is determined by a comprehensive calculation of the pixel areas of areas A and C according to a specific weight ratio, as shown in the following formula: Area=Area A +Area C *t Where, Area: hole pixel area; Area A 、Area C : Pixel area of ​​regions A and C; t: weight coefficient, the value varies depending on the pixel position in area C, ranging from 0 to 1. The larger the value, the greater the overall contribution of the pixel to the slider hole area; Among them, the calculation method of the contribution of each pixel position in the A and C areas to the pixel area of ​​the slider hole is: In the formula, I A (i,j),I C (i, j): the contribution of the pixel at (i, j) to the pixel area of ​​the slider hole, which has been normalized between 0 and 1; I(i, j): the pixel value at (i, j); th L ,th H : Boundary thresholds between regions A and C and between regions B and C; S34, sum up the contribution values ​​calculated from each pixel in the A and C regions, and further obtain the sub-pixel area of ​​the slider hole as: S35, using a radius measurement method based on pixel area to obtain the pixel radius of the slider hole, as shown in the following formula: Using the above method to calculate the pixel radius of the slider hole can achieve more accurate measurement and minimize the influence of noise interference in the blurred area of ​​the hole edge; S36, storing the calculated hole pixel radius and hole center pixel coordinates into a dictionary.

5. The method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 1, characterized in that: The step S4 comprises the following steps: S41, using the Canny edge detection technology to extract the edge features of the preprocessed slider image; then, calculating the gradient values ​​of each pixel of the image on the x-axis and the y-axis, the gradient value directly reflects the rate and direction of change of the gray value of the image; and further determining the direction in which the gray value changes most dramatically, that is, the direction perpendicular to the edge of the slider contour, the specific calculation process is shown in the following formula: θ(i,j)=arctan(Q(i,j) / P(i,j)) Where, P(i,j), Q(i,j): the amplitude of the image pixel along the x and y directions, M(i,j) is the synthesis of the two, that is, the gradient size; f(i,j): the gray value of the pixel at the (i,j) coordinate; θ: gradient direction expressed as an angle; S42, performing non-maximum suppression processing on the calculated gradient to improve the contour clarity and eliminate redundant edge points; in this process, a linear interpolation method is used to calculate the gradient value of the intersection point c and its eight neighborhoods: w=distance(p,g2) / distance(g1,g2) M(p)=w×M(g2)+(1-w)×M(g1) Where, M: gradient value; w: proportionality coefficient; g i : Eight neighborhood endpoints; distance: the distance formula between two points; if M(c)>=M(p), then c is a maximum value, i.e. an edge point; S43, using a line segment detector to fit and extract all line segments in the edge image, forming a line segment set including line segment geometric features, and storing the line segment set in a line segment list data structure, wherein the line segment geometric features include endpoint coordinates, direction, and length; if the number of detected line segments does not meet the standard or the line segment geometric attributes, i.e., direction and length, deviate from expectations, iteratively adjusting the line segment fitting parameters to enhance the sensitivity and accuracy of line segment detection until a line segment detection result that meets the requirements is obtained; S44. When processing the slider image line segment cluster data, accurately extract the target edge line of the complex shape slider.

6. A method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 5, characterized in that: The step S44 comprises the following steps: S441, line segment screening; traversing the line segment cluster, checking whether the coordinates of the midpoint and the endpoint of each line segment are located in the vicinity of the image slider; at the same time, evaluating the length of the line segment, and eliminating the line segments that are too short and cannot provide valid information; S442, line segment feature extraction and direction classification; feature extraction is performed on the line segments retained after screening; each line segment is represented by a specific number, and its length, angle, endpoint and midpoint coordinates are recorded; based on the angle feature, the line segments are divided into two groups: a horizontal line group and a vertical line group, wherein the angle of the horizontal line group is between -45.0° and 45.0°, and the angle of the vertical line group is between 45.0° and 90.0° or -90.0° and -45.0°; S443, determining the number of cluster centers; determining the k value, i.e., the number of cluster centers, before using the k-means clustering algorithm; S444, line segment clustering and optimal cluster determination; based on the k value determined above and the extracted line segment features, k-means clustering is performed to further divide the line segment cluster into multiple clusters, each cluster corresponding to a sideline in the slider image; after clustering is completed, the line segments in each cluster are compared with the target sideline length and relative position relationship, and the cluster with the highest overlap with the target sideline is determined as the optimal cluster; S445, optimal cluster line segment fitting and target edge determination; traverse the line segments in the optimal cluster, record the coordinate values ​​of their respective two end points, form the subsequent straight line fitting data source, use the least squares method to fit the coordinate points of the optimal cluster discontinuous straight line segments, and use the minimized sum of squares of the error to find the best function parameters of the data, and finally obtain a best fitting straight line, which is used as the result of the target edge; in this step, it is necessary to find a straight line with the minimum total error between all coordinate points, that is, the sum of squares of the vertical distances from the point to the straight line, and its equation is as follows: y=mx+b Where, m: slope; b: intercept; In order to find the best fit line, we need to calculate the slope m and intercept b. First, we calculate the average values ​​of x and y, which are respectively and The slope m is calculated by the following formula: Where n: number of coordinate points; (x i ,y i ): coordinate values; The average of x and y; Next, calculate the intercept b using the following formula: Through the above calculation method, a best fitting straight line equation y=mx+b is obtained; In addition, the two endpoints of the straight line segment are determined according to the distribution of the coordinate points and the direction of the straight line segment; the minimum and maximum x values ​​of the coordinate points, as well as the minimum and maximum y values, are found to intercept the corresponding part of the straight line equation y=mx+b as the best fitting straight line segment, that is, the target edge detection result; S446. Number the line segments whose lengths and positions meet the requirements, and store their lengths and endpoint coordinate pixel values ​​into a dictionary for subsequent analysis.

7. The method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 1, characterized in that: The step S5 comprises the following steps: S51, in step S1, the homogeneous transformation matrix between the image pixel coordinate system and the part coordinate system is calculated, the pixel coordinates of the key points of the slider are converted into corresponding coordinates in the part coordinate system, and the coordinates are stored in the dictionary; S52, calculating the pixel location size of each key point of each element to be measured based on its pixel coordinates; S53, using a vernier caliper to measure the actual parameter values ​​of each element to be measured, and combining the obtained pixel parameters of the hole to be measured and the edge line to be measured to calculate the conversion formula between the two: Where, k is the average pixel conversion ratio, that is, the actual size value represented by the unit pixel, including length, diameter and coordinate position, in units of mm / pixel; n is the number of slider image detections; d ... r d pixel : The actual size of the slider and the pixel size obtained by fitting; S54, converting the shaping and positioning pixel parameters of each element to be measured in the image of the slider to be measured into actual parameters, and visualizing the dimension measurement results; superimposing the shaping and positioning dimensions of the edge line and circle to be measured on the slider image, and comparing them with the DXF value of the standard slider, calculating the deviation value between the two, and judging whether the slider is a qualified product according to the tolerance requirements; S55. Use Pyside2 to build a visualization interface, create an exe executable program, visualize the measurement process, and record the generated measurement results.

8. The method for measuring the size of a guide rail slider with a complex shape based on intelligent vision according to claim 7, characterized in that: The step S55 comprises: S551. The left area of ​​the main interface is the input source button, which has three main function buttons arranged from top to bottom: "Image Source", "Video Source" and "Camera Source". They correspond to different input sources, namely static images, dynamic videos and pictures captured by real-time cameras. They only differ in input sources, while the core algorithms and processing procedures used to perform measurement tasks are consistent. Users can select the most appropriate input source for measurement according to actual needs. S552. Trigger the function button at the bottom center of the main interface to enable multiple functions. "DXF file reading" is used to load local DXF files as a measurement reference. Activate the "Get and detect the source to be measured" function, and the user can choose to load local slider images or video files for frame-by-frame analysis, or detect the dynamic images captured by the camera in real time. During the detection process, click the "Detection Process" button, and the system will display the image processing visualization results of each stage of the detection in real time, including DXF files, input sources, corner point detection, area to be measured, grayscale conversion, filtering, edge detection, circle element detection, hole ROI to be measured, line segment fitting, target edge detection results, and hole and edge detection results. Test results; Activate the "Key point coordinate measurement results" function, the main interface will mark the key point positions measured based on the DXF file and the slider image in the image, and display the coordinate calculation results, including the actual coordinate standard value and measured value in mm; Click the "Dimension measurement results" button, the system will mark the number, standard value, tolerance zone, measured value and deviation value of the dimensions to be measured in the slider image one by one, and mark the qualified and unqualified dimensions in green and red respectively; In addition, the DXF file visualization information is superimposed on the measurement result image for intuitive comparison; Users can click the "Start / Pause" button at any time to start or interrupt the current inspection and measurement process; S553. The right area of ​​the main interface displays the running time and key indicators of the current image detection; the coordinate measurement result label lists in detail the key point numbers, coordinate standard values, and actual coordinate measurement values ​​of the image slider to be tested obtained from the standard slider DXF file in the form of a list; the dimension measurement result label lists the number, standard value, tolerance range, actual measurement value, deviation value and qualified judgment result of each dimension to be tested, and the qualified and unqualified dimensions are marked as "good" and "bad" respectively; the system displays the final state result of the dimension comparison of the slider to be tested in real time in the lower right corner of the main interface. The result is comprehensively judged based on the degree of fit between the dimensions of all elements to be tested and the requirements of the standard DXF file; only when all elements meet the standards, the slider is identified as a qualified product by the system; this judgment is a key indicator, which comprehensively reflects the previous dimension measurement results and directly reflects the final quality of the slider product; S554. When only one of the options "DXF Visualization" and "Measurement Result Visualization" on the right is selected, the system main interface displays the DXF design data visualization and the annotations of each measurement result on the slider image respectively; if both are selected, the system will superimpose the above two types of images for intuitive comparison; if the "Optimal Result" option is checked, the system will calculate the average measurement value of multiple frames of the slider to be measured to enhance the measurement accuracy and stability; in addition, by enabling the "Save Result" function, the input image, measurement result image and key parameter information can be saved as a txt file to provide a basis for measurement and facilitate subsequent analysis and archiving.

Citation Information

Cited By

  • Optical detection calibration method based on laser cross calibration method

    CN120558128A

  • Linear high-precision repositioning method based on Hough transform result and image sub-pixel edge point regression

    CN120765745A

  • High-precision line repositioning method based on hough transform result and image sub-pixel edge point regression

    CN120765745B

  • Laser processing method and system

    CN121091791A

  • Product assembly line automatic detection system based on visual identification

    CN121860921A