A distance measurement method, storage medium and electronic device based on image matching
Through image acquisition, stereo correction and semi-global stereo matching algorithms, the problems of low image matching efficiency and poor adaptability in the existing technology are solved, and high-precision and high-resolution ranging are achieved, which improves the real-time and accuracy.
Patent Information
- Application Number
- CN202210345515.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-02
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2042-04-02
AI Technical Summary
The existing image matching algorithms have problems in the ranging system with low matching efficiency, sensitivity to environmental and lighting changes, and inability to adapt to irregular shape objects and complex background interference, which affects the ranging accuracy and real-time nature.
The distance measurement method based on image matching is adopted, including image acquisition, stereo correction, edge feature extraction, semi-global stereo matching and adaptive sampling, and the dense disparity map is restored through sparse disparity maps to calculate the target distance.
Output high-precision and high-resolution depth information without high computing power is improved, which improves the real-time and accuracy of distance measurement, reduces the amount of matching calculations, and is highly adaptable.
Smart Images

Figure CN114723769B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of measured distance measurement, and in particular to a distance measurement method, storage medium and electronic equipment based on image matching. Background Art
[0002] Most of the existing reconnaissance and indication systems use laser ranging, which is an active ranging method that requires active laser emission. The pulse method commonly used in long-distance ranging is to measure the propagation time from laser emission to reception to determine the distance of the target. The fatal disadvantage of this active ranging method is that it has poor concealment and is easy to expose itself. Although lasers in bands invisible to the human eye can be used, the opponent can still detect and counter it through photoelectric detectors.
[0003] The passive ranging method is to determine the distance of an object by analyzing the light radiation of the object itself. The advantage is that it is well concealed and not easily discovered by the enemy and exposed. The binocular ranging method is a relatively mature one among the passive ranging methods. It is an optical ranging method that imitates the human perception of distance with binoculars. It has the characteristics of non-contact passive measurement, simplicity and reliability.
[0004] Image matching is the most critical link in binocular ranging. The accuracy and speed of image matching greatly affect the ranging accuracy and real-time performance of the ranging system. In practical applications, many existing image matching algorithms have the following problems: (1) matching efficiency needs to be improved to meet the real-time performance of the system; (2) matching results are greatly affected by changes in the environment and lighting; (3) matching of irregularly shaped objects is not yet suitable; (4) interference from complex backgrounds, etc. Summary of the invention
[0005] In order to overcome the defects in the above-mentioned prior art, the present invention proposes a ranging method, storage medium and electronic device based on image matching. The method of the present invention has the advantage of being able to output high-precision and high-resolution depth information without requiring high computing power.
[0006] To achieve the above object, in a first aspect, the present invention provides a distance measurement method based on image matching, the method comprising the following steps:
[0007] S1: Collect the image of the target to be measured;
[0008] S2: Perform stereo correction on the acquired image according to the stereo correction matrix;
[0009] S3: extract edge features of the stereo-rectified image;
[0010] S4: Use the semi-global stereo matching algorithm to perform stereo matching and obtain a sparse disparity map;
[0011] S5: Adaptively sample the sparse disparity map to restore the dense disparity map;
[0012] S6: Obtaining the distance between the detection point and the target to be detected according to the dense disparity map.
[0013] As an optional embodiment, the stereo correction matrix in step S2 is determined according to the following method:
[0014] S21: Calculation Where T = [T x T y T z ] T ;
[0015] S22: Make e2 and e1 orthogonal, select the cross product of the principal optical axis direction (0, 0, 1) and e1, and calculate
[0016] S23: Calculate e3=e1×e2;
[0017] S24: Multiplying the rotation matrix of the camera used to acquire the image of the target to be measured by the left matrix to obtain the stereo correction matrix;
[0018] Among them, e1 is the pole with the same direction as the translation vector T, T x 、T y 、T z are the translation vectors in the x, y and z directions respectively, e2 is the vector in the direction of the image plane; e3 is the vector perpendicular to the plane where e1 and e2 are located.
[0019] As an optional embodiment, the camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image; the stereo correction matrix includes a first stereo correction matrix for stereo correcting the left image, and a second stereo correction matrix for stereo correcting the right image;
[0020] Step S24 includes: Multiply it by the first component rotation matrix to get the first stereo correction matrix, and Multiply it to the second component rotation matrix on the left to obtain a second stereo correction matrix; the first component rotation matrix is the matrix of the left camera coordinate system after the rotation matrix of the binocular camera is decomposed, and the second component rotation matrix is the matrix of the right camera coordinate system after the rotation matrix of the binocular camera is decomposed.
[0021] As an optional embodiment, step S3 includes:
[0022] S31: Use a Gaussian filter to smooth the stereo-rectified image;
[0023] S32: Use edge detection operator to detect the edge of the image and return the first-order derivative value G in the horizontal direction x and the first-order derivative value G in the vertical direction y , and based on the G x and the G y Determine the gradient G and direction θ of each pixel on the image;
[0024] in,
[0025]
[0026]
[0027] S33: Compare the gradient value of the current pixel with the gradient values of two pixels along the positive and negative gradient directions θ. If the gradient value of the current pixel is greater than the gradient values of the other two pixels, retain the current pixel as an edge pixel; otherwise, suppress the current pixel.
[0028] As an optional embodiment, step S33 further includes step S34:
[0029] Determine the gradient values of all filtered edge pixels:
[0030] If the gradient value of the edge pixel point is higher than the first threshold, the edge pixel point is marked as a strong edge pixel point;
[0031] If the gradient value of an edge pixel is less than the first threshold and greater than the second threshold, the edge pixel is marked as a weak edge pixel; all the neighborhood pixels of the weak edge pixels are checked in turn to see if there is a strong edge pixel. If so, the current weak edge pixel is retained as the edge feature of the image, otherwise the edge pixel is suppressed;
[0032] If the gradient value of the edge pixel point is less than the second threshold, suppress the edge pixel point;
[0033] All the weak edge pixels marked as strong edge pixels and retained as image edge features are used as edge features of the stereo-rectified image.
[0034] As an optional embodiment, step S4 includes:
[0035] S41: Setting a global energy function related to the disparity map, and minimizing the set global energy function to solve the optimal disparity of each pixel. The global energy function E(D) is as follows:
[0036]
[0037] Among them, p and q represent a pixel point in the image respectively; N p Refers to the pixel points adjacent to the pixel point p; C(P, D p ) refers to the current pixel disparity D p When , the cost value corresponding to the pixel point; P1 is a penalty coefficient, which is used to calculate the pixel point whose disparity value in the adjacent pixels of pixel point p differs from the disparity value of pixel point p by 1; P2 is another penalty coefficient, which is used to calculate the pixel point whose disparity value in the adjacent pixels of pixel point p differs from the disparity value of pixel point p by more than 1; I[] function indicates that the return value is 1 when the parameter in the function is true, otherwise it returns a value of 0;
[0038] S42: Calculate the minimum cost value corresponding to the pixel point p; the specific calculation formula is as follows:
[0039]
[0040] Among them, r is the adjacent pixel to the left of pixel p; L r (p, d) represents the minimum cost value corresponding to pixel p when the disparity value of the current pixel p is d along the current direction;
[0041] S43: Calculate the cost value of the current pixel point p minus the minimum cost value C(p, d) when the previous pixel point takes different disparity values; the calculation formula is as follows:
[0042] C(p, d) = min(d(p, pd, I L , I R ), d(pd, I R , I L ))
[0043]
[0044] S44: calculating multiple cost values of the pixel point p along different directions, and accumulating the multiple cost values calculated in each direction, and selecting the disparity value in the direction with the smallest accumulated cost value as the final disparity value of the current pixel point p;
[0045] S45: Traverse all pixel points to obtain a sparse disparity map.
[0046] As an optional embodiment, step S5 includes:
[0047] S51: Calculate the parallax N i The weight value ω; the specific calculation formula is as follows:
[0048]
[0049] Among them, (x i,y i ) and (x p ,y p ) are N i and the coordinates of P in the image, where P is the pixel point where the disparity value is to be restored;
[0050] S52: Calculate the approximate disparity value of the filling When all solutions are completed, a dense disparity map is restored;
[0051] Among them, d(N i ) is point N i The parallax value of .
[0052] As an optional embodiment, the camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image;
[0053] Step S6 includes:
[0054] The distance between the detection point and the target to be measured is calculated by triangulation method; specifically:
[0055]
[0056] Among them, x l and x r are the horizontal positions of the detection point P in the limited space in the left camera and the right camera, respectively; f is the focal length of the binocular camera; D represents the vertical distance from the detection point P to the imaging plane of the binocular camera; O L , O R They represent the optical center coordinate positions of the left camera and the right camera respectively, T is the straight-line distance d between the optical centers of the left camera and the right camera, and represents the parallax value of the left camera and the right camera.
[0057] In a second aspect, the present invention provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the method steps described in the first aspect of the present invention.
[0058] In a third aspect, the present invention provides an electronic device, comprising a processor and a storage medium, wherein the storage medium is the storage medium as described in the second aspect of the present invention; the processor is used to execute a computer program in the storage medium.
[0059] The present invention can achieve the following technical effects:
[0060] The present invention provides a distance measurement method, storage medium and electronic device based on image matching, the method comprising the following steps: S1: collecting an image of a target to be measured; S2: performing stereo correction on the collected image according to a stereo correction matrix; S3: extracting edge features of the image after stereo correction; S4: performing stereo matching using a semi-global stereo matching algorithm to obtain a sparse disparity map; S5: performing adaptive sampling on the sparse disparity map to restore a dense disparity map; S6: obtaining the distance between the detection point and the target to be measured according to the dense disparity map. The above scheme greatly reduces the amount of matching calculation and improves the real-time performance of stereo matching by extracting the edge features of the target to be measured and then performing stereo matching. At the same time, an adaptive sampling algorithm is used to restore the sparse disparity map to a dense disparity map, thereby ensuring the integrity and accuracy of the distance measurement. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 is a flow chart of a distance measurement method based on image matching according to an embodiment of the present invention;
[0062] Figure 2 is a flow chart of a distance measurement method based on image matching according to another embodiment of the present invention;
[0063] Figure 3 is a flow chart of a distance measurement method based on image matching according to another embodiment of the present invention;
[0064] Figure 4 is a schematic diagram of a triangulation method according to an embodiment of the present invention;
[0065] Figure 5 is a schematic diagram of a module of an electronic device according to an embodiment of the present invention;
[0066] Reference numerals:
[0067] 10. Electronic equipment;
[0068] 101. Storage medium;
[0069] 102. Processor. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and do not constitute a limitation of the present invention.
[0071] like Figure 1 FIG. 1 is a flow chart of a distance measurement method based on image matching according to an embodiment of the present invention. The method comprises the following steps:
[0072] S1: Collect the image of the target to be measured;
[0073] S2: Perform stereo correction on the acquired image according to the stereo correction matrix;
[0074] S3: extract edge features of the stereo-rectified image;
[0075] S4: Use the semi-global stereo matching algorithm to perform stereo matching and obtain a sparse disparity map;
[0076] S5: Adaptively sample the sparse disparity map to restore the dense disparity map;
[0077] S6: Obtaining the distance between the detection point and the target to be detected according to the dense disparity map.
[0078] Compared with the prior art, the present invention has the following advantages: (1) by preprocessing the image to be measured, the edge of the target to be measured (such as an obstacle) is extracted, and then stereo matching is performed, which greatly reduces the amount of matching calculation and improves the real-time performance of stereo matching; (2) the stereo matching method adopted is semi-global matching, which has high precision and improves the accuracy of ranging; (3) an adaptive sampling algorithm is used to restore the sparse disparity map to a dense disparity map, thereby ensuring the integrity and accuracy of ranging.
[0079] In some embodiments, the stereo correction matrix in step S2 is determined according to the following method:
[0080] S21: Calculation Where T = [T x T y T z ] T ;
[0081] S22: Make e2 and e1 orthogonal, select the cross product of the principal optical axis direction (0,0,1) and e1, and calculate
[0082] S23: Calculate e3=e1×e2;
[0083] S24: Multiplying the rotation matrix of the camera used to acquire the image of the target to be measured by the left matrix to obtain the stereo correction matrix;
[0084] Among them, e1 is the pole with the same direction as the translation vector T, T x 、T y 、T z are the translation vectors in the x, y and z directions respectively, e2 is the vector in the direction of the image plane; e3 is the vector perpendicular to the plane where e1 and e2 are located.
[0085] In some embodiments, the camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image; the stereo correction matrix includes a first stereo correction matrix for stereo correction of the left image, and a second stereo correction matrix for stereo correction of the right image;
[0086] Step S24 includes: Multiply it by the first component rotation matrix to get the first stereo correction matrix, and Multiply it to the second component rotation matrix on the left to obtain a second stereo correction matrix; the first component rotation matrix is the matrix of the left camera coordinate system after the rotation matrix of the binocular camera is decomposed, and the second component rotation matrix is the matrix of the right camera coordinate system after the rotation matrix of the binocular camera is decomposed.
[0087] In certain embodiments, such as Figure 2 As shown, step S3 includes:
[0088] S31: Use a Gaussian filter to smooth the stereo-rectified image;
[0089] S32: Use edge detection operator to detect the edge of the image and return the first-order derivative value G in the horizontal direction x and the first-order derivative value G in the vertical direction y , and based on the G x and the G y Determine the gradient G and direction θ of each pixel on the image;
[0090] in,
[0091]
[0092]
[0093] S33: Compare the gradient value of the current pixel with the gradient values of two pixels along the positive and negative gradient directions θ. If the gradient value of the current pixel is greater than the gradient values of the other two pixels, retain the current pixel as an edge pixel; otherwise, suppress the current pixel.
[0094] In step S31, in order to minimize the effect of noise on the edge detection result, the noise can be filtered to prevent false detection caused by noise. In order to smooth the image, a Gaussian filter is used to convolve with the image. This step will smooth the image to reduce the obvious effect of noise on the edge detector. For example, a Gaussian filter with a size of (2k+1)x(2k+1) can be used to smooth the image. The generation equation of the Gaussian filter kernel with a size of (2k+1)x(2k+1) is as follows:
[0095]
[0096] Preferably, σ=1.4, the Gaussian convolution kernel size is 3x3, and the H matrix is obtained after normalization as follows:
[0097]
[0098] Suppose a 3x3 window in the image is A and the filtered pixel is e. After Gaussian filtering, the brightness value of pixel e is: e=H*A.
[0099] In step S32, the edges in the image may point to various directions, so in this embodiment, four operators may be used to respectively detect the edges in the horizontal, vertical and diagonal directions in the image.
[0100] In step S33, suppressing the current pixel may be assigning a pixel value of the current pixel to 0.
[0101] After applying non-maximum suppression, the remaining pixels can more accurately represent the actual edge in the image. However, there are still some edge pixels caused by noise and color changes. In order to solve these stray responses, edge pixels must be filtered with weak gradient values and edge pixels with high gradient values must be retained, which can be achieved by selecting high and low thresholds. Therefore, in some embodiments, step S33 is followed by step S34:
[0102] Determine the gradient values of all filtered edge pixels:
[0103] If the gradient value of the edge pixel point is higher than the first threshold, the edge pixel point is marked as a strong edge pixel point;
[0104] If the gradient value of an edge pixel is less than the first threshold and greater than the second threshold, the edge pixel is marked as a weak edge pixel.
[0105] If the gradient value of an edge pixel point is less than a second threshold, the edge pixel point is suppressed.
[0106] In this embodiment, the selection of the first threshold and the second threshold can be determined according to actual needs, specifically depending on the content of the input image.
[0107] After the above-mentioned step S34 is processed, the pixels divided into strong edges have been determined as edges because they are extracted from the real edges in the image. However, for weak edge pixels, it may be extracted from the real edge or may be caused by noise or color change. In order to obtain accurate results, the weak edges caused by the latter should be suppressed. Usually, the weak edge pixels caused by the real edge will be connected to the strong edge pixels, and the noise response is not connected. In order to track edge connections, by looking at the weak edge pixels and their multiple (such as 8) neighborhood pixels, as long as one of them is a strong edge pixel, the weak edge point can be retained as a real edge.
[0108] Therefore, after step S34, the following steps can be performed: check whether there are strong edge pixels in the neighborhood pixels of all weak edge pixels in turn, if so, retain the current weak edge pixel as the edge feature of the image, otherwise suppress the edge pixel; all the weak edge pixels marked as strong edge pixels and retained as image edge features are used as the edge features of the stereo corrected image. In this way, the final extraction of the image edge features is completed.
[0109] like Figure 3 As shown, in some embodiments, step S4 includes:
[0110] S41: Setting a global energy function related to the disparity map, and minimizing the set global energy function to solve the optimal disparity of each pixel. The global energy function E(D) is as follows:
[0111]
[0112] Among them, p and q represent a pixel point in the image respectively; N p Refers to the pixel points adjacent to the pixel point p; C(P, D p ) refers to the current pixel disparity D p When , the cost value corresponding to the pixel point; P1 is a penalty coefficient, which is used to calculate the pixel point whose disparity value in the adjacent pixels of pixel point p differs from the disparity value of pixel point p by 1; P2 is another penalty coefficient, which is used to calculate the pixel point whose disparity value in the adjacent pixels of pixel point p differs from the disparity value of pixel point p by more than 1; I[] function indicates that the return value is 1 when the parameter in the function is true, otherwise it returns a value of 0;
[0113] S42: Calculate the minimum cost value corresponding to the pixel point p; the specific calculation formula is as follows:
[0114]
[0115] Among them, r is the adjacent pixel to the left of pixel p; L r(p, d) represents the minimum adjusted cost value corresponding to the pixel point p when the disparity value of the current pixel point p is d along the current direction:
[0116] (1) When the disparity of the left adjacent pixel is d, the adjusted minimum cost value corresponding to the pixel p is its minimum cost value itself.
[0117] (2) When the disparity of the left adjacent pixel is d-1, the adjusted minimum cost value corresponding to the pixel point p is its minimum cost value + penalty coefficient P1.
[0118] (3) When the disparity of the left adjacent pixel is d+1, the adjusted minimum cost value corresponding to the pixel point p is its minimum cost value + penalty coefficient P1.
[0119] (4) When the left adjacent pixel disparity is other, the adjusted minimum cost value corresponding to the pixel point p is its minimum cost value + penalty coefficient P2.
[0120] S43: Calculate the cost value of the current pixel point p minus the minimum cost value C(p, d) when the previous pixel point takes different disparity values; the calculation formula is as follows:
[0121] C(p, d) = min(d(p, pd, I L , I R ), d(pd, I R , I L ))
[0122]
[0123] S44: Calculate multiple cost values of the pixel point p along different directions, and accumulate the multiple cost values calculated in each direction, and select the disparity value in the direction with the smallest accumulated cost value as the final disparity value of the current pixel point p. For example, if each pixel point has 8 neighboring pixels, it is necessary to calculate the cost values from 8 directions (specifically left and right, right left, up and down, down and up, left up and down, right down and down, right down and down, left down and down). Then accumulate the cost values in the 8 directions, and select the disparity value with the smallest accumulated cost value as the final disparity value of the pixel.
[0124] S45: Traverse all pixel points to obtain a sparse disparity map.
[0125] In some embodiments, step S5 comprises:
[0126] S51: Calculate the parallax N i The weight value ω; the specific calculation formula is as follows:
[0127]
[0128] Among them, (x i ,y i ) and (x p ,y p ) are N i and the coordinates of P in the image, where P is the pixel point (center of gravity of the triangle) for which the disparity value is to be restored;
[0129] S52: Calculate the approximate disparity value of the filling When all solutions are completed, a dense disparity map is restored;
[0130] Among them, d(N i ) is point N i The parallax value of .
[0131] In some embodiments, the camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image;
[0132] like Figure 4 As shown, step S6 includes:
[0133] The distance between the detection point and the target to be measured is calculated by triangulation method; specifically:
[0134]
[0135] Among them, x l and x r are the horizontal positions of the detection point P in the limited space in the left camera and the right camera, respectively; f is the focal length of the binocular camera; D represents the vertical distance from the detection point P to the imaging plane of the binocular camera; O L , O R They represent the optical center coordinate positions of the left camera and the right camera respectively, T is the straight-line distance d between the optical centers of the left camera and the right camera, and represents the parallax value of the left camera and the right camera.
[0136] In a second aspect, the present invention further provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in the first aspect of the present invention are implemented. The storage medium includes, but is not limited to: RAM, ROM, disk, tape, CD, flash memory, USB flash drive, mobile hard disk, memory card, memory stick, network server storage, network cloud storage, etc.
[0137] In the third aspect, Figure 5As shown, the present invention further provides an electronic device 10, the electronic device 10 includes a processor 102 and a storage medium 101, the storage medium 101 is the storage medium described in the second aspect of the present invention; the processor 102 is used to execute the computer program in the storage medium 101. The electronic device can be a computer device, including but not limited to: a personal computer, a server, a general-purpose computer, a special-purpose computer, a network device, an embedded device, a programmable device, an intelligent mobile terminal, an intelligent home device, a wearable intelligent device, an in-vehicle intelligent device, etc.
[0138] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0139] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
[0140] The above specific implementations of the present invention do not constitute a limitation on the protection scope of the present invention. Any other corresponding changes and modifications made based on the technical concept of the present invention should be included in the protection scope of the claims of the present invention.
Claims
1. A distance measurement method based on image matching, characterized in that: The method comprises the following steps: S1: Collect the image of the target to be measured; S2: Perform stereo correction on the acquired image according to the stereo correction matrix; S3: extract edge features of the stereo-rectified image; S4: Use the semi-global stereo matching algorithm to perform stereo matching and obtain a sparse disparity map; S5: Adaptively sample the sparse disparity map to restore the dense disparity map; S6: Obtaining the distance between the detection point and the target to be detected according to the dense disparity map; The stereo correction matrix in step S2 is determined in the following manner: S21: Calculation ,in, ; S22: Make e2 and e1 orthogonal, select the cross product of the principal optical axis direction (0,0,1) and e1, and calculate ; S23: Calculation ; S24: Multiplying the rotation matrix of the camera used to capture the image of the target to be measured by the left matrix to obtain the stereo correction matrix; in, is the translation vector The poles in the same direction, , , are the translation vectors in the x, y and z directions respectively, is the vector in the direction of the image plane; is perpendicular to and The vector of the plane; The camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image; the stereo correction matrix includes a first stereo correction matrix for stereo correcting the left image, and a second stereo correction matrix for stereo correcting the right image; Step S24 includes: Multiply it by the first component rotation matrix to get the first stereo correction matrix, and Multiply it to the second component rotation matrix on the left to obtain a second stereo correction matrix; the first component rotation matrix is the matrix of the left camera coordinate system after the rotation matrix of the binocular camera is decomposed, and the second component rotation matrix is the matrix of the right camera coordinate system after the rotation matrix of the binocular camera is decomposed.
2. The distance measurement method based on image matching according to claim 1, characterized in that: Step S3 includes: S31: Use a Gaussian filter to smooth the stereo-rectified image; S32: Use edge detection operator to detect the edge of the image and return the first-order derivative value in the horizontal direction and the first-order derivative in the vertical direction , and based on the and stated Determine the gradient G and direction of each pixel on the image ; in, ; S33: Compare the gradient value of the current pixel point with the gradient values along the positive and negative gradient directions The gradient values of the two pixels on the image are compared. If the gradient value of the current pixel is greater than the gradient values of the other two pixels, the current pixel is retained as an edge pixel, otherwise the current pixel is suppressed.
3. The distance measurement method based on image matching as claimed in claim 2, characterized in that: Step S33 also includes step S34: Determine the gradient values of all filtered edge pixels: If the gradient value of the edge pixel point is higher than the first threshold, the edge pixel point is marked as a strong edge pixel point; If the gradient value of an edge pixel is less than the first threshold and greater than the second threshold, the edge pixel is marked as a weak edge pixel; all the neighborhood pixels of the weak edge pixels are checked in turn to see if there is a strong edge pixel. If so, the current weak edge pixel is retained as the edge feature of the image, otherwise the edge pixel is suppressed; If the gradient value of the edge pixel point is less than the second threshold, suppress the edge pixel point; All the weak edge pixels marked as strong edge pixels and retained as image edge features are used as edge features of the stereo-rectified image.
4. The distance measurement method based on image matching according to claim 1, characterized in that: Step S4 includes: S41: Set a global energy function related to the disparity map and minimize the set global energy function to solve the optimal disparity of each pixel. as follows: Among them, p and q represent a pixel point in the image respectively; N p Refers to the pixel points adjacent to the pixel point p; C(P, D p ) refers to the current pixel disparity D p When , the cost value corresponding to the pixel point; is a penalty coefficient used to calculate the pixel whose disparity value among the neighboring pixels of pixel p differs from the disparity value of pixel p by 1; It is another penalty coefficient used to calculate the pixel points whose disparity value among the adjacent pixels of pixel p differs from the disparity value of pixel p by more than 1; the I[] function indicates that the return value is 1 when the parameter in the function is true, otherwise it returns a value of 0; S42: Calculate the minimum cost value corresponding to the pixel point p; the specific calculation formula is as follows: Among them, r is the adjacent pixel to the left of pixel p; Indicates the minimum cost value corresponding to pixel p when the disparity value of the current pixel p is d along the current direction; S43: Calculate the cost value of the current pixel point p minus the minimum cost value C(p, d) when the previous pixel point takes different disparity values; the calculation formula is as follows: S44: calculating multiple cost values of the pixel point p along different directions, and accumulating the multiple cost values calculated in each direction, and selecting the disparity value in the direction with the smallest accumulated cost value as the final disparity value of the current pixel point p; S45: Traverse all pixel points to obtain a sparse disparity map.
5. The distance measurement method based on image matching according to claim 1, characterized in that: Step S5 includes: S51: Calculate the parallax The weight value ; The specific calculation formula is as follows: in,( )and( ) are and the coordinates of P in the image, where P is the pixel point where the disparity value is to be restored; S52: Calculate the approximate disparity value of the filling , when all solutions are completed, a dense disparity map is restored; in, For point The parallax value of .
6. The distance measurement method based on image matching according to claim 1, characterized in that: The camera is a binocular camera, and the binocular camera includes a left camera and a right camera; the image of the target to be measured includes a left image and a right image; Step S6 includes: The distance between the detection point and the target to be measured is calculated using triangulation method; specifically: Among them, x l and x r are the horizontal positions of the detection point P in the limited space in the left camera and the right camera, respectively; f is the focal length of the binocular camera; D represents the vertical distance from the detection point P to the imaging plane of the binocular camera; O L , O R They represent the optical center coordinate positions of the left camera and the right camera respectively, T is the straight-line distance d between the optical centers of the left camera and the right camera, and represents the parallax value of the left camera and the right camera.
7. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method steps according to any one of claims 1 to 6 are implemented.
8. An electronic device, characterized in that: The electronic device comprises a processor and a storage medium, wherein the storage medium is the storage medium as claimed in claim 7; and the processor is used to execute a computer program in the storage medium.
