A ranging method and system
By using a specially designed QR code to assist in distance measurement, the problems of low accuracy and high cost in existing technologies have been solved, achieving high-precision and low-cost distance measurement results, which are suitable for visual distance measurement and train positioning systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING GUOKE QIMING EDUCATION TECH CO LTD
- Filing Date
- 2022-11-22
- Publication Date
- 2026-05-15
AI Technical Summary
Existing ranging technologies suffer from low ranging accuracy and high cost.
A specially designed QR code is used for distance measurement. By acquiring the contour in the distance measurement image, the cluster of positioning points is determined, converted to the world coordinate system, and the vertical distance from the QR code to the origin is calculated.
It improves ranging accuracy, reduces ranging costs, and has a wide range of applications, including visual ranging and train positioning systems.
Smart Images

Figure CN116086344B_ABST
Abstract
Description
Technical Field
[0001] This invention discloses a ranging method and system, belonging to the field of ranging technology. Background Technology
[0002] To determine the current location of a person or object, it is necessary to obtain the distance between the person or object and a specific object. Existing methods for measuring this distance mainly include UWB ranging, binocular ranging, and RGBD ranging.
[0003] The principle of UWB ranging is to calculate the distance based on the transmission time of wireless signals between devices and the speed of light. However, it cannot simultaneously balance cost and accuracy, and its cost is relatively high. The binocular ranging method calculates the distance using the parallax of two images. Although its cost is lower, its error is relatively large. The RGBD ranging method determines the distance based on the RGB image and the depth image, which also suffers from the problem of large error. Summary of the Invention
[0004] The purpose of this application is to provide a ranging method and system to solve the technical problems of low ranging accuracy and high cost in the prior art.
[0005] A first aspect of the present invention provides a ranging method, comprising:
[0006] Step 1: Acquire the ranging image;
[0007] Step 2: Obtain the contour in the ranging image, and determine multiple positioning points based on the contour to obtain a positioning point cluster;
[0008] Step 3: Determine the QR code in the ranging image based on the cluster of positioning points;
[0009] Step 4: Determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the QR code and the camera's intrinsic parameter matrix and distortion matrix;
[0010] Step 5: Transform the three-dimensional coordinates of the QR code into the world coordinate system, and determine the vertical distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system.
[0011] Preferably, step 2 specifically includes:
[0012] Obtain the double-layer contour from the binary image of the ranging image;
[0013] Determine the inner contour of the double-layer contour;
[0014] Obtain the centroid of the inner contour, record the centroid as a positioning point, and obtain a positioning point cluster.
[0015] Preferably, step 3 specifically includes:
[0016] Determine the location points representing the QR code from the cluster of location points;
[0017] Obtain the binary array between the positioning points of the QR code;
[0018] The QR code in the ranging image is determined based on the binary array.
[0019] Preferably, determining the positioning point representing the QR code from the positioning point cluster specifically includes:
[0020] The system slides along the cluster of positioning points using a preset rectangular window, and determines whether the positioning point contained in the rectangular window is a positioning point of a QR code after each slide.
[0021] If so, exclude the positioning points of the QR code and continue to slide the rectangular window until the number of positioning points is less than the preset value;
[0022] If not, exclude one of the positioning points in the rectangular window and continue sliding the rectangular window until the number of positioning points is less than the preset value.
[0023] Preferably, determining whether the positioning point contained within the rectangular window after each swipe is a positioning point of a QR code specifically includes:
[0024] Obtain the distance and included angle between the two straight lines formed by the positioning points within the rectangular window;
[0025] Calculate the difference between the distance and the included angle and the corresponding distance and included angle in the physical model of the QR code. If the difference is less than a preset difference threshold, the positioning point contained in the rectangular window is the positioning point of a QR code.
[0026] Preferably, determining the QR code in the ranging image based on the binary array specifically includes:
[0027] The number of directional markers in the binary array is obtained, and it is determined whether the number is the same as the number of directional markers in the QR code physical model. If they are the same, the binary array is identified by ID, and the check code in the binary array is verified. If the verification passes, the QR code of the QR code physical model in the ranging image is obtained.
[0028] Preferably, after determining the location point representing the QR code from the location point cluster, the method further includes:
[0029] Determine the area between the positioning points of the QR code;
[0030] Perform perspective transformation and color adjustment on the area;
[0031] Accordingly, the binary array between the positioning points of the QR code is obtained, specifically as follows:
[0032] Obtain the binary array between the positioning points of the QR code after perspective transformation and color adjustment.
[0033] Preferably, step 5 specifically includes:
[0034] Based on the extrinsic parameter matrix, determine the coordinates of the origin of the world coordinate system in the camera coordinate system;
[0035] In the camera coordinate system, determine the distance between the coordinates of the origin and the three-dimensional coordinates of the QR code;
[0036] The three-dimensional coordinates of the QR code are converted into coordinates in the world coordinate system, and the vertical distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system is obtained.
[0037] Preferably, the QR code includes four positioning areas located at the four corners and a binary array disposed between the four positioning areas;
[0038] One edge point of the binary array is a directional plotting point, and the binary array includes a check code;
[0039] The inner boundary of the positioning area is formed by an arc and two straight lines connecting the two endpoints of the arc respectively;
[0040] The outer boundary of the positioning area is an arc-shaped boundary, and the outer boundary and the inner boundary form a closed area.
[0041] Alternatively, the inner boundary of the positioning area may be formed by an arc;
[0042] The outer boundary of the positioning area is a right-angled side, and the outer boundary and the inner boundary form a closed area.
[0043] A second aspect of the present invention provides a ranging system, comprising:
[0044] Image acquisition module, the image acquisition module is used to acquire ranging images;
[0045] A cluster determination module is used to acquire the contour in the ranging image, determine multiple positioning points based on the contour, and obtain a positioning point cluster.
[0046] A QR code determination module is used to determine the QR code in the ranging image based on the location point cluster.
[0047] A coordinate determination module is used to determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the QR code and the camera's intrinsic parameter matrix and distortion matrix.
[0048] The distance determination module is used to transform the three-dimensional coordinates of the QR code into the world coordinate system and determine the vertical distance between the QR code and the plane formed by the x and y axes of the origin of the world coordinate system.
[0049] The ranging method and system of the present invention have the following advantages compared with the prior art:
[0050] The method of this invention utilizes QR codes for assisted distance measurement, offering high accuracy, simplicity, fast calculation speed, and wide applicability. For example, it can be applied to visual distance measurement, where the subject holds a physical model of the QR code, and a camera is positioned at the visual target to obtain the distance between the subject and the target. Alternatively, it can be applied to train positioning systems, using the QR code as a distance marker to obtain the distance between the train and the QR code, thereby determining the train's position based on this distance and the distance marker.
[0051] The specially designed QR code of this invention can be accurately identified even if it is small in size, thus improving the accuracy of identification.
[0052] The system of the present invention uses simple equipment, thus reducing the cost of ranging and providing accurate ranging with low error under conditions of low cost and low technical risk. Attached Figure Description
[0053] Figure 1 This is a flowchart illustrating the ranging method in an embodiment of the present invention;
[0054] Figure 2 This is one form of QR code in an embodiment of the present invention;
[0055] Figure 3 for Figure 2 A schematic diagram showing the location of the verification code in the QR code shown;
[0056] Figure 4 This is a schematic diagram showing the location of the verification code in another form of QR code in an embodiment of the present invention;
[0057] Figure 5 This is a schematic diagram of the ranging system in an embodiment of the present invention.
[0058] In the diagram, 1 represents the positioning area; 2 represents the binary array; 3 represents the direction markers; 4 represents the positioning point; 5 represents the check code; 101 represents the image acquisition module; 102 represents the cluster determination module; 103 represents the QR code determination module; 104 represents the coordinate determination module; and 105 represents the distance determination module. Detailed Implementation
[0059] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of the invention with unnecessary detail.
[0060] like Figure 1 As shown, the ranging method of this invention includes:
[0061] Step 1: Obtain a ranging image, which contains a QR code for ranging.
[0062] In this embodiment of the invention, an improved, specially designed QR code is used for distance measurement. The improved QR code includes four positioning areas 1 located at the four corners or three positioning areas located in a triangle, and a binary array 2 disposed between the positioning areas 1;
[0063] One edge point of binary array 2 is the direction plotting point 3, and binary array 2 includes check code 5.
[0064] Figure 2 In one embodiment of the present invention, the QR code has a positioning area 1 whose inner boundary is formed by an arc and two straight lines connecting the two endpoints of the arc; the outer boundary of the positioning area 1 is an arc-shaped boundary, and the outer boundary and the inner boundary form a closed area. The binary array 2 of the QR code is positioned between four positioning areas 1. The check code 5 used consists of two parity check codes, such as... Figure 3 As shown, the area corresponding to the checksum above is a black block, and the area corresponding to the checksum below is a white block.
[0065] Figure 4 In another embodiment of the present invention, the location of the check code in a QR code is shown. The inner boundary of the positioning area 1 of the QR code is an arc, and the outer boundary is a right angle, forming a closed area. The binary array 2 of the QR code is set between the four positioning areas 1. The check code 5 used is four parity check codes, wherein the area corresponding to the top check code is a black block, and the areas corresponding to the other three check codes are white blocks.
[0066] The specially designed QR code of this invention uses a double-layer contour positioning area, which enables accurate recognition even if the QR code in the ranging image is very small, thus improving the recognition rate. Furthermore, the binary array set between the positioning areas in this invention is relatively large, thereby improving the recognition accuracy. Moreover, this invention adaptively sets the number of check codes according to the size of the binary array, thereby significantly improving the recognition accuracy.
[0067] Step 2: Obtain the contour in the ranging image, determine multiple positioning points based on the contour, and obtain a positioning point cluster, specifically including:
[0068] Step 21: Obtain the double-layer contour from the binary image of the ranging image.
[0069] In this embodiment of the invention, a binary image of the ranging image is first obtained, thereby converting the color space of the ranging image;
[0070] Then, contour features are obtained from the binary image of the ranging image. Since the contour features contain noise information, it is necessary to filter out the contour coordinates that are repeatedly identified, and then filter out the double-layer contours. In this embodiment of the invention, the double-layer contours are the positioning areas of the QR code.
[0071] Step 22: Determine the inner contour in the double-layer contour;
[0072] Step 23: Obtain the centroid of the inner contour, record the centroid as the positioning point, and obtain the positioning point cluster.
[0073] Step 3: Based on the cluster of positioning points, determine the QR code in the ranging image, specifically including:
[0074] Step 31: Determine the location points representing the QR code from the location point cluster.
[0075] In this invention, to locate a QR code from a ranging image, it is necessary to determine the positioning point representing the QR code.
[0076] In this invention, the positioning point representing the QR code is determined as follows:
[0077] The system uses a pre-defined rectangular window to slide along a cluster of positioning points and determines whether the positioning points contained within the rectangular window after each slide are positioning points for a QR code.
[0078] If so, exclude the QR code's positioning points and continue sliding the rectangular window until the number of positioning points is less than the preset value;
[0079] If not, exclude one of the anchor points in the rectangular window and continue sliding the rectangular window until the number of anchor points is less than the preset value.
[0080] The determination of whether the positioning point contained within the rectangular window after each swipe is a positioning point of a QR code specifically includes:
[0081] Get the distance and included angle between two straight lines formed by the positioning points within a rectangular window;
[0082] Calculate the difference between the distance and the included angle and the corresponding distance and included angle in the physical model of the QR code. If the difference is less than the preset difference threshold, the positioning point contained in the rectangular window is the positioning point of a QR code.
[0083] In this embodiment of the invention, the size of the rectangular window is the same as the size of the QR code. Taking the improved QR code with 4 positioning points as an example, the specific implementation process of step 31 is explained below:
[0084] The system slides along a cluster of positioning points using a pre-defined rectangular window and determines whether the four positioning points within the rectangular window constitute a positioning point for a QR code after each slide.
[0085] If so, exclude the 4 positioning points within the rectangular window and continue sliding the rectangular window. Each time you slide, the rectangular window contains 4 positioning points until the number of positioning points is less than the preset value of 4. When the positioning point within the rectangular window is a positioning point of a QR code, the sliding step of the rectangular window is 2 columns of positioning points. At other times, the sliding step is 1 column of positioning points.
[0086] If not, exclude one of the positioning points in the rectangular window. The excluded positioning point is the positioning point located at the upper left corner of the rectangular window. Continue to slide the rectangular window, with the sliding step being one column of positioning points, until the number of positioning points is less than the preset value of 4.
[0087] The determination of whether the positioning point contained within the rectangular window after each swipe is a positioning point of a QR code specifically includes:
[0088] A. Obtain the distance and included angle between two straight lines formed by the positioning points within the rectangular window. Specifically:
[0089] Grouping and denoising the positioning points in the positioning point cluster: First, randomly select one positioning point from the positioning point cluster, and then select the three closest positioning points from this point set as the initial group. The rectangular window then opens and slides from this initial group.
[0090] Classify the four positioning points within the rectangular window into four groups (top left, bottom left, top right, bottom right), denoted as group 0, group 1, group 2, and group 3. Then calculate the distance between the line connecting group 0 and group 3 and the line connecting group 1 and group 2, the angle between the line connecting group 0 and group 3 and the line connecting group 1 and group 2, the angle between the line connecting group 0 and group 2 and the line connecting group 1 and group 3, and the angle between the line connecting group 0 and group 1 and the line connecting group 2 and group 3.
[0091] B. After obtaining the above distance and angle, calculate the difference between the distance and angle and the corresponding distance and angle in the QR code physical model. If the difference is less than the preset difference threshold, the positioning point contained in the rectangular window is the positioning point of a QR code.
[0092] In this embodiment of the invention, after determining the location points of the QR code, in order to improve the accuracy of subsequent recognition, a perspective transformation is performed on the area between the four location points to convert it to a normalized positive direction; then, the color of each pixel of the perspective-transformed QR code is adjusted to make the blacks darker and the whites whiter.
[0093] Step 32: Obtain the binary array between the positioning points of the QR code, specifically:
[0094] Obtain the binary array between the positioning points of the QR code after perspective transformation and color adjustment.
[0095] Step 33: Determine the QR code in the ranging image based on the binary array, specifically including:
[0096] Obtain the number of directional markers in the binary array, and determine whether the number is the same as the number of directional markers in the QR code physical model. If they are the same, perform ID recognition on the binary array and verify it based on the check code in the binary array. If the verification passes, obtain the QR code in the ranging image of the QR code physical model.
[0097] Step 33 will continue to be described in detail using the above embodiments:
[0098] Obtain the orientation points and their number in the binary array, and rotate the QR code according to the orientation points to determine the orientation of the binary array.
[0099] The number of directional markers is compared with the number of directional markers in the QR code physical model. If the number does not match, it is considered an incorrect recognition; if they match, it is considered a correct recognition. Then, the binary array is further processed for ID recognition based on the coordinates. If the verification code fails, it is considered an incorrect recognition; if the verification code passes, it is considered a correct recognition, thus obtaining the QR code in the ranging image of the QR code physical model.
[0100] Step 4: Determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the QR code and the camera's intrinsic parameter matrix and distortion matrix.
[0101] After obtaining the four positioning points of all QR codes, this embodiment of the invention, in conjunction with the QR code physical model, camera intrinsic parameter matrix and distortion matrix, calculates the three-dimensional coordinates of the QR code center in the camera coordinate system. The Euclidean distance between the QR code and the camera, as well as the angle between the QR code and the x, y, z coordinate axes of the camera coordinate system, are obtained through the three-dimensional coordinates of the QR code in the camera coordinate system.
[0102] Step 5: Transform the 3D coordinates of the QR code to the world coordinate system, and determine the perpendicular distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system. Specifically, this includes:
[0103] Based on the extrinsic parameter matrix, determine the coordinates of the origin of the world coordinate system in the camera coordinate system;
[0104] In the camera coordinate system, determine the distance between the coordinates of the origin and the three-dimensional coordinates of the QR code;
[0105] Convert the three-dimensional coordinates of the QR code to coordinates in the world coordinate system, and obtain the vertical distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system.
[0106] In this embodiment of the invention, the rotation and translation matrices of the world coordinate system in the camera coordinate system are obtained through the extrinsic parameter matrix, thereby calculating the coordinates of the origin of the world coordinate system (point E) in the camera coordinate system. The distance between the coordinates of the QR code in the camera coordinate system and the coordinates of point E in the camera coordinate system is calculated and used as the distance from the center point of the QR code to point E.
[0107] Then, the vertical distance is calculated. At this point, the coordinates of the QR code in the camera coordinate system need to be converted to the coordinates in the world coordinate system. In this way, the vertical distance from the QR code to the plane formed by the xy axes of point E is calculated and denoted as the distance to be measured.
[0108] The method of this invention utilizes QR codes for assisted distance measurement, offering high accuracy, simplicity, fast calculation speed, and wide applicability. For example, it can be applied to visual acuity measurement, where the subject holds a physical model of the QR code, and a camera is positioned at the visual target to obtain the distance between the subject and the target. Alternatively, it can be applied to train positioning systems, using the QR code as a distance marker to determine the distance between the train and the QR code, thus pinpointing the train's location. This invention does not limit its specific application areas; it can be used in any scenario requiring distance measurement.
[0109] The specially designed QR code of this invention can be accurately identified even if it is small in size, thus improving the accuracy of identification.
[0110] A second aspect of the present invention provides a ranging system, such as Figure 5 As shown, it includes an image acquisition module 101, a cluster determination module 102, a QR code determination module 103, a coordinate determination module 104, and a distance determination module 105.
[0111] The image acquisition module 101 is used to acquire the ranging image;
[0112] The cluster determination module 102 is used to acquire the contour in the ranging image, determine multiple positioning points based on the contour, and obtain a positioning point cluster.
[0113] The QR code determination module 103 is used to determine the QR code in the ranging image based on the cluster of positioning points;
[0114] The coordinate determination module 104 is used to determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the intrinsic parameter matrix and distortion matrix of the QR code and the camera.
[0115] The distance determination module 105 is used to transform the three-dimensional coordinates of the QR code into the world coordinate system and determine the vertical distance between the QR code and the plane formed by the xy axes of the origin of the world coordinate system.
[0116] The system of the present invention uses simple equipment, thus reducing the cost of ranging and providing accurate ranging with low error under conditions of low cost and low technical risk.
[0117] The above description is merely a few embodiments of this application and is not intended to limit this application in any way. Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any changes or modifications made by those skilled in the art without departing from the scope of the technical solution of this application using the disclosed technical content are equivalent to equivalent implementation cases and fall within the scope of the technical solution.
Claims
1. A distance measurement method, characterized in that, Applications in visual acuity measurement include: Step 1: Acquire the ranging image; Step 2: Obtain the contour in the ranging image, and determine multiple positioning points based on the contour to obtain a positioning point cluster; Step 3: Determine the QR code in the ranging image based on the cluster of positioning points; Step 4: Determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the QR code and the camera's intrinsic parameter matrix and distortion matrix; Step 5: Transform the three-dimensional coordinates of the QR code into the world coordinate system, and determine the vertical distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system; The QR code includes four positioning areas located at the four corners and a binary array disposed between the four positioning areas; One edge point of the binary array is a directional plotting point, and the binary array includes a check code; The inner boundary of the positioning area is formed by an arc and two straight lines connecting the two endpoints of the arc respectively; The outer boundary of the positioning area is an arc-shaped boundary, and the outer boundary and the inner boundary form a closed area.
2. The ranging method according to claim 1, characterized in that, Step 2 specifically includes: Obtain the double-layer contour from the binary image of the ranging image; Determine the inner contour of the double-layer contour; Obtain the centroid of the inner contour, record the centroid as a positioning point, and obtain a positioning point cluster.
3. The ranging method according to claim 1, characterized in that, Step 3 specifically includes: Determine the location points representing the QR code from the cluster of location points; Obtain the binary array between the positioning points of the QR code; The QR code in the ranging image is determined based on the binary array.
4. The ranging method according to claim 3, characterized in that, Determining the location points representing the QR code from the location point cluster specifically includes: The system slides along the cluster of positioning points using a preset rectangular window, and determines whether the positioning point contained in the rectangular window is a positioning point of a QR code after each slide. If so, exclude the positioning points of the QR code and continue to slide the rectangular window until the number of positioning points is less than the preset value; If not, exclude one of the positioning points in the rectangular window and continue sliding the rectangular window until the number of positioning points is less than the preset value.
5. The ranging method according to claim 4, characterized in that, Determining whether the positioning point within the rectangular window after each swipe is a positioning point for a QR code specifically includes: Obtain the distance and included angle between the two straight lines formed by the positioning points within the rectangular window; Calculate the difference between the distance and the included angle and the corresponding distance and included angle in the physical model of the QR code. If the difference is less than a preset difference threshold, the positioning point contained in the rectangular window is the positioning point of a QR code.
6. The ranging method according to claim 3, characterized in that, Determining the QR code in the ranging image based on the binary array specifically includes: The number of directional markers in the binary array is obtained, and it is determined whether the number is the same as the number of directional markers in the QR code physical model. If they are the same, the binary array is identified by ID, and the check code in the binary array is verified. If the verification passes, the QR code of the QR code physical model in the ranging image is obtained.
7. The ranging method according to claim 3, characterized in that, After determining the location points representing the QR code from the cluster of location points, the method further includes: Determine the area between the positioning points of the QR code; Perform perspective transformation and color adjustment on the area; Accordingly, the binary array between the positioning points of the QR code is obtained, specifically as follows: Obtain the binary array between the positioning points of the QR code after perspective transformation and color adjustment.
8. The ranging method according to any one of claims 1-7, characterized in that, Step 5 specifically includes: Based on the extrinsic parameter matrix, determine the coordinates of the origin of the world coordinate system in the camera coordinate system; In the camera coordinate system, determine the distance between the coordinates of the origin and the three-dimensional coordinates of the QR code; The three-dimensional coordinates of the QR code are converted into coordinates in the world coordinate system, and the vertical distance from the QR code to the plane formed by the x and y axes of the origin of the world coordinate system is obtained.
9. A ranging system based on the ranging method according to any one of claims 1-8, characterized in that, include: Image acquisition module, the image acquisition module is used to acquire ranging images; A cluster determination module is used to acquire the contour in the ranging image, determine multiple positioning points based on the contour, and obtain a positioning point cluster. A QR code determination module is used to determine the QR code in the ranging image based on the location point cluster. A coordinate determination module is used to determine the three-dimensional coordinates of the QR code in the camera coordinate system based on the QR code and the camera's intrinsic parameter matrix and distortion matrix. The distance determination module is used to transform the three-dimensional coordinates of the QR code into the world coordinate system and determine the vertical distance between the QR code and the plane formed by the x and y axes of the origin of the world coordinate system.