Method and device for measuring object spatial posture based on monocular camera
By using the reference shape and PNP algorithm in monocular camera measurement, the problem of difficult to determine the target position and attitude in the measurement of 3D information in object space is solved, and real-time and accurate object pose measurement is achieved, which is suitable for complex environments and high-altitude operations. .
Patent Information
- Application Number
- CN202410940300.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-15
AI Technical Summary
When the existing technology measures 3D information in object space, it is difficult to determine the target position and attitude, especially in low-texture or long-distance scenes, the reconstruction effect is poor, and the accuracy is affected by the camera baseline distance and parallax resolution, and is sensitive to lighting conditions.
An object space pose measurement method based on a monocular camera is used, by fixing a label with a reference shape to the object to be measured, using the Canny edge detection algorithm and convex hull algorithm to detect and connect edges, and applying the PNP algorithm to calculate the transformation matrix, thereby Analyze the translation and rotation amounts to determine the position and attitude of the label.
It achieves real-time and accurate measurement of the spatial posture of objects under monocular camera monitoring, reduces subjective errors and safety hazards caused by manual judgment, and is suitable for complex environments and high-altitude operations.
Smart Images

Figure CN118470099B
Abstract
Description
Technical Field
[0001] The invention relates to a method and a device for measuring the spatial posture of an object based on a monocular camera, and belongs to the technical field of image processing. Background Art
[0002] In the industrial field, measuring the spatial three-dimensional information of objects based on machine vision is essential for achieving precise control and automated operations. For example, in robotics, the extraction of spatial three-dimensional information of objects can help robots identify and locate target objects in order to perform tasks such as handling, cleaning or maintenance; in the construction industry, during high-altitude operations, the measurement of spatial three-dimensional information of objects based on machine vision can eliminate the subjective errors of human eye judgment and reduce safety hazards. The measurement of spatial three-dimensional information of objects based on machine vision has been gradually applied to industries such as robotics, logistics and warehousing, medical and bioengineering, construction and civil engineering, and security monitoring. It has the advantages of improving production efficiency, improving product quality, enhancing safety, and improving resource utilization efficiency, and has great development prospects.
[0003] In the field of visual measurement technology, measuring the spatial 3D information of an object mainly depends on the image information captured by the camera. At the current stage, applications include structured light technology, binocular stereo vision and monocular vision. Structured light technology projects a known pattern on the surface of an object, then uses a camera to capture the deformed pattern, and calculates the 3D shape of the object surface by analyzing the deformation of the pattern, but it is sensitive to lighting conditions and requires specific hardware equipment. Binocular stereo vision captures the same scene from different perspectives of two or more cameras, and calculates the parallax between the two views to reconstruct 3D information. Binocular stereo vision technology has poor reconstruction effect in low-texture or long-distance scenes, and the accuracy is affected by the baseline distance and parallax resolution of the camera.
[0004] Therefore, the present invention proposes a method and device for measuring the spatial posture of an object based on a monocular camera. Summary of the invention
[0005] In order to solve the above problems, the present invention proposes a method and device for measuring the spatial posture of an object based on a monocular camera, which can solve the problem that the target position and posture are difficult to determine during the process of measuring the spatial 3D information of the object.
[0006] The technical solution adopted by the present invention to solve the technical problem is:
[0007] In a first aspect, an embodiment of the present invention provides a method for measuring the spatial pose of an object based on a monocular camera, comprising the following steps:
[0008] Step S1, fixing a label with a reference shape of the object to be measured to the object to be measured, recording the information of the reference shape on the label, and calibrating the monocular camera;
[0009] Step S2, photographing the object to be tested, obtaining an image of the object to be tested with a label, converting the color image into a grayscale image, and using a Gaussian filter to filter random noise in the image;
[0010] Step S3, using the Canny edge detection algorithm to detect edges in the image and connect the edges to form a shape;
[0011] Step S4, using a convex hull algorithm to find a matching pre-recorded reference shape and locate the pixel coordinates of the corner points of the reference shape;
[0012] Step S5, applying the PNP algorithm to solve the transformation relationship between the tag with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix, analyzing the translation and rotation from the transformation matrix, and calculating the position and posture of the tag at this time.
[0013] As a possible implementation of this embodiment, in step S1, information of the reference shape on the label is pre-set according to the usage scenario, and the information is:
[0014] ),
[0015] in, The angles of the interior angles of each reference shape, , ,..., is the side length of each reference shape.
[0016] As a possible implementation of this embodiment, in step S3, the formula for connecting the edges to form a shape is:
[0017] ,
[0018] in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
[0019] As a possible implementation of this embodiment, in step S4, the expression for finding a matching pre-recorded reference shape is:
[0020] ,
[0021] in, For the matching result, is the process function for comparison, is the output image edge information of step S3, The reference shape information preset in step S1.
[0022] As a possible implementation of this embodiment, step S5 includes:
[0023] Step S51, using the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix:
[0024] ,
[0025] in, is the three-dimensional point set of the object to be measured, is the two-dimensional point set of the image of the object to be tested, is the camera intrinsic parameter matrix, is the camera distortion coefficient;
[0026] Step S52: Analyze the translation amount from the change matrix and the amount of rotation :
[0027] ,
[0028] ,
[0029] in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function;
[0030] Step S53, further decomposing the translation amount and the amount of rotation , get the position and posture of the tag at this time:
[0031] ,
[0032] ,
[0033] ,
[0034] ,
[0035] in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
[0036] In a second aspect, an embodiment of the present invention provides a device for measuring the spatial position of an object based on a monocular camera, comprising:
[0037] The camera calibration module is used to fix a label with a reference shape of the object to be measured to the object to be measured, record the information of the reference shape on the label, and calibrate the monocular camera;
[0038] An image capturing module is used to capture images of the object to be tested, obtain images of the object to be tested with labels attached thereto, convert the color images into grayscale images, and use a Gaussian filter to filter random noise in the images;
[0039] An edge detection module is used to detect edges in an image using the Canny edge detection algorithm and connect the edges to form shapes;
[0040] A reference coordinate acquisition module, used to find a matching pre-recorded reference shape using a convex hull algorithm and locate the pixel coordinates of the corner points of the reference shape;
[0041] The posture calculation module is used to apply the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix, analyze the translation and rotation from the change matrix, and calculate the position and posture of the label at this time.
[0042] As a possible implementation of this embodiment, the camera calibration module pre-sets the reference shape information on the label according to the usage scenario, and the information is:
[0043] ),
[0044] in, The angles of the interior angles of each reference shape, , ,..., is the side length of each reference shape.
[0045] As a possible implementation of this embodiment, the edge detection module connects the edges to form a shape using the following formula:
[0046] ,
[0047] in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
[0048] As a possible implementation of this embodiment, the reference coordinate acquisition module searches for an expression that matches a pre-recorded reference shape:
[0049] ,
[0050] in, For the matching results, is the process function for comparison, is the output image edge information of the edge detection module, Reference shape information preset for the camera calibration module.
[0051] As a possible implementation of this embodiment, the posture calculation module includes:
[0052] The PNP algorithm module is used to apply the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix:
[0053] ,
[0054] in, is the three-dimensional point set of the object to be measured, is the two-dimensional point set of the image of the object to be tested, is the camera intrinsic parameter matrix, is the camera distortion coefficient;
[0055] Parsing module, used to parse the translation from the change matrix and the amount of rotation :
[0056] ,
[0057] ,
[0058] in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function;
[0059] The pose module is used to further decompose the translation and the amount of rotation , get the position and posture of the tag at this time:
[0060] ,
[0061] ,
[0062] ,
[0063] ,
[0064] in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
[0065] The beneficial effects of the technical solution of the embodiment of the present invention are as follows:
[0066] The technical solution of the embodiment of the present invention is a method for measuring the spatial posture of an object based on a monocular camera, comprising the following steps: step S1, fixing a label with a reference shape of the object to be measured to the object to be measured, recording the information of the reference shape on the label, and calibrating the monocular camera; step S2, photographing the object to be measured, obtaining an image of the object to be measured with the label, converting the color image into a grayscale image, and filtering the random noise in the image using a Gaussian filter; step S3, using the Canny edge detection algorithm to detect the edge in the image, and connecting the edge to form a shape; step S4, using the convex hull algorithm to find a matching pre-recorded reference shape, and locating the pixel coordinates of the corner points of the reference shape; step S5, applying the PNP algorithm to solve the transformation relationship of the label with the reference shape of the object to be measured relative to the monocular camera to obtain a transformation matrix, parsing the translation and rotation from the change matrix, and calculating the position and posture of the label at this time. The present invention uses a monocular camera to monitor the label on the object to be measured, and calculates the spatial posture of the label through a specific shape matching algorithm, thereby solving the problem that the target position and posture are difficult to determine during the process of measuring the spatial 3D information of the object. The present invention extracts label information on the object to be measured in the real-time image and performs calculations through an algorithm, thereby reducing subjective errors and safety hazards caused by manual judgment of the spatial posture of the target object.
[0067] An object space posture measurement device based on a monocular camera according to the technical solution of an embodiment of the present invention has the same beneficial effects as an object space posture measurement method based on a monocular camera according to the technical solution of an embodiment of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 is a flow chart of a method for measuring the spatial pose of an object based on a monocular camera according to an exemplary embodiment;
[0069] Figure 2 is a schematic structural diagram of a device for measuring the spatial position and posture of an object based on a monocular camera according to an exemplary embodiment;
[0070] Figure 3 (a) and Figure 3 (b) are comparisons of the de-distortion effects before and after camera calibration (Figure 3 (a) image before camera calibration, Figure 3 (b) de-distortion image after camera calibration);
[0071] Figure 4 It is a schematic diagram of a plurality of preset specific shape labels;
[0072] Figure 5 (a), Figure 5 (b) and Figure 5 (c) are grayscale and noise reduction comparison images of the original image of the same frame (Figure 5 (a) is a color image of the same frame image, Figure 5 (b) is a grayscale image of Figure 5 (a) after grayscale processing, and Figure 5 (c) is an effect image of Figure 5 (a) after grayscale and noise reduction processing);
[0073] Figure 6 Based on Figure 4 Edge detection and connection effect diagram;
[0074] Figure 7 Find and draw corner point demonstration diagrams for real-world applications. DETAILED DESCRIPTION
[0075] In order to more clearly illustrate the technical features of the solution of the present invention, the present invention is described in detail below through specific implementation methods and in conjunction with the accompanying drawings.
[0076] Since structured light technology and binocular vision technology have problems such as limited application scenarios and large amount of calculation, the present invention can also be applied in outdoor environments with strong lighting changes. Based on the improvement of computer algorithms, a real-time measurement technology for object posture that meets the needs is provided.
[0077] like Figure 1 As shown, an embodiment of the present invention provides a method for measuring the spatial posture of an object based on a monocular camera, comprising the following steps:
[0078] Step S1, fixing a label with a reference shape of the object to be measured to the object to be measured, recording the information of the reference shape on the label, and calibrating the monocular camera;
[0079] Step S2, photographing the object to be tested, obtaining an image of the object to be tested with a label, converting the color image into a grayscale image, and using a Gaussian filter to filter random noise in the image;
[0080] Step S3, using the Canny edge detection algorithm to detect edges in the image and connect the edges to form a shape;
[0081] Step S4, using a convex hull algorithm to find a matching pre-recorded reference shape and locate the pixel coordinates of the corner points of the reference shape;
[0082] Step S5, applying the PNP algorithm to solve the transformation relationship between the tag with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix, analyzing the translation and rotation from the change matrix, and calculating the position and posture of the tag at this time.
[0083] The present invention can complete the spatial posture detection of the object to be measured using only a monocular camera; the calculation efficiency can meet the requirement of real-time grasp of the posture of the object to be measured in space.
[0084] As a possible implementation of this embodiment, in step S1, a label is preset: the reference shape inner angle and side length ratio of the label containing the reference shape of the object to be measured are recorded to provide a matching standard for the reference shape detected in the image; the information of the reference shape on the label is preset according to the usage scenario as follows:
[0085] ),
[0086] in, The angles of the interior angles of each reference shape, , ,..., is the side length of each reference shape.
[0087] Camera calibration: Use a chessboard to calibrate the camera to obtain the camera's intrinsic coefficients and distortion coefficients for calculation and distortion compensation. The intrinsic coefficients are used for pnp calculations, and the distortion is used to compensate and restore the real picture.
[0088] As a possible implementation of this embodiment, in step S2, the color image is converted into a grayscale image to reduce the amount of data and facilitate transmission and calculation; the grayscale image is smoothed using Gaussian filtering to remove random noise in the image.
[0089] As a possible implementation of this embodiment, in step S3, the Canny edge detection algorithm is used to detect edge lines in the image, and they are connected by the edge connection algorithm to form a complete edge; the coding-based region growing algorithm is applied to encode the edge pixels in the image according to the rules, and then starting from the starting point, similar edge points are found according to the coding values, thereby realizing edge connection and polygon closure. The formula for connecting edges to form a shape is:
[0090] ,
[0091] in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
[0092] As a possible implementation of this embodiment, in step S4, a convex hull algorithm is used to find a reference shape formed in a polygon, and the internal angle and side length ratio of the reference shape found are calculated. The calculation result of each reference shape is compared with a specific shape with a predefined fixed internal angle and side length ratio, and the position of the label in the image is obtained, and the pixel coordinates of the corner points of the specific polygon at this time are output. The expression for finding a matching pre-recorded reference shape is:
[0093] ,
[0094] in, For the matching result, is the process function for comparison, is the output image edge information of step S3, The reference shape information preset in step S1.
[0095] As a possible implementation of this embodiment, the PNP algorithm is used to solve the transformation relationship between the label with a specific shape and the camera to obtain a transformation matrix, and the translation and rotation are analyzed from the transformation matrix to obtain the position and posture of the label at this time; the step S5 includes:
[0096] Step S51, using the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix:
[0097] ,
[0098] in, is the set of three-dimensional points of the object to be measured (usually the vertices of the object), is a set of two-dimensional points in the image of the object to be tested (usually corresponding points in the image), is the camera intrinsic parameter matrix, is the camera distortion coefficient;
[0099] Step S52: Analyze the translation amount from the change matrix and the amount of rotation :
[0100] ,
[0101] ,
[0102] in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function;
[0103] Step S53, further decomposing the translation amount and the amount of rotation , get the position and posture of the tag at this time:
[0104] ,
[0105] ,
[0106] ,
[0107] ,
[0108] in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
[0109] In a second aspect, an embodiment of the present invention provides a device for measuring the spatial position of an object based on a monocular camera, comprising:
[0110] The camera calibration module is used to fix a label with a reference shape of the object to be measured to the object to be measured, record the information of the reference shape on the label, and calibrate the monocular camera;
[0111] An image capturing module is used to capture images of the object to be tested, obtain images of the object to be tested with labels attached thereto, convert the color images into grayscale images, and use a Gaussian filter to filter random noise in the images;
[0112] An edge detection module is used to detect edges in an image using the Canny edge detection algorithm and connect the edges to form shapes;
[0113] A reference coordinate acquisition module, used to find a matching pre-recorded reference shape using a convex hull algorithm and locate the pixel coordinates of the corner points of the reference shape;
[0114] The posture calculation module is used to apply the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix, analyze the translation and rotation from the change matrix, and calculate the position and posture of the label at this time.
[0115] As a possible implementation of this embodiment, the camera calibration module pre-sets the reference shape information on the label according to the usage scenario, and the information is:
[0116] ),
[0117] in, The angles of the interior angles of each reference shape, , ,..., is the side length of each reference shape.
[0118] As a possible implementation of this embodiment, the edge detection module connects the edges to form a shape using the following formula:
[0119] ,
[0120] in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
[0121] As a possible implementation of this embodiment, the reference coordinate acquisition module searches for an expression that matches a pre-recorded reference shape:
[0122] ,
[0123] in, For the matching results, is the process function for comparison, is the output image edge information of the edge detection module, Reference shape information preset for the camera calibration module.
[0124] As a possible implementation of this embodiment, the posture calculation module includes:
[0125] The PNP algorithm module is used to apply the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix:
[0126] ,
[0127] in, is the set of three-dimensional points of the object to be measured (usually the vertices of the object), is a set of two-dimensional points in the image of the object to be tested (usually corresponding points in the image), is the camera intrinsic parameter matrix, is the camera distortion coefficient;
[0128] Parsing module, used to parse the translation from the change matrix and the amount of rotation :
[0129] ,
[0130] ,
[0131] in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function;
[0132] The pose module is used to further decompose the translation and the amount of rotation , get the position and posture of the tag at this time:
[0133] ,
[0134] ,
[0135] ,
[0136] ,
[0137] in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
[0138] The following takes the spatial posture measurement of the hanging part as an example to explain in detail the spatial posture measurement technology of the present invention.
[0139] At the current stage, transmission towers use human eye observation and positioning sensor methods when hoisting parts. The human eye observation method relies on ground personnel or high-altitude workers to observe the position and posture of the hoist to make adjustments. It is greatly affected by the environment, such as weather and light, which will affect the accuracy of observation. It relies on the operator's experience and judgment, has subjective errors, and has safety hazards.
[0140] During implementation, the present invention first fixes a label with a specific shape of a hanger to an object such as a hanging component, and records the information of the convex polygon (specific shape of the hanger) on the label, and calibrates the monocular camera at the same time. Next, the camera is used to shoot the object and obtain an image with the label. In order to reduce noise interference, the color image is converted to a grayscale image, and a Gaussian filter is applied to denoise the image. Subsequently, the Canny edge detection algorithm is used to detect the edges in the image, and the shape of the convex polygon is formed by the edge connection algorithm.
[0141] In order to locate the pixel coordinates of the corner points of the convex polygon, the convex hull algorithm is used to find the shape that matches the pre-recorded convex polygon. On this basis, the PNP algorithm is used to solve the transformation relationship between the tag and the camera to obtain the transformation matrix. By analyzing the translation and rotation in the transformation matrix, the position and posture of the tag at the current moment can be accurately obtained.
[0142] The present invention first fixes and records the specific shape labels on the object and calibrates the camera. Next, take an image of the object to be tested with the label, convert it to grayscale and apply Gaussian filtering to remove noise. Then, use the Canny edge detection algorithm and edge connection algorithm to detect and form the edge shape in the image. Use the convex hull algorithm to match the pre-recorded convex polygons and locate the pixel coordinates of their corner points. Finally, use the PNP algorithm to solve the transformation relationship between the label and the camera, parse the translation and rotation, and determine the position and posture of the label.
[0143] The purpose of camera calibration is to determine the intrinsic parameter matrix of the fixed-focus lens monocular camera module. The accuracy of the calibrated intrinsic parameter matrix directly affects the actual measurement results. The camera intrinsic parameter matrix is represented by K, and its elements are as follows:
[0144] ,
[0145] in, and are the horizontal focal length and vertical focal length on the image plane respectively; and are the horizontal and vertical coordinates of the principal point (image center) on the image plane, respectively.
[0146] De-distortion is a step in image processing, which aims to correct the image distortion caused by the camera lens so that geometric shapes such as lines and circles in the image are visually closer to their true shapes in three-dimensional space. The comparison of de-distortion effects before and after camera calibration is shown in Figure 3 (a) and Figure 3 (b).
[0147] The design of specific shapes on the tag follows the principle of adapting to practical applications. For example, when there is not much background interference, a design with a low degree of shape complexity can be used to reduce the calculation of parameters. In complex environments, the potential recognition area of the tag should have more feature information to prevent misidentification and failure to recognize. For example, Apriltag is an open source radio frequency identification (RFID) tag for robots and automatic navigation systems. It uses a coding format called "TAG", which is a coding system designed specifically for machine vision and can be quickly recognized by machine vision systems. Figure 4 As shown, it has relatively complete feature information and is easy to generate and record.
[0148] Grayscale and noise reduction are two common steps in image processing, which can improve the quality of images and provide a better basis for subsequent image analysis, recognition and processing. Grayscale is the process of converting a color image as shown in Figure 5 (a) into a grayscale image as shown in Figure 5 (b), that is, converting the RGB (red, green and blue) color value of each pixel in the image into a single grayscale value. Grayscale values are usually between 0 (black) and 255 (white). Noise reduction refers to reducing or eliminating noise in an image to improve the clarity and readability of the image. Noise can be random noise, salt and pepper noise, etc., which will interfere with the useful information in the image. The noise reduction effect is shown in Figure 5 (c).
[0149] The Canny edge detection algorithm is used to detect edge lines in the image, and they are connected through the edge connection algorithm to form a complete edge. The coding-based region growing algorithm is applied to encode the edge pixels in the image according to the rules, and then starting from the starting point, similar edge points are found according to the coding value, so as to achieve edge connection and polygon closure. The edge detection is performed based on Figure 5 (c). The effect is as follows: Figure 6 shown.
[0150] Use the convex hull algorithm to find the convex polygons in the polygon, calculate the internal angle and side length ratio of the found convex polygons, compare the calculation results of each convex polygon with a pre-defined fixed internal angle and side length ratio, and find the position of the label in the image, and output the pixel coordinates of the corner points of the specific polygon at this time. After finding the corner point position of the label on the image, the corner point coordinates can be drawn on the original image to verify the accuracy of the corner point pixel coordinate extraction process. The effect is as follows Figure 7 shown.
[0151] The present invention not only completes the spatial posture detection of the object to be detected, but also reduces the subjective errors and safety hazards caused by manual judgment of the spatial posture of the target object.
[0152] Compared with the prior art, the present invention has the following advantages:
[0153] (1) The present invention only requires a monocular camera. With a small amount of preliminary preparation, it can realize real-time and accurate collection of the spatial position and posture information of an object. The hard conditions required are not high, and a computer with sufficient computing power and a high-frame monocular camera module are sufficient.
[0154] (2) The present invention provides a method for objectively evaluating the spatial position of an object, and its accuracy is less affected by environmental interference. Especially during high-altitude operations, the advantages of this technology are greater, providing a complete set of objective high-altitude operation technologies suitable for complex environments.
[0155] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for measuring the spatial position of an object based on a monocular camera, characterized in that: The steps include: Step S1, fixing a label with a reference shape of the object to be measured to the object to be measured, recording the information of the reference shape on the label, and calibrating the monocular camera; Step S2, photographing the object to be tested, obtaining an image of the object to be tested with a label, converting the color image into a grayscale image, and using a Gaussian filter to filter random noise in the image; Step S3, using the Canny edge detection algorithm to detect edges in the image and connect the edges to form a shape; Step S4, using a convex hull algorithm to find a matching pre-recorded reference shape, and locate the pixel coordinates of the corner points of the reference shape; the use of the convex hull algorithm to find a matching pre-recorded reference shape is specifically as follows: using the convex hull algorithm to find a convex polygon formed in a polygon, calculating the internal angle and side length ratio of the found convex polygon, comparing the calculation result of each convex polygon with a specific shape with a pre-defined fixed internal angle and side length ratio, obtaining the position of the label in the image, and outputting the pixel coordinates of the corner points of the specific polygon at this time; Step S5, applying the PNP algorithm to solve the transformation relationship between the tag with the reference shape of the object to be measured and the monocular camera to obtain a transformation matrix, parsing the translation and rotation from the change matrix, and calculating the position and posture of the tag at this time; In step S1, the reference shape information on the label is pre-set according to the usage scenario, and the information is: ), in, is the angle of each reference shape's interior angle, , ,..., is the side length of each reference shape; In step S4, the expression for finding a matching pre-recorded reference shape is: , in, For the matching result, is the process function for comparison, is the output image edge information of step S3, The reference shape information preset in step S1; The step S5 comprises: Step S51, using the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix: , in, is the three-dimensional point set of the object to be measured, is the two-dimensional point set of the image of the object to be tested, is the camera intrinsic parameter matrix, is the camera distortion coefficient; Step S52: Analyze the translation amount from the change matrix and the amount of rotation : , , in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function; Step S53, further decomposing the translation amount and the amount of rotation , get the position and posture of the tag at this time: , , , , in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
2. The method for measuring the spatial position of an object based on a monocular camera according to claim 1, characterized in that: In step S3, the formula for connecting edges to form a shape is: , in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
3. A device for measuring the spatial position of an object based on a monocular camera, characterized in that: include: The camera calibration module is used to fix a label with a reference shape of the object to be measured to the object to be measured, record the information of the reference shape on the label, and calibrate the monocular camera; An image capturing module is used to capture images of the object to be tested, obtain images of the object to be tested with labels attached thereto, convert the color images into grayscale images, and use a Gaussian filter to filter random noise in the images; An edge detection module is used to detect edges in an image using the Canny edge detection algorithm and connect the edges to form shapes; A reference coordinate acquisition module is used to use a convex hull algorithm to find a matching reference shape that is recorded in advance, and locate the pixel coordinates of the corner points of the reference shape; the use of the convex hull algorithm to find a matching reference shape that is recorded in advance is specifically as follows: using the convex hull algorithm to find a convex polygon formed in a polygon, calculating the internal angle and side length ratio of the found convex polygon, comparing the calculation result of each convex polygon with a specific shape with a predefined fixed internal angle and side length ratio, obtaining the position of the label in the image, and outputting the pixel coordinates of the corner points of the specific polygon at this time; The posture calculation module is used to apply the PNP algorithm to solve the transformation relationship between the tag with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix, analyze the translation and rotation from the change matrix, and calculate the position and posture of the tag at this time; The camera calibration module pre-sets the reference shape information on the label according to the usage scenario, and the information is: ), in, The angles of the interior angles of each reference shape, , ,..., is the side length of each reference shape; The expression used by the reference coordinate acquisition module to find a matching pre-recorded reference shape is: , in, For the matching result, is the process function for comparison, is the output image edge information of the edge detection module, Reference shape information pre-set for the camera calibration module; The posture calculation module comprises: The PNP algorithm module is used to apply the PNP algorithm to solve the transformation relationship between the label with the reference shape of the object to be measured and the monocular camera to obtain the transformation matrix: , in, is the three-dimensional point set of the object to be measured, is the two-dimensional point set of the image of the object to be tested, is the camera intrinsic parameter matrix, is the camera distortion coefficient; Parsing module, used to parse the translation from the change matrix and the amount of rotation : , , in, is the rotation vector from Get from the function; is the translation vector, also from Get from the function; The pose module is used to further decompose the translation and the amount of rotation , get the position and posture of the tag at this time: , , , , in, is the rotation matrix, from get; represents the elements in the rotation matrix, is the translation vector The three components of , , are the rotation angles around the Z, Y and X axes respectively. is the translation vector of the label relative to the camera.
4. The object space posture measurement device based on a monocular camera according to claim 3, characterized in that: The edge detection module connects the edges to form a shape using the following formula: , in, represents the output image, i.e., the connected edges; represents the merge region function, which merges all grown regions into a complete edge graph; represents the region growing function, which starts from a single seed point and grows the region according to the similarity criterion; Represents the Canny edge detection function, which is used to detect edges in an image; represents the input image; Respectively represent the low threshold and high threshold of Canny edge detection; Represents the similarity criterion for region growing; Represents the seed point selection function, which selects the starting point from the edge image for region growing.
