Method and system for detecting aperture and nest diameter of mechanical connecting hole
Technical Field
The invention relates to the field of digital intelligent detection, in particular to a method and a system for detecting the aperture and the nest diameter of a mechanical connecting hole.
Background
In the assembly process of complex machinery, the detection quality of the aperture nest diameter of the mechanical connecting hole is an important factor influencing the assembly quality of the complex machinery.
At present, in the manufacturing process, the aperture nest diameter of the connecting hole is usually measured manually, so the detection quality can change along with the difference of the operation level of workers, the detection precision is difficult to guarantee, and the workload of the workers is also large. At present, in manufacturing, a method for detecting the aperture of a connecting hole is a go-no go gauge detection method. Although the go-no go gauge can greatly improve the detection speed when being produced in batches, the go-no go gauge needs to pass through the connecting hole, so the connecting hole can be damaged, and the go gauge is worn after being used for many times, so the detection quality is influenced. Meanwhile, through the detection of the go-no go gauge, whether the aperture meets the tolerance requirement or not can be obtained, the specific numerical value of the aperture cannot be obtained, and the quantitative detection of the aperture cannot be completed. At present, the quality of each dimple is inspected by using a rivet or a bolt, and the method is greatly influenced by the precision of the rivet or the bolt, and the precision of a connecting hole is influenced because the rivet or the bolt needs to be in contact with the connecting hole.
Disclosure of Invention
Based on the above, the invention aims to provide a method and a system for detecting the aperture and the nest diameter of a mechanical connecting hole.
In order to achieve the purpose, the invention provides the following scheme:
a mechanical connection hole aperture and nest diameter detection method comprises the following steps:
enabling the camera to finish automatic focusing and determining the automatic focusing position of the camera;
setting the camera at the automatic focusing position, and acquiring image information of the connecting hole;
processing the image information and extracting the boundary of the connecting hole;
the lengths of the aperture and dimple diameter are calculated based on the boundary of the connecting hole.
Optionally, the enabling the camera to complete automatic focusing and determining an automatic focusing position of the camera specifically includes:
initializing focusing parameters; the focusing parameters include: camera position, camera movement step length and image definition;
moving a camera according to the camera moving step length and updating the position of the camera;
shooting the connecting holes at the positions of the cameras;
calculating the definition of the shot image through a Tenengrad image definition evaluation function;
and determining the corresponding camera position as an automatic focusing position when the definition of the shot image is maximum.
Optionally, the calculation formula of the definition of the shot image is as follows:
wherein, I (x, y) represents the gray value of the captured image at (x, y), n is the total number of pixels in the captured image, Q represents the sharpness of the captured image, Gx represents the kernel of the horizontal derivation at a certain pixel point of the image, Gy represents the kernel of the vertical derivation at a certain pixel point of the image, and S (x, y) represents the gradient value of the image at (x, y).
Optionally, the processing the image information to extract the boundary of the connection hole specifically includes:
carrying out binarization processing on the acquired image, and respectively obtaining an aperture image and a pit diameter image by setting different gray threshold values;
and extracting the image boundaries of the aperture image and the nest diameter image after binaryzation by using a Sobel edge detection algorithm.
Optionally, the calculating the lengths of the aperture and the socket diameter based on the boundary of the connection hole specifically includes:
processing the extracted image boundary by using an ellipse recognition algorithm in Opencv to obtain the endpoint coordinate A of the long axis of the aperture of the connecting hole0(x0,y0)、A1(x1,y1) Minor axis end point coordinate B of aperture of connecting hole0(m0,n0)、B1(m1,n1) Coordinates C of long shaft end point of socket diameter of connecting hole0(X0,Y0)、C1(X1,Y1) And coordinates D of end point of minor axis of socket diameter of connecting hole0(M0,N0)、D1(M1,N1);A0The position of the starting point of the long axis of the aperture of the connecting hole on the image (x)0,y0) Is A0Pixel point coordinates on the image; a. the1The position of the end point of the aperture major axis of the connecting hole on the image (x)1,y1) Is A1Pixel point coordinates on the image; b is0The position of the starting point of the minor axis of the aperture of the connecting hole on the image (m)0,n0) Is B0Pixel point coordinates on the image; b is1The position of the end point of the minor axis of the aperture of the connecting hole on the image (m)1,n1) Is B1Pixel point coordinates on the image; c0The position of the long axis starting point of the pit diameter of the connecting hole on the image (X)0,Y0) Is C0Pixel point coordinates on the image; c1The position of the long axis end point of the pit diameter of the connecting hole on the image (X)1,Y1) Is C1Pixel point coordinates on the image; d0The starting point of the minor axis of the pit diameter of the connecting hole is in the imagePosition (M)0,N0) Is D0Pixel point coordinates on the image; d1The position of the minor axis end point of the socket diameter of the connecting hole on the image (M)1,N1) Is D1Pixel point coordinates on the image;
acquiring a transverse calibration result a and a longitudinal calibration result b of the camera; the transverse calibration result a is the real transverse length of a pixel point, and the longitudinal calibration result b is the real longitudinal length of a pixel point;
according to the calibration results a and b of the camera in the transverse and longitudinal directions, the real length A, B of the long and short axes of the aperture of the connecting hole and the real length C, D of the long and short axes of the socket of the connecting hole are calculated, and the calculation formula is as follows:
the invention also provides a mechanical connection hole aperture and nest diameter detection system, which comprises:
the position determining module is used for enabling the camera to finish automatic focusing and determining the automatic focusing position of the camera;
the acquisition module is used for setting the camera at the automatic focusing position and acquiring the image information of the connecting hole;
the image processing module is used for processing the image information and extracting the boundary of the connecting hole;
and the length calculation module is used for calculating the lengths of the aperture and the nest diameter based on the boundary of the connecting hole.
Optionally, the position determining module specifically includes:
the initialization unit is used for initializing focusing parameters; the focusing parameters include: camera position, camera movement step length and image definition;
a moving unit for moving the camera by the camera moving step length and updating the camera position;
a shooting unit for shooting the connecting holes at each camera position;
the definition calculating unit is used for calculating the definition of the shot image through a Tenengrad image definition evaluation function;
and the determining unit is used for determining that the corresponding camera position when the definition of the shot image is maximum is an automatic focusing position.
Optionally, the calculation formula of the definition of the shot image is as follows:
wherein, I (x, y) represents the gray value of the captured image at (x, y), n is the total number of pixels in the captured image, Q represents the sharpness of the captured image, Gx represents the kernel of the horizontal derivation at a certain pixel point of the image, Gy represents the kernel of the vertical derivation at a certain pixel point of the image, and S (x, y) represents the gradient value of the image at (x, y).
Optionally, the image processing module specifically includes:
the binarization processing unit is used for carrying out binarization processing on the acquired image and respectively obtaining an aperture image and a pit diameter image by setting different gray threshold values;
and the image boundary extraction unit is used for extracting the image boundaries of the aperture image and the nest diameter image after binaryzation by utilizing a Sobel edge detection algorithm.
Optionally, the length calculating module specifically includes:
an identification unit, configured to process the extracted image boundary using an ellipse identification algorithm in Opencv to obtain a connection hole aperture major axis endpoint coordinate a0(x0,y0)、A1(x1,y1) Minor axis end point coordinate B of aperture of connecting hole0(m0,n0)、B1(m1,n1) Coordinates C of long shaft end point of socket diameter of connecting hole0(X0,Y0)、C1(X1,Y1) And coordinates D of end point of minor axis of socket diameter of connecting hole0(M0,N0)、D1(M1,N1);A0The position of the starting point of the long axis of the aperture of the connecting hole on the image (x)0,y0) Is A0Pixel point coordinates on the image; a. the1The position of the end point of the aperture major axis of the connecting hole on the image (x)1,y1) Is A1Pixel point coordinates on the image; b is0The position of the starting point of the minor axis of the aperture of the connecting hole on the image (m)0,n0) Is B0Pixel point coordinates on the image; b is1The position of the end point of the minor axis of the aperture of the connecting hole on the image (m)1,n1) Is B1Pixel point coordinates on the image; c0The position of the long axis starting point of the pit diameter of the connecting hole on the image (X)0,Y0) Is C0Pixel point coordinates on the image; c1The position of the long axis end point of the pit diameter of the connecting hole on the image (X)1,Y1) Is C1Pixel point coordinates on the image; d0The starting point of the minor axis of the socket diameter of the connecting hole is shown in the figurePosition on the image, (M)0,N0) Is D0Pixel point coordinates on the image; d1The position of the minor axis end point of the socket diameter of the connecting hole on the image (M)1,N1) Is D1Pixel point coordinates on the image;
the calibration result acquisition unit is used for acquiring a transverse calibration result a and a longitudinal calibration result b of the camera; the transverse calibration result a is the real transverse length of a pixel point, and the longitudinal calibration result b is the real longitudinal length of a pixel point;
the real length calculating unit is used for calculating the real length A, B of the aperture major axis and the minor axis of the connecting hole and the real length C, D of the aperture major axis and the minor axis of the connecting hole according to the calibration results a and b of the camera in the transverse direction and the longitudinal direction, and the calculation formula is as follows:
according to the specific embodiment provided by the invention, the invention discloses the following technical effects:
1) the detection precision is high. The invention carries out digital detection on the connecting hole through the camera to obtain the true value of the aperture nest diameter parameter of the connecting hole, so that the detection precision can reach the pixel point level.
2) The workpiece is not damaged. According to the invention, the camera is used for completing the spacing measurement of the connecting hole, and the connecting hole is not contacted, so that the damage to the workpiece is avoided.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings without inventive exercise.
FIG. 1 is an overall flow chart of a mechanical connection hole aperture and nest diameter detection method provided by the present invention;
FIG. 2 is a flowchart of an auto-focusing method according to the present invention;
FIG. 3 is a flow chart of an image processing method provided by the present invention;
FIG. 4 is a schematic diagram of a camera provided by the present invention;
FIG. 5 is an image of a connection hole at a different location provided by the present invention;
FIG. 6 is a graph showing the variation trend of the image sharpness along with the position of the camera according to the present invention; .
FIG. 7 is an original image provided by the present invention;
FIG. 8 is a binarized aperture image provided by the present invention;
FIG. 9 is a nest diameter image after binarization processing provided by the invention;
FIG. 10 is an aperture image boundary extracted by the Sobel edge detection algorithm provided by the present invention;
FIG. 11 is a dimple diameter image boundary extracted by the Sobel edge detection algorithm provided by the present invention;
FIG. 12 is a schematic diagram of the aperture image recognition result provided by the present invention;
FIG. 13 is a schematic diagram of a dimple diameter image recognition result provided by the present invention;
FIG. 14 is a block diagram of a mechanical linkage hole diameter and socket diameter detection system provided by the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention aims to provide a method and a system for detecting the aperture and the nest diameter of a mechanical connecting hole.
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
As shown in fig. 1, a method for detecting the aperture and the nest diameter of a mechanical connection hole comprises the following steps:
step 1: the camera is aligned with the attachment hole as in fig. 4.
Step 2: the auto-focusing function is operated to make the camera complete auto-focusing through the movement of the sliding table of the guide rail, as shown in fig. 2, which is a flow chart of the auto-focusing method. The auto-focusing steps of the camera are as follows:
step 2.1: and initializing focusing parameters. The focusing parameters include: camera position x, camera movement step L, image sharpness Q.
Step 2.2: the camera is moved in steps and the camera position x is updated x + L.
Step 2.3: a photograph was taken and the image sharpness Q was calculated by the Tenengrad image sharpness evaluation function. The Tenengrad image definition evaluation function formula is as follows, wherein I (x, y) represents the gray value of a shot image at the position (x, y), and n is the total number of pixel points in the shot image;
step 2.4: and judging whether the image definition Q is a maximum value at the current camera position x. If so, the automatic focusing is completed, otherwise, the step 2.2 is returned to, and the camera is continuously moved. As shown in fig. 5, at x 1000, the image resolution Q4.102061; at x-2000, image sharpness Q-4.604799; at x 3000, the image sharpness Q5.847310; at x 4000, image sharpness Q50.635648; at x 5000, image sharpness Q24.105014; at x 6000, image sharpness Q6.019339; at x 7000, image sharpness Q4.183125; at x 8000, the image sharpness Q2.811283. The degree of image sharpness changes with the change of Q, and it can be seen from fig. 5 that the image is sharper when Q is larger. The trend of Q with x is shown in FIG. 6, where it can be seen that Q has a maximum value. After the automatic focusing is finished, the camera will move to the position where x is 5000.
And step 3: keeping the camera position consistent with the camera position when the automatic focusing is finished, shooting a picture of the connecting hole, and processing the picture through an image processing algorithm to obtain the lengths of the long shaft and the short shaft of the aperture pit diameter of the connecting hole. The image processing algorithm process is shown in fig. 3, and comprises the following steps:
step 3.1: the acquired raw image is processed, and the raw image is shown in fig. 7.
Step 3.2: the acquired image is subjected to binarization processing, and an aperture image and a pit diameter image are respectively obtained by setting different gray level thresholds, wherein the processed aperture image is shown in fig. 8, and the processed pit diameter image is shown in fig. 9.
Step 3.3: the boundary of the binarized image is extracted by using a Sobel edge detection algorithm, the extraction result of the aperture image is shown in figure 10, and the extraction result of the pit diameter image is shown in figure 11.
Step 3.5: processing the extracted image boundary by using an ellipse recognition algorithm in Opencv to obtain the endpoint coordinate A of the long axis of the aperture of the connecting hole0(x0,y0)、A1(x1,y1) And the minor axis end point coordinate B of the aperture of the connecting hole0(m0,n0)、B1(m1,n1) Obtaining coordinates C of the long shaft end point of the socket diameter of the connecting hole0(X0,Y0)、C1(X1,Y1) And the minor axis end point coordinate D of the aperture of the connecting hole0(M0,N0)、D1(M1,N1)。A0The position of the starting point of the long axis of the aperture of the connecting hole on the image (x)0,y0) Is A0Pixel point coordinates on the image; a. the1The position of the end point of the aperture major axis of the connecting hole on the image (x)1,y1) Is A1Pixel point coordinates on the image; b is0The position of the starting point of the minor axis of the aperture of the connecting hole on the image (m)0,n0) Is B0Pixel point coordinates on the image; b is1The position of the end point of the minor axis of the aperture of the connecting hole on the image (m)1,n1) Is B1Pixel point coordinates on the image; c0The position of the long axis starting point of the pit diameter of the connecting hole on the image (X)0,Y0) Is C0Pixel point coordinates on the image; c1The position of the long axis end point of the pit diameter of the connecting hole on the image (X)1,Y1) Is C1Pixel point coordinates on the image; d0The position of the minor axis starting point of the pit diameter of the connecting hole on the image (M)0,N0) Is D0Pixel point coordinates on the image; d1The position of the minor axis end point of the socket diameter of the connecting hole on the image (M)1,N1) Is D1Coordinates of pixel points on the image.
Step 3.6: according to the calibration results a and b of the camera in the transverse direction and the longitudinal direction, the real length A, B of the long axis and the short axis of the aperture of the connecting hole and the real length C, D of the long axis and the short axis of the socket of the connecting hole are calculated. And the calibration results a and b of the camera in the transverse and longitudinal directions are the real transverse and longitudinal lengths of a pixel point. The aperture image recognition result is shown in fig. 12, the dimple image recognition result is shown in fig. 13, and the calculation formula of the true length A, B, C, D is as follows:
and 4, step 4: if the use is finished, the equipment is closed; if the use is continued, the step 2 is returned to.
As shown in fig. 14, the present invention also provides a mechanical connection hole aperture and socket aperture detection system, comprising:
a position determining module 1401, configured to enable the camera to complete auto-focus, and determine an auto-focus position of the camera.
The position determining module specifically includes:
the initialization unit is used for initializing focusing parameters; the focusing parameters include: camera position, camera movement step size, and image sharpness.
And the moving unit is used for moving the camera according to the camera moving step length and updating the camera position.
And the shooting unit is used for shooting the connecting hole at each camera position.
The definition calculating unit is used for calculating the definition of the shot image through a Tenengrad image definition evaluation function; the calculation formula of the definition of the shot image is as follows:
wherein, I (x, y) represents the gray value of the captured image at (x, y), n is the total number of pixels in the captured image, Q represents the sharpness of the captured image, Gx represents the kernel of the horizontal derivation at a certain pixel point of the image, Gy represents the kernel of the vertical derivation at a certain pixel point of the image, and S (x, y) represents the gradient value of the image at (x, y).
And the determining unit is used for determining that the corresponding camera position when the definition of the shot image is maximum is an automatic focusing position.
The collecting module 1402 is configured to set the camera at the auto-focus position, and collect image information of the connecting hole.
An image processing module 1403, configured to process the image information and extract a boundary of the connection hole.
The image processing module specifically comprises:
the binarization processing unit is used for carrying out binarization processing on the acquired image and respectively obtaining an aperture image and a pit diameter image by setting different gray threshold values;
and the image boundary extraction unit is used for extracting the image boundaries of the aperture image and the nest diameter image after binaryzation by utilizing a Sobel edge detection algorithm.
A length calculation module 1404 for calculating the lengths of the aperture and the dimple diameter based on the boundary of the connection hole.
The length calculation module specifically includes:
an identification unit, configured to process the extracted image boundary using an ellipse identification algorithm in Opencv to obtain a connection hole aperture major axis endpoint coordinate a0(x0,y0)、A1(x1,y1) Minor axis end point coordinate B of aperture of connecting hole0(m0,n0)、B1(m1,n1) Coordinates C of long shaft end point of socket diameter of connecting hole0(X0,Y0)、C1(X1,Y1) And coordinates D of end point of minor axis of socket diameter of connecting hole0(M0,N0)、D1(M1,N1);A0The position of the starting point of the long axis of the aperture of the connecting hole on the image (x)0,y0) Is A0Pixel point coordinates on the image; a. the1The position of the end point of the aperture major axis of the connecting hole on the image (x)1,y1) Is A1Pixel point coordinates on the image; b is0The position of the starting point of the minor axis of the aperture of the connecting hole on the image (m)0,n0) Is B0Pixel point coordinates on the image; b is1The position of the end point of the minor axis of the aperture of the connecting hole on the image (m)1,n1) Is B1Pixel point coordinates on the image; c0The position of the long axis starting point of the pit diameter of the connecting hole on the image (X)0,Y0) Is C0Pixel point coordinates on the image; c1The position of the long axis end point of the pit diameter of the connecting hole on the image (X)1,Y1) Is C1Pixel point coordinates on the image; d0The position of the minor axis starting point of the pit diameter of the connecting hole on the image (M)0,N0) Is D0Pixel point coordinates on the image; d1The position of the minor axis end point of the socket diameter of the connecting hole on the image (M)1,N1) Is D1Coordinates of pixel points on the image.
The calibration result acquisition unit is used for acquiring a transverse calibration result a and a longitudinal calibration result b of the camera; the transverse calibration result a is the real transverse length of a pixel point, and the longitudinal calibration result b is the real longitudinal length of a pixel point;
the real length calculating unit is used for calculating the real length A, B of the aperture major axis and the minor axis of the connecting hole and the real length C, D of the aperture major axis and the minor axis of the connecting hole according to the calibration results a and b of the camera in the transverse direction and the longitudinal direction, and the calculation formula is as follows:
the embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. For the system disclosed by the embodiment, the description is relatively simple because the system corresponds to the method disclosed by the embodiment, and the relevant points can be referred to the method part for description.
The principles and embodiments of the present invention have been described herein using specific examples, which are provided only to help understand the method and the core concept of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, the specific embodiments and the application range may be changed. In view of the above, the present disclosure should not be construed as limiting the invention.