Sliding block size measuring method, device and equipment based on machine vision and medium

Through the slider size measurement method based on machine vision, camera calibration and sub-pixel edge detection are used to solve the problem of low slider size measurement accuracy in the prior art, and a high-precision and automated measurement process is realized.

CN119941667APending Publication Date: 2025-05-06SOUTH CHINA AGRICULTURAL UNIVERSITY
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510009298.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-03
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The prior art has problems such as low accuracy and complex operation in the measurement of slider size, which affects the accuracy of the measurement results.

Method used

Using a slider size measurement method based on machine vision, we can obtain the slider image and CAD model, detect edge points and fit them, and combine camera calibration and subpixel edge detection to achieve high-precision slider size measurement.

Benefits of technology

It improves the accuracy and efficiency of slider size measurement, reduces errors, and realizes automated measurement, which greatly improves measurement efficiency compared with traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119941667A_ABST
    Figure CN119941667A_ABST
Patent Text Reader

Abstract

The invention discloses a sliding block size measuring method, device and equipment based on machine vision and a storage medium. The sliding block size measuring method comprises the steps that a sliding block image and a corresponding CAD model are acquired; detecting edge points in the slide block image, and performing fitting operation based on the edge points to obtain fitting primitives; and comparing the fitting primitives in the slide block image with the to-be-detected primitives of the CAD model, and judging whether the size of the slide block is qualified or not and the primitive tolerance in the unqualified slide block. According to the embodiment of the invention, the method improves the measurement reliability through image preprocessing and precise registration, reduces the errors, achieves the automatic measurement through the machine vision technology, and greatly improves the measurement efficiency compared with a conventional method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision measurement, and in particular to a method, device, equipment and medium for measuring the size of a slider based on machine vision. Background Art

[0002] The slider is a component that can perform linear motion in a mechanical structure. In a mechanical motion system, the slider cooperates with the guide rail to provide precise linear motion guidance for the moving parts. For example, in a CNC machine tool, the movement of the tool is often achieved by the movement of the slider along the guide rail, which can ensure the accuracy of the tool's motion trajectory during the processing, thereby improving the processing accuracy. Therefore, in the field of mechanical manufacturing, the slider is a key component, and its dimensional accuracy directly affects the performance and stability of the overall equipment.

[0003] Traditional slider size measurement methods mainly rely on manual measurement, which often has problems such as low accuracy, low efficiency, and large manual operation errors. With the development of machine vision technology, it has become possible to use machine vision for high-precision size measurement, but the existing methods still have some shortcomings when measuring slider size. For example, errors are easily generated during image acquisition, processing, and registration, affecting the accuracy of the measurement results. Summary of the invention

[0004] The purpose of the present invention is to provide a slider size measurement method based on machine vision to solve the problems of low measurement accuracy and complex operation in the prior art, and to achieve high-precision and high-efficiency measurement of the slider size.

[0005] In order to solve the above technical problems, the present application provides a method for measuring the size of a slider based on machine vision, comprising:

[0006] Get the slider image and the corresponding CAD model;

[0007] Detecting edge points in the slider image, and performing a fitting operation based on the edge points to obtain a fitting primitive;

[0008] The fitted primitives in the slider image are compared with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the tolerance of the primitives in the unqualified slider.

[0009] Preferably, the obtaining of the slider image includes:

[0010] Calibrate the camera's internal and external parameters, distortion coefficients, and pixel equivalents of the plane to be measured;

[0011] Importing a CAD model of a slider and numbering primitives to be measured in the CAD model;

[0012] Adjust the light source and obtain the slider image through the camera;

[0013] The slider image is preprocessed based on the calibrated camera internal and external parameters and distortion coefficients.

[0014] Preferably, the adjusting the light source comprises:

[0015] Adjust the brightness and angle of the light source according to the reflective properties and surface characteristics of the slider material.

[0016] Preferably, the preprocessing of the slider image based on the calibrated camera internal and external parameters and distortion coefficients includes:

[0017] Performing denoising on the initial slider image of the slider using a median filter;

[0018] Remove distortion by combining calibrated internal and external parameters and distortion coefficients;

[0019] Eliminate the perspective effect on the upper surface of the slider image by using the inverse perspective transformation matrix;

[0020] The irrelevant background in the slider image is removed through binarization and connected domain operations, the foreground image is segmented, and the slider image required for measurement is extracted.

[0021] Preferably, performing a fitting operation based on the edge points to obtain a fitting primitive comprises:

[0022] Establish the slider coordinate system and use pixel equivalent to perform the registration between the slider image and the CAD model;

[0023] According to the position of the primitive to be measured in the CAD model, sub-pixel edge points are searched near the position corresponding to the primitive to be measured in the slider image, and a fitting operation is performed on the searched sub-pixel edge points to obtain a fitting primitive.

[0024] Preferably, the establishing of the slider coordinate system comprises:

[0025] Detect line segments in the slider image using a straight line detection method;

[0026] The gradient of each pixel in the slider image is calculated by a gradient calculation formula, edge points where line segments may exist are screened out according to a preset formula, and the edge points are put into a list in descending order of gradient;

[0027] Select the point with the largest gradient as the center point, traverse the seed points in the list, and classify the points whose seed point errors are less than a specific value as the growth area, growing outward from the seed point that meets the conditions as the center until there are no seed points that meet the conditions within the 8-neighborhood range of the center point and stop growing; set the number of false alarms (NFA) and the threshold ε, and calculate that when NFA(r)≤ε of the growth area, all edge points contained in the growth area meet the line segment condition;

[0028] Calculate the length of each line segment, filter out shorter line segments according to the set length threshold, merge the line segments on the same line into one line segment, and select the longest line segment as the x-axis of the slider coordinate system in the slider image;

[0029] Calculate the inclination angle of the x-axis in the image coordinate system, where k represents the slope of the x-axis. Determine the line segment perpendicular to the x-axis and located on its left as the y-axis. Use the straight line intersection formula to calculate the coordinates of the slider coordinate origin in the image coordinate system, thereby establishing the slider coordinate system.

[0030] Preferably, the registering of the slider image and the CAD model by using pixel equivalents comprises:

[0031] Determine the rotation angle and direction based on the coordinate system of the CAD model and the slider image;

[0032] The scaling factor between the CAD model and the slider image is calculated using the calibrated pixel equivalent to achieve matching between the CAD model and the slider image.

[0033] In order to solve the above technical problems, the present application also provides a slider size measuring device based on machine vision, comprising:

[0034] A data acquisition module, used to acquire the slider image and the corresponding CAD model;

[0035] A fitting module, used for detecting edge points in the slider image, and performing a fitting operation based on the edge points to obtain a fitting primitive;

[0036] The comparison and judgment module is used to compare the fitting primitives in the slider image with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the primitive tolerance of the unqualified slider.

[0037] In order to solve the above technical problems, the present application also provides a slider size measurement device based on machine vision, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, the above-mentioned slider size measurement method based on machine vision is implemented.

[0038] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, which stores a computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the above-mentioned machine vision-based slider size measurement method.

[0039] Compared with the prior art, the machine vision-based slider size measurement method, device, equipment and storage medium disclosed in the present invention ensure the high precision of slider size measurement through precise camera calibration and sub-pixel edge detection and other technologies, improve the measurement reliability and reduce errors through image preprocessing and precise alignment process, and use machine vision technology to realize automated measurement, which greatly improves the measurement efficiency compared with traditional methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solution of the present invention, the drawings used in the implementation mode will be briefly introduced below. Obviously, the drawings described below are only some implementation modes of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 is a flow chart of a method for measuring slider size based on machine vision provided by an embodiment of the present invention;

[0042] Figure 2 for Figure 1 A detailed implementation flow chart of one of the steps in the slider size measurement method based on machine vision described in the invention;

[0043] Figure 3 A schematic diagram for numbering the primitives to be tested;

[0044] Figure 4 Schematic diagram of the image preprocessing process;

[0045] Figure 5 for Figure 1 A detailed implementation flow chart of another step in the slider size measurement method based on machine vision;

[0046] Figure 6 A schematic diagram of a determined slider image coordinate system;

[0047] Figure 7 Schematic diagram of the circle fitting process

[0048] Figure 8 It is a structural block diagram of a slider size measuring device based on machine vision provided by an embodiment of the present invention;

[0049] Fig. 9It is a schematic diagram of a slider size measuring device based on machine vision provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "in one embodiment" or "in an embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.

[0052] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0053] In the embodiments of the present application, the term "and / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. In the embodiments of the present application, the term "plurality" refers to two or more than two, and other quantifiers are similar.

[0054] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0055] like Figure 1 As shown, an embodiment of the present application provides a slider size measurement method based on machine vision, comprising:

[0056] Step S1, obtaining a slider image and a corresponding CAD model.

[0057] In the embodiment of the present invention, the slider refers to a component capable of linear motion in a mechanical structure. In the embodiment of the present invention, the slider image can be acquired by a camera device. Furthermore, the CAD model refers to a three-dimensional CAD model of the slider.

[0058] In detail, Figure 2 As shown, the step of obtaining the slider image in S1 includes:

[0059] S10, calibrating the internal and external parameters of the camera, the distortion coefficient, and the pixel equivalent of the plane to be measured.

[0060] The embodiments of the present invention can obtain the internal parameters of the camera, including focal length, principal point coordinates, radial distortion coefficient, tangential distortion coefficient, etc., through a camera calibration method, and use calibration points of known size to shoot on the plane to be measured, and obtain the pixel size of the calibration points in the image through image processing technology, so as to calculate the pixel equivalent of the plane to be measured.

[0061] The pixel equivalent of the plane to be measured refers to the actual physical size corresponding to each pixel in the image. For example, if a pixel equivalent is 0.1mm, it means that a pixel in the image represents a length of 0.1mm in the actual physical world. Calculation method: Through the camera calibration method, use calibration points of known size to shoot on the plane to be measured. For example, there are several calibration points on a standard calibration plate with a known length of 10mm. After shooting it, the pixel size of the calibration points in the image is obtained through image processing technology. Assuming that the calibration point occupies 100 pixels in the image, the pixel equivalent P = 10mm / 100 = 0.1mm / pixel. The pixel equivalent of the plane to be measured is a key parameter to establish the connection between image pixels and actual physical size. In the embodiment of the present invention, after obtaining the pixel equivalent of the plane to be measured, its actual physical size can be calculated according to the pixel size of the slider in the image. For example, when measuring the length of a slider, if the slider length is measured to be 200 pixels in the image and the pixel equivalent is known to be 0.1 mm / pixel, then the actual length of the slider is 200×0.1=20 mm.

[0062] In one embodiment of the present invention, a two-dimensional chessboard can be used as a target for calibrating a camera, and a camera is used to capture multiple images containing a calibration plate placed at different positions, angles, and distances, so as to obtain a better calibration effect. The calibration plate used in the present invention has a grid spacing of 5 mm, a length and width of 12×10, and uses the Zhang Zhengyou camera calibration method to calibrate the internal and external parameters of the camera, the distortion coefficient, and the pixel equivalent of the plane to be measured.

[0063] Through camera calibration, the geometric model of camera imaging can be accurately established, so as to determine the relationship between the two-dimensional geometric position of the point on the slider surface and its corresponding point in the image, which helps to improve the accuracy of image measurement and make the measurement results more accurate and reliable. At the same time, pixel equivalent calibration can determine the actual physical distance represented by a pixel point in the image in space, further enhancing the accuracy of measurement.

[0064] S11, importing a CAD model of a slider and numbering primitives to be measured in the CAD model.

[0065] In an embodiment of the present invention, the CAD model of the slider may be in a DXF file format, and the DXF file is a file format for data exchange between AutoCAD software and other software. Furthermore, in an embodiment of the present invention, the primitives to be tested in the CAD model are numbered, and the ezdxf library can be used in Python to read the DXF file, identify the primitives to be tested, and then add a numbering attribute to each primitive. The numbering of the primitives to be tested is used to ensure traceability during testing. The numbering can effectively distinguish and track the objects to be tested, which not only helps to reduce confusion and improve the efficiency of data management, but also ensures the reliability of the test results. Figure 3 As shown, in the embodiment of the present invention, in the slider to be measured, there are 5 line segments and 8 arcs that need to be measured, and they are numbered in sequence.

[0066] S12, adjusting the light source, and obtaining the slider image through the camera.

[0067] The light source is adjusted to ensure the clarity and contrast of the slider image to improve the accuracy of subsequent image processing.

[0068] In an embodiment of the present invention, the brightness and angle of the light source can be adjusted according to the reflective properties and surface features of the slider material, and the camera preview image can be observed to ensure that the general outline and key features of the slider are visible, thereby improving the quality and recognition of the image and ensuring that the detailed features of the slider are accurately displayed, thereby providing a more reliable data basis for subsequent image processing, analysis and recognition, and further improving the overall performance and accuracy of the machine vision system.

[0069] S13, preprocessing the slider image based on the calibrated camera internal and external parameters and distortion coefficients.

[0070] In the embodiment of the present invention, the preprocessing includes, but is not limited to, denoising, enhancement, and contrast adjustment to improve image quality. Figure 4As shown, the preprocessing includes, first, denoising the initial slider image of the slider using a median filter; removing distortion by combining calibrated internal and external parameters and distortion coefficients; eliminating the perspective effect on the upper surface of the slider image by an inverse perspective transformation matrix; removing irrelevant background in the slider image by binarization and connected domain operations, achieving segmentation of the foreground image, and extracting the slider image required for measurement.

[0071] Through operations such as noise reduction and enhancement, the slider image can be made clearer, the image quality can be improved, the information of interest can be highlighted, and the subsequent feature extraction and analysis can be facilitated. The calculation complexity of the algorithm can also be reduced, thereby speeding up the processing speed.

[0072] Step S2: Detect edge points in the slider image, and perform a fitting operation based on the edge points to obtain a fitting primitive.

[0073] In the embodiment of the present invention, an edge detection algorithm based on sub-pixel interpolation, such as a sub-pixel edge detection algorithm based on grayscale moment, may be used to detect edge points in the slider image.

[0074] The grayscale moment is a method used to describe image features in image processing. The sub-pixel edge detection algorithm based on grayscale moment determines the sub-pixel position of the edge point by calculating the grayscale moment of the image, thereby improving the accuracy of edge detection. In one embodiment of the present invention, the sub-pixel edge detection algorithm based on grayscale moment detects the edge points in the slider image, including: converting the slider image into a grayscale image; using Gaussian blur to reduce image noise; using the Canny edge detection algorithm to detect the edge image in the image, and using the contour detection function to find the contour in the edge image, for each contour, calculating its grayscale moment, and calculating the center of mass of the contour through the grayscale moment, and the position of the center of mass is the edge point with sub-pixel accuracy.

[0075] Sub-pixel edge detection can surpass traditional pixel-level accuracy and improve detection accuracy to the sub-pixel level, which helps capture more subtle image details.

[0076] Furthermore, if Figure 5 As shown, the fitting operation is performed based on the edge points to obtain the fitting primitives, including:

[0077] Step 20, establishing a slider coordinate system, and performing registration between the slider image and the CAD model using pixel equivalent;

[0078] In detail, the embodiment of the present invention uses the LSD (Line Segment Detector) line detection method to detect line segments in the slider image, and uses the gradient calculation formula (In the formula, τ is the allowable angle error, generally taken as ) calculates the gradient of each pixel in the slider image, and selects edge points that may have line segments according to a preset formula (the gradient value is greater than 2.83, and the angle allowable error is generally a certain value), and puts the edge points into a list in descending order of gradient; selects the point with the largest gradient as the center point, traverses the seed points in the list, and selects the seed points with an error less than a specific value The points are classified as the growth area, and the seed point that meets the conditions is taken as the center to grow outward until there is no seed point that meets the conditions within the 8-neighborhood range of the center point and the growth stops; the number of false alarms (NFA) and the threshold ε=0.2 are set, and when the NFA(r)≤ε of the growth area is calculated, all edge points contained in the growth area meet the line segment condition; the length of each line segment is calculated, and the shorter line segments are screened out according to the set length threshold (λ=100), and the straight line segments on the same straight line are merged into one line segment, and the longest line segment is selected as the x-axis of the slider coordinate system in the slider image, and the formula θ=arctan(k) is used to calculate the inclination of the x-axis in the image coordinate system, where k represents the slope of the x-axis, and the line segment perpendicular to the x-axis and located on its left is determined as the y-axis, and the coordinates (x0, y0) of the slider coordinate origin in the image coordinate system are calculated by the straight line intersection formula, so as to establish the following Figure 6 The slider coordinate system is shown.

[0079] After determining the coordinate system of the slider CAD model and the slider image, clarifying the rotation angle and rotation direction, the scaling factor of the CAD model and the slider image is calculated using the calibrated pixel equivalent P of the plane to be measured to achieve matching between the two.

[0080] Among them, LSD is a line detection algorithm that can quickly and accurately extract line segment features from an image. Its principle is to identify a set of pixels that meet the straight line features to form a line segment based on the gradient information of the local area of ​​the image through a series of calculations and judgment logic. When calculating the gradient of each pixel, the gradient size and direction are usually determined by the change of the pixel grayscale value in the horizontal and vertical directions (or more directions, depending on the specific algorithm implementation), which helps to determine whether the pixel is at the edge of the line segment. The condition of setting the gradient value greater than 2.83 to screen possible edge points is based on the empirical or experimentally verified numerical limit of the degree of pixel grayscale change at the edge of the line segment in the actual image. The setting of the angle allowable error takes into account the angle fluctuation of the actual line segment edge within a certain range. Through these comprehensive judgments, the pixels with a high probability of being at the edge of the line segment are preliminarily screened out and sorted into a list for further processing.

[0081] Growing region is an image segmentation method used to further determine the area where the line segment is located. The point with the largest gradient is used as the starting center point because this point is usually located in a critical or characteristic position of the line segment, and then other points in the list are used as seed points for investigation. When the seed point error is less than a certain value, it means that these points are similar to the current center point in terms of spatial position, characteristic attributes, etc., and can be classified as the same growth region. This region is continuously expanded outward to simulate the characteristics of continuous distribution of line segments in the image. Until no seed point that meets the conditions is found within the 8-neighborhood range of the center point, it means that the region is relatively complete locally and has reached the boundary of the range covered by the line segment. Then, strict judgment is made through the set threshold and related formulas to ensure that the region does meet the characteristic requirements of the line segment, thereby accurately determining the position of the line segment in the image.

[0082] The reason why the length of the line segment is calculated and the threshold is set to filter out the shorter straight line segments is that there may be some short line segments in the image that are mistakenly detected due to noise, local micro texture and other factors. These line segments are not the line segments representing the key structural features of the slider that we are concerned about, so the length threshold is used for filtering to improve the accuracy of subsequent processing. The line segments on the same line are fused to take into account that the original continuous line segments may be split into multiple segments due to incomplete segmentation in the actual detection process. The fusion operation can restore the complete line segments that conform to the actual physical structure. The longest line segment is determined as the x-axis because the line segment corresponding to the x-axis direction in the slider image is often the longest and most representative of the main body direction. The inclination angle in the image coordinate system can be calculated to clarify its direction angle, and then the y-axis is determined based on the vertical relationship with the x-axis and the position specification, and the coordinate origin position is calculated by the straight line intersection formula. In this way, the coordinate system of the slider image is completely constructed to prepare for matching with the CAD model coordinate system.

[0083] After the coordinate systems of the slider CAD model and the slider image are determined, the rotation angle and direction are also clear. At this time, the calibrated pixel equivalent P of the plane to be measured is used to calculate the scaling factor. The pixel equivalent links the pixel size in the image with the actual physical size. Through it, the corresponding size of the line segments and coordinates in the image in the actual physical model can be known. Then, according to the corresponding relationship between the CAD model and the coordinate axis in the image, the appropriate scaling factor is calculated, so that the CAD model and the image can accurately match in position, direction, size, etc., and realize the registration of the two, which is convenient for subsequent application operations such as size measurement and model comparison.

[0084] By determining the slider coordinate system, the slider's position in space can be accurately located, and then combined with pixel equivalents for registration, it can ensure that the alignment between the CAD model and the actual object is more accurate. Using pixel equivalents to match image information with actual size can make the size ratio between the CAD model and the real object completely consistent.

[0085] Step 21, according to the position of the primitive to be measured in the CAD model, searching for sub-pixel edge points near the position corresponding to the primitive to be measured in the slider image, and performing a fitting operation on the searched sub-pixel edge points to obtain a fitting primitive.

[0086] When the registration of the slider image and the CAD model is completed, sub-pixel edge points are searched near the position corresponding to the primitive to be measured in the slider image according to the position of the primitive to be measured in the CAD model, and fitting algorithms such as the least squares method and the random sampling consensus algorithm (RANSAC) are used to fit line segments and circles to obtain fitted primitives.

[0087] When fitting an arc, the RANSAC method cannot be used directly for fitting because of the large noise at the edge points near the fitted circle. To solve this problem, the present invention performs clustering on the sub-pixel edge points before fitting the circle. The main purpose is to minimize the impact of chamfering on the fitting result. Figure 7 (a) Sub-pixel edge points near each fitted circle; Figure 7 (b) is a sub-pixel edge point of one of the fitted circles and chamfers. Figure 7 (c) Use k-means to classify these edge points into two categories. Figure 7 (d) is the circle with a smaller radius after RANSAC fitting. Figure 7 (e) is the final fitting circle.

[0088] Step S3, comparing the fitted primitives in the slider image with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the tolerance of the primitives in the unqualified slider.

[0089] The embodiments of the present invention can use a size comparison method, an angle size comparison method, a shape comparison method, a position comparison method, etc. to compare the fitting primitives in the slider image with the primitives to be measured in the CAD model, so as to determine whether the size of the slider is qualified, and when any deviation between the fitting primitive and the corresponding primitive to be measured exceeds a certain tolerance range, the slider is judged to be unqualified, and the name of the fitting primitive (such as a specific slot, hole, etc.), the unqualified parameters (size, position or shape parameters) and the values ​​exceeding the tolerance are marked in the slider image, which can facilitate subsequent quality analysis and the formulation of improvement measures.

[0090] The slider size measurement method based on machine vision disclosed in the present invention ensures the high precision of slider size measurement through technologies such as precise camera calibration and sub-pixel edge detection, improves the measurement reliability and reduces errors through image preprocessing and precise alignment process, and realizes automated measurement using machine vision technology, which greatly improves the measurement efficiency compared with traditional methods.

[0091] See also Figure 8 , Figure 8 : is a structural block diagram of a slider size measuring device based on machine vision provided by an embodiment of the present invention, wherein the slider size measuring device based on machine vision comprises:

[0092] Data acquisition module 1, used to acquire the slider image and the corresponding CAD model;

[0093] A fitting module 2, used for detecting edge points in the slider image, and performing a fitting operation based on the edge points to obtain a fitting primitive;

[0094] The comparison and judgment module 3 is used to compare the fitting primitives in the slider image with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the primitive tolerance of the unqualified slider.

[0095] In detail, when acquiring the slider image, the data acquisition module 1 specifically performs:

[0096] First, calibrate the camera's internal and external parameters, distortion coefficients, and pixel equivalents of the plane to be measured.

[0097] The embodiments of the present invention can obtain the internal parameters of the camera, including focal length, principal point coordinates, radial distortion coefficient, tangential distortion coefficient, etc., through a camera calibration method, and use calibration points of known size to shoot on the plane to be measured, and obtain the pixel size of the calibration points in the image through image processing technology, so as to calculate the pixel equivalent of the plane to be measured.

[0098] The pixel equivalent of the plane to be measured refers to the actual physical size corresponding to each pixel in the image. For example, if a pixel equivalent is 0.1mm, it means that a pixel in the image represents a length of 0.1mm in the actual physical world. Calculation method: Through the camera calibration method, use calibration points of known size to shoot on the plane to be measured. For example, there are several calibration points on a standard calibration plate with a known length of 10mm. After shooting it, the pixel size of the calibration points in the image is obtained through image processing technology. Assuming that the calibration point occupies 100 pixels in the image, the pixel equivalent P = 10mm / 100 = 0.1mm / pixel. The pixel equivalent of the plane to be measured is a key parameter to establish the connection between image pixels and actual physical size. In the embodiment of the present invention, after obtaining the pixel equivalent of the plane to be measured, its actual physical size can be calculated according to the pixel size of the slider in the image. For example, when measuring the length of a slider, if the slider length is measured to be 200 pixels in the image and the pixel equivalent is known to be 0.1 mm / pixel, then the actual length of the slider is 200×0.1=20 mm.

[0099] In one embodiment of the present invention, a two-dimensional chessboard can be used as a target for calibrating a camera, and a camera is used to capture multiple images containing a calibration plate placed at different positions, angles, and distances, so as to obtain a better calibration effect. The calibration plate used in the present invention has a grid spacing of 5 mm, a length and width of 12×10, and uses the Zhang Zhengyou camera calibration method to calibrate the internal and external parameters of the camera, the distortion coefficient, and the pixel equivalent of the plane to be measured.

[0100] Through camera calibration, the geometric model of camera imaging can be accurately established, so as to determine the relationship between the two-dimensional geometric position of the point on the slider surface and its corresponding point in the image, which helps to improve the accuracy of image measurement and make the measurement results more accurate and reliable. At the same time, pixel equivalent calibration can determine the actual physical distance represented by a pixel point in the image in space, further enhancing the accuracy of measurement.

[0101] Second, the CAD model of the slider is imported and the primitives to be measured in the CAD model are numbered.

[0102] In an embodiment of the present invention, the CAD model of the slider may be in a DXF file format, and the DXF file is a file format for data exchange between AutoCAD software and other software. Furthermore, in an embodiment of the present invention, the primitives to be tested in the CAD model are numbered, and the ezdxf library can be used in Python to read the DXF file, identify the primitives to be tested, and then add a numbering attribute to each primitive. The numbering of the primitives to be tested is used to ensure traceability during testing. The numbering can effectively distinguish and track the objects to be tested, which not only helps to reduce confusion and improve the efficiency of data management, but also ensures the reliability of the test results. Figure 3 As shown, in the embodiment of the present invention, in the slider to be measured, there are 5 line segments and 8 arcs that need to be measured, and they are numbered in sequence.

[0103] Third, adjust the light source and obtain the slider image through the camera.

[0104] The light source is adjusted to ensure the clarity and contrast of the slider image to improve the accuracy of subsequent image processing.

[0105] In an embodiment of the present invention, the brightness and angle of the light source can be adjusted according to the reflective properties and surface features of the slider material, and the camera preview image can be observed to ensure that the general outline and key features of the slider are visible, thereby improving the quality and recognition of the image and ensuring that the detailed features of the slider are accurately displayed, thereby providing a more reliable data basis for subsequent image processing, analysis and recognition, and further improving the overall performance and accuracy of the machine vision system.

[0106] Fourth, the slider image is preprocessed based on the calibrated camera internal and external parameters and distortion coefficients.

[0107] In the embodiment of the present invention, the preprocessing includes, but is not limited to, denoising, enhancement, and contrast adjustment to improve image quality. Figure 4 As shown, the preprocessing includes, first, denoising the initial slider image of the slider using a median filter; removing distortion by combining calibrated internal and external parameters and distortion coefficients; eliminating the perspective effect on the upper surface of the slider image by an inverse perspective transformation matrix; removing irrelevant background in the slider image by binarization and connected domain operations, achieving segmentation of the foreground image, and extracting the slider image required for measurement.

[0108] Through operations such as noise reduction and enhancement, the slider image can be made clearer, the image quality can be improved, the information of interest can be highlighted, and the subsequent feature extraction and analysis can be facilitated. The calculation complexity of the algorithm can also be reduced, thereby speeding up the processing speed.

[0109] The fitting module 2 performs a fitting operation based on the edge points to obtain a fitting primitive, specifically performing:

[0110] First, the slider coordinate system is established and the registration between the slider image and the CAD model is performed using pixel equivalent;

[0111] In detail, the embodiment of the present invention uses the LSD (Line Segment Detector) line detection method to detect line segments in the slider image, and uses the gradient calculation formula (In the formula, τ is the allowable angle error, generally taken as ) calculates the gradient of each pixel in the slider image, and selects edge points that may have line segments according to a preset formula (the gradient value is greater than 2.83, and the angle allowable error is generally a certain value), and puts the edge points into a list in descending order of gradient; selects the point with the largest gradient as the center point, traverses the seed points in the list, and selects the seed points with an error less than a specific value The points are classified as the growth area, and the seed point that meets the conditions is taken as the center to grow outward until there is no seed point that meets the conditions within the 8-neighborhood range of the center point and the growth stops; the threshold ε=0.2 is set, and when the NFA(r)≤ε of the growth area is calculated, all the edge points contained in the growth area meet the line segment condition; the length of each line segment is calculated, and the shorter line segments are screened out according to the set length threshold (λ=100), and the line segments on the same line are merged into one line segment, and the longest line segment is selected as the x-axis of the slider coordinate system in the slider image, and the formula θ=arctan(k) is used to calculate the inclination of the x-axis in the image coordinate system, where k represents the slope of the x-axis, and the line segment perpendicular to the x-axis and located on its left is determined as the y-axis, and the coordinates of the slider coordinate origin in the image coordinate system (x0, y0) are calculated by the straight line intersection formula, so as to establish the following Figure 6 The slider coordinate system is shown.

[0112] After determining the coordinate systems of the slider CAD model and the slider image (i.e., clarifying the rotation angle and rotation direction), the scaling coefficients of the two are calculated using the calibrated pixel equivalent P of the plane to be measured to achieve matching between the two.

[0113] Among them, LSD is a line detection algorithm that can quickly and accurately extract line segment features from an image. Its principle is to identify a set of pixels that meet the straight line features to form a line segment based on the gradient information of the local area of ​​the image through a series of calculations and judgment logic. When calculating the gradient of each pixel, the gradient size and direction are usually determined by the change of the pixel grayscale value in the horizontal and vertical directions (or more directions, depending on the specific algorithm implementation), which helps to determine whether the pixel is at the edge of the line segment. The condition of setting the gradient value greater than 2.83 to screen possible edge points is based on the empirical or experimentally verified numerical limit of the degree of pixel grayscale change at the edge of the line segment in the actual image. The setting of the angle allowable error takes into account the angle fluctuation of the actual line segment edge within a certain range. Through these comprehensive judgments, the pixels with a high probability of being at the edge of the line segment are preliminarily screened out and sorted into a list for further processing.

[0114] Growing region is an image segmentation method used to further determine the area where the line segment is located. The point with the largest gradient is used as the starting center point because this point is usually located in a critical or characteristic position of the line segment, and then other points in the list are used as seed points for investigation. When the seed point error is less than a certain value, it means that these points are similar to the current center point in terms of spatial position, characteristic attributes, etc., and can be classified as the same growth region. This region is continuously expanded outward to simulate the characteristics of continuous distribution of line segments in the image. Until no seed point that meets the conditions is found within the 8-neighborhood range of the center point, it means that the region is relatively complete locally and has reached the boundary of the range covered by the line segment. Then, strict judgment is made through the set threshold and related formulas to ensure that the region does meet the characteristic requirements of the line segment, thereby accurately determining the position of the line segment in the image.

[0115] The reason why the length of the line segment is calculated and the threshold is set to filter out the shorter straight line segments is that there may be some short line segments in the image that are mistakenly detected due to noise, local micro texture and other factors. These line segments are not the line segments representing the key structural features of the slider that we are concerned about, so the length threshold is used for filtering to improve the accuracy of subsequent processing. The line segments on the same line are fused to take into account that the original continuous line segments may be split into multiple segments due to incomplete segmentation in the actual detection process. The fusion operation can restore the complete line segments that conform to the actual physical structure. The longest line segment is determined as the x-axis because the line segment corresponding to the x-axis direction in the slider image is often the longest and most representative of the main body direction. The inclination angle in the image coordinate system can be calculated to clarify its direction angle, and then the y-axis is determined based on the vertical relationship with the x-axis and the position specification, and the coordinate origin position is calculated by the straight line intersection formula. In this way, the coordinate system of the slider image is completely constructed to prepare for matching with the CAD model coordinate system.

[0116] After the coordinate systems of the slider CAD model and the slider image are determined, the rotation angle and direction are also clear. At this time, the calibrated pixel equivalent P of the plane to be measured is used to calculate the scaling factor. The pixel equivalent links the pixel size in the image with the actual physical size. Through it, the corresponding size of the line segments and coordinates in the image in the actual physical model can be known. Then, according to the corresponding relationship between the CAD model and the coordinate axis in the image, the appropriate scaling factor is calculated, so that the CAD model and the image can accurately match in position, direction, size, etc., and realize the registration of the two, which is convenient for subsequent application operations such as size measurement and model comparison.

[0117] By determining the slider coordinate system, the slider's position in space can be accurately located, and then combined with pixel equivalents for registration, it can ensure that the alignment between the CAD model and the actual object is more accurate. Using pixel equivalents to match image information with actual size can make the size ratio between the CAD model and the real object completely consistent.

[0118] Second, according to the position of the primitive to be measured in the CAD model, sub-pixel edge points are searched near the position corresponding to the primitive to be measured in the slider image, and a fitting operation is performed on the searched sub-pixel edge points to obtain a fitting primitive.

[0119] When the registration of the slider image and the CAD model is completed, sub-pixel edge points are searched near the position corresponding to the primitive to be measured in the slider image according to the position of the primitive to be measured in the CAD model, and fitting algorithms such as the least squares method and the random sampling consensus algorithm (RANSAC) are used to fit line segments and circles to obtain fitted primitives.

[0120] When fitting an arc, the RANSAC method cannot be used directly for fitting because of the large noise at the edge points near the fitted circle. To solve this problem, the present invention performs clustering on the sub-pixel edge points before fitting the circle. The main purpose is to minimize the impact of chamfering on the fitting result. Figure 7 (a) Sub-pixel edge points near each fitted circle; Figure 7 (b) is a sub-pixel edge point of one of the fitted circles and chamfers. Figure 7 (c) Use k-means to classify these edge points into two categories. Figure 7 (d) is the circle with a smaller radius after RANSAC fitting. Figure 7 (e) is the final fitting circle.

[0121] The comparison and judgment module 3 compares the fitting primitives in the slider image with the primitives to be measured in the CAD model by using a size comparison method, an angle size comparison method, a shape comparison method, a position comparison method, etc., so as to judge whether the size of the slider is qualified, and when any deviation between the fitting primitive and the corresponding primitive to be measured exceeds a certain tolerance range, the slider is judged to be unqualified, and the name of the fitting primitive (such as a specific slot, hole, etc.), the unqualified parameters (size, position or shape parameters) and the values ​​exceeding the tolerance are marked in the slider image, which can facilitate subsequent quality analysis and formulation of improvement measures.

[0122] It should be noted that the working process of each module in the slider size measuring device based on machine vision described in the embodiment of the present invention can refer to the working process of the slider size measuring method based on machine vision described in the above embodiment, and the technical effect achieved is also the same as that of the slider size measuring device based on machine vision described in the above embodiment, which will not be repeated here.

[0123] See also Fig. 9 , is a schematic diagram of a slider size measuring device based on machine vision provided by an embodiment of the present invention. The slider size measuring device based on machine vision includes a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, the steps in the above-mentioned slider size measuring method embodiments based on machine vision are implemented, such as steps S1 to S3.

[0124] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 22 and executed by the processor 21 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the machine vision-based slider size measurement device.

[0125] The machine vision-based slider size measuring device may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art may understand that the schematic diagram is only an example of a machine vision-based slider size measuring device and does not constitute a limitation on the machine vision-based slider size measuring device. The machine vision-based slider size measuring device may include more or less components than shown in the figure, or a combination of certain components, or different components. For example, the machine vision-based slider size measuring device may also include input and output devices, network access devices, buses, etc.

[0126] The processor 21 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 21 is the control center of the machine vision-based slider size measuring device, and uses various interfaces and lines to connect various parts of the entire machine vision-based slider size measuring device.

[0127] The memory 22 can be used to store the computer program and / or module. The processor 21 realizes various functions of the slider size measuring device based on machine vision by running or executing the computer program and / or module stored in the memory 22 and calling the data stored in the memory 22. The memory 22 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 22 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0128] Wherein, if the module / unit integrated in the slider size measuring device based on machine vision is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor 21, the steps of the above-mentioned method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0129] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.

[0130] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, many improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A slider size measurement method based on machine vision, characterized in that: include: Get the slider image and the corresponding CAD model; Detecting edge points in the slider image, and performing a fitting operation based on the edge points to obtain a fitting primitive; The fitted primitives in the slider image are compared with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the tolerance of the primitives in the unqualified slider.

2. The method for measuring the size of a slider based on machine vision according to claim 1, characterized in that: The step of obtaining the slider image comprises: Calibrate the camera's internal and external parameters, distortion coefficients, and pixel equivalents of the plane to be measured; Importing a CAD model of a slider and numbering primitives to be measured in the CAD model; Adjust the light source and obtain the slider image through the camera; The slider image is preprocessed based on the calibrated camera internal and external parameters and distortion coefficients.

3. The method for measuring the size of a slider based on machine vision according to claim 2, characterized in that: The adjusting the light source comprises: Adjust the brightness and angle of the light source according to the reflective properties and surface characteristics of the slider material.

4. The method for measuring the size of a slider based on machine vision according to claim 2, characterized in that: The preprocessing of the slider image based on the calibrated camera internal and external parameters and distortion coefficients includes: Performing denoising on the initial slider image of the slider using a median filter; Combine the calibrated internal and external parameters and distortion coefficients to remove distortion; Eliminate the perspective effect on the upper surface of the slider image by using the inverse perspective transformation matrix; The irrelevant background in the slider image is removed through binarization and connected domain operations, the foreground image is segmented, and the slider image required for measurement is extracted.

5. The method for measuring the size of a slider based on machine vision according to claim 2, characterized in that: The performing a fitting operation based on the edge points to obtain a fitting primitive comprises: Establishing a slider coordinate system, and performing registration of the slider image with the CAD model using the pixel equivalent; According to the position of the primitive to be measured in the CAD model, sub-pixel edge points are searched near the position corresponding to the primitive to be measured in the slider image, and a fitting operation is performed on the searched sub-pixel edge points to obtain a fitting primitive.

6. The method for measuring the size of a slider based on machine vision according to claim 5, characterized in that: The step of establishing the slider coordinate system comprises: Detect line segments in the slider image using a straight line detection method; The gradient of each pixel in the slider image is calculated by a gradient calculation formula, edge points where line segments may exist are screened out according to a preset formula, and the edge points are put into a list in descending order of gradient; Select the point with the largest gradient as the center point, traverse the seed points in the list, and classify the points whose seed point errors are less than a certain value as the growth area. Grow outward from the seed point that meets the conditions as the center until there are no seed points that meet the conditions within the 8-neighborhood range of the center point, and stop growing. The number of false alarms and the threshold ε are set. When the number of false alarms in the growing area is calculated to be ≤ ε, all edge points contained in the growing area meet the line segment condition. Calculate the length of each line segment, filter out shorter line segments according to the set length threshold, merge the line segments on the same line into one line segment, and select the longest line segment as the x-axis of the slider coordinate system in the slider image; Calculate the inclination angle of the x-axis in the image coordinate system, where k represents the slope of the x-axis. Determine the line segment perpendicular to the x-axis and located on its left as the y-axis. Use the straight line intersection formula to calculate the coordinates of the slider coordinate origin in the image coordinate system, thereby establishing the slider coordinate system.

7. The method for measuring the size of a slider based on machine vision according to claim 5, characterized in that: The registering of the slider image and the CAD model by using pixel equivalents includes: Determine the rotation angle and direction based on the coordinate system of the CAD model and the slider image; The scaling factor between the CAD model and the slider image is calculated using the calibrated pixel equivalent to achieve matching between the CAD model and the slider image.

8. A slider size measuring device based on machine vision, characterized in that: include: A data acquisition module, used to acquire the slider image and the corresponding CAD model; A fitting module, used for detecting edge points in the slider image, and performing a fitting operation based on the edge points to obtain a fitting primitive; The comparison and judgment module is used to compare the fitting primitives in the slider image with the primitives to be tested in the CAD model to determine whether the size of the slider is qualified and the primitive tolerance of the unqualified slider.

9. A slider size measuring device based on machine vision, characterized in that: include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the slider size measurement method based on machine vision according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the slider size measurement method based on machine vision according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • LSD improvement-based sea-sky-line extraction method of UUV near-sea-surface visible-light image

    CN107273903A

  • Fine scratch detection method and device, electronic equipment and computer readable storage medium

    CN112258448A

  • Multi-type workpiece size visual measurement method based on DXF file import

    CN115760860A

  • Part sub-pixel straight line detection method

    CN117893556A

  • Line segment detection method, apparatus, device, and computer-readable storage medium

    US20210150729A1