Two-dimensional displacement real-time detection method based on histogram similarity
By using a histogram similarity-based method to calculate the gray-level slope and voting mechanism of gray-level statistical images, the shortcomings of two-dimensional displacement sensors in terms of accuracy, speed, and range are solved, achieving high-precision, fast, and robust two-dimensional displacement detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WANYAN RAILWAY EQUIP (CHENGDU) CO LTD
- Filing Date
- 2026-01-21
- Publication Date
- 2026-05-01
AI Technical Summary
Existing two-dimensional displacement sensors have shortcomings in measurement accuracy, response speed, and measurement range. Especially when measuring with high precision and large range, multiple sensors are often required in combination, and they are sensitive to changes in illumination.
A histogram-based similarity method is adopted to calculate the gray-level slope of fixed-interval pixels within a sliding window of a gray-level statistical image. Two-dimensional displacement detection is then performed using slope comparison and voting mechanisms, achieving fast and reliable displacement detection.
It achieves high-precision (micrometer level), fast, and robust large-range two-dimensional displacement detection, and can remain stable under changes in illumination, reducing computational complexity and noise sensitivity.
Smart Images

Figure CN121962201A_ABST
Abstract
Description
A real-time two-dimensional displacement detection method based on histogram similarity Technical Field
[0001] This invention belongs to the field of data detection technology, specifically relating to a real-time two-dimensional displacement detection method based on histogram similarity. Background Technology
[0002] Three-dimensional or two-dimensional displacement of a target or workpiece is a common state in workpiece machining. Often, it's necessary to obtain the target's displacement data in real time. In principle, a multi-dimensional displacement sensor can be composed of multiple one-dimensional displacement sensors. A two-dimensional displacement sensor is a device that can simultaneously measure the movement or positional change of an object in two orthogonal directions (usually the X-axis and Y-axis). It outputs not a single distance value, but a two-dimensional coordinate point (X, Y), thus accurately describing the target object's position in a plane. Most two-dimensional displacement sensors employ non-contact principles (such as optical and capacitive), avoiding interference and wear on the measured object. High-precision and high-resolution displacement sensors can achieve micrometer (μm) level accuracy. High-speed response two-dimensional displacement sensors can capture the trajectory and vibration of high-speed moving objects.
[0003] Two-dimensional displacement sensors are primarily optical sensors, which typically include a light source and a photosensitive receiver (such as a CCD or CMOS sensor). These sensors can be categorized into several types.
[0004] (1) Laser triangular reflection method
[0005] The sensor emits a laser beam that strikes the surface of the object being measured. The reflected light passes through a lens and forms a spot on a photosensitive element. As the object moves, the position of the spot changes. By calculating the movement of the spot on the receiver, the displacement of the object in the X and Z directions (distance) can be calculated. Its advantages are high accuracy and fast response. However, to achieve lateral displacement measurement in the (X, Y) plane, two such sensors are typically required, arranged orthogonally.
[0006] (2) Optical correlation method (laser surface probe)
[0007] When a laser beam illuminates the surface of an object, its speckle pattern is captured by a sensor. By calculating the movement of the speckle pattern in a series of images (correlation calculation), the displacement of the object in the (X, Y) direction can be determined. Its advantages include suitability for measuring diffuse reflective surfaces and extremely high accuracy; its disadvantage is a very small measurement range, typically on the order of millimeters.
[0008] (3) Vision sensor (CCD / CMOS camera)
[0009] By capturing feature points or specific markers on the surface of an object, image processing algorithms (such as template matching and edge detection) are used to calculate the positional changes of the marker points in the image, thus obtaining two-dimensional displacement. Its advantages include flexible measurement range, capable of measuring a wide range of displacements. Its disadvantages include occasional failures and processing speed being affected by the algorithm, sometimes being very slow.
[0010] Other displacement sensors include capacitive displacement sensors and eddy current displacement sensors, which have very small measurement ranges and short working distances. Summary of the Invention
[0011] The purpose of this invention is to solve the above-mentioned problems and provide a non-contact, fast, highly reliable, and large-range two-dimensional displacement real-time detection method based on histogram similarity.
[0012] To solve the above technical problems, the technical solution of the present invention is: a real-time two-dimensional displacement detection method based on histogram similarity, comprising the following steps:
[0013] S1, Input image (original image) and image to be matched;
[0014] S2. If the image is in color, first convert it to a grayscale image, and then convert it to a grayscale statistical image.
[0015] S3. Select a few fixed rows or columns of the image and convert them into a grayscale statistical chart;
[0016] S4. Define a fixed-length window on the grayscale chart;
[0017] S5. Determine the sampling interval for calculating the grayscale slope within the window;
[0018] S6. For a series of sampling points, calculate the number of adjacent sampling points (x). i y i ) and (x j y j );
[0019] S7. Convert the image to be matched into a grayscale statistical image, and move the window of the same size over the grayscale statistical image to be matched.
[0020] S8. For the k-th candidate window, set its sequence S current,k With reference sequence S ref Compare;
[0021] S9. If the difference δ(sref,i,scurrent,k,i) of a certain window is less than or equal to a certain preset threshold T (i.e. the point is considered to be a successful match), then cast a vote for the candidate window.
[0022] The number of votes in the Kth window: ;
[0023] Where 1(.) is the indicator function (takes 1 if the condition is true, otherwise takes 0); the higher the number of votes, the better the match.
[0024] S10. After voting for all n candidate windows is completed, compare their vote counts Vk; find the candidate window with the highest vote count, and its index k* is the best matching window; the estimated pixel movement (Δx, Δy) is:
[0025] Δx=x k∗ − x ref Δy=y k∗ -y ref .
[0026] Furthermore, in S3, rows correspond to the calculation of the x-direction, and columns correspond to the calculation of the y-direction.
[0027] Furthermore, in S5, the sampling interval is to calculate a slope every 3 pixels.
[0028] Furthermore, the formula for calculating the slope m of adjacent sampling points in S6 is: Calculate the slope between all adjacent sampling points to form a sequence of values Sref={m1,m2,...mn}.
[0029] Furthermore, the movement in S7 is in units of one pixel, and each movement obtains a window sequence, resulting in all window sequences Scurrent,k={sk,1,sk,2,...,sk,n}.
[0030] Furthermore, the S current,k Voting value V k It is obtained through voting.
[0031] The beneficial effects of this invention are:
[0032] 1. The present invention provides a two-dimensional displacement real-time detection method based on histogram similarity, which can simultaneously detect displacement in two directions (X, Y), and has the characteristics of non-contact, fast, highly reliable, large range, and accuracy of several micrometers.
[0033] 2. The present invention has illumination robustness: the slope calculation has better adaptability to illumination changes compared to direct matching of gray values.
[0034] 3. This invention reduces computational complexity and improves robustness through discrete sampling, slope comparison, and voting mechanisms. Attached Figure Description
[0035] Figure 1 is the first frame image in actual use of the two-dimensional displacement real-time detection method based on histogram similarity according to the present invention;
[0036] Figure 2 is the second frame image of the present invention;
[0037] Figure 3 is a comparison of the images and histograms collected during the movement of the rails according to the present invention;
[0038] Figure 4 is a schematic diagram of the measuring device of the present invention;
[0039] Figure 5 is a comparison of images and histograms captured by the camera during the movement of the present invention.
[0040] Figure 6 is a structural schematic diagram of the first support of the present invention;
[0041] Figure 7 is a structural schematic diagram of the first connector of the present invention;
[0042] Figure 8 is a structural schematic diagram of the linear module detection component of the present invention.
[0043] Explanation of reference numerals in the attached drawings: 1. First support; 2. Second support; 3. Linear module; 4. Motor; 5. Camera; 31. First connector; 32. Connector base plate; 33. Connecting block; 34. Linear module detection component; 331. Connecting block base plate; 332. Connecting block connecting plate; 333. Connecting block base plate through hole; 334. Connecting block connecting plate through hole; 341. Detection component connecting base plate; 342. Detection component block. Detailed Implementation
[0044] The present invention will be further described below with reference to the accompanying drawings and specific embodiments:
[0045] As shown in Figures 1 to 5, the present invention provides a real-time two-dimensional displacement detection method based on histogram similarity, comprising the following steps:
[0046] S1. Input the original image and the image to be matched.
[0047] In Figure 3 of this invention, (a) and (b) represent partial images from two frames that are remembered only when the rail is moving. (c) and (d) represent the grayscale histograms in the x and y directions, respectively. (e) and (f) represent the regions with the highest histogram similarity in the sliding window within (c) and (d) of Figure 3, respectively. Figures (a) to (f) in Figure 5 correspond to the images (a) to (f) in Figure 3 during actual use.
[0048] In this embodiment, the original image in step S1 is (a) in Figure 3, and the image to be matched is (b) in Figure 3. A "partial image" refers to a segment of an image; an image is a large set. Each element in the set can be considered as part of the image for matching. See the two boxed areas in Figures e and f for details. This area is a variable; the final matching area is calculated.
[0049] S2. If the image is in color, first convert it to a grayscale image, and then convert it to a grayscale statistical graph.
[0050] The statistical graph in step S2 is shown in Figure 3 (c).
[0051] S3. Select a few fixed rows or columns of the image and convert them into a grayscale statistical chart.
[0052] In step S3, the row corresponds to the calculation of the x-direction, and the column corresponds to the calculation of the y-direction.
[0053] S4. Define a fixed-length window on the grayscale chart.
[0054] The window in step S4 is shown in the box in Figure 3(e).
[0055] S5. Determine the sampling interval for calculating the grayscale slope within the window.
[0056] In step S5, the sampling interval is to calculate a slope every 3 pixels.
[0057] S6. For a series of sampling points, calculate the number of adjacent sampling points (x). i y i ) and (x j y j ).
[0058] The formula for calculating the slope m of adjacent sampling points in step S6 is: Calculate the slope between all adjacent sampling points to form a sequence of values Sref={m1,m2,...mn}.
[0059] S7. Convert the image to be matched into a grayscale statistical image, and move the window of the same size over the grayscale statistical image to be matched.
[0060] The movement in step S7 is in units of one pixel. Each movement yields a window sequence, resulting in all window sequences Scurrent,k={sk,1,sk,2,...,sk,n}.
[0061] Where S current,k Voting value V k It is obtained through voting.
[0062] S8. For the k-th candidate window, set its sequence S current,k With reference sequence S ref Compare them.
[0063] S9. If the difference δ(sref,i,scurrent,k,i) of a certain window is less than or equal to a certain preset threshold T (i.e. the point is considered to be a successful match), then cast a vote for the candidate window.
[0064] The number of votes in the Kth window: .
[0065] Where 1(.) is the indicator function (takes 1 if the condition is true, otherwise takes 0); the higher the number of votes, the better the match.
[0066] S10. After voting for all n candidate windows is completed, compare their vote counts Vk; find the candidate window with the highest vote count, and its index k* is the best matching window; the estimated pixel movement (Δx, Δy) is:
[0067] Δx=x k∗ − x ref Δy=y k∗ -y ref .
[0068] A stepper motor controls the camera to move 100mm at a time, capturing each frame. The movement of adjacent frames is calculated, and the cumulative value of all adjacent frames is examined. Each pixel represents 0.18mm. The repeatability is less than one-thousandth. The experimental results are shown in the table below, with a maximum error of 55. m.
[0069] ;
[0070] With the camera stationary and the motor controlling the billet's movement, the same displacement in the Y direction can be obtained. In practical applications, the camera remains stationary, and a sliding window searches for the most similar histogram along both the x and Y directions.
[0071] The real-time monitoring device used in this invention includes a first support 1 and a second support 2. A linear module 3 is provided on the first support 1 and the second support 2. A motor 4 is connected to the end of the linear module 3 and a camera 5 is connected to the bottom of the linear module 3. When the motor 4 drives the linear module 3 to work, it drives the camera 5 to move, thereby realizing real-time monitoring.
[0072] In practical use, the object detected by camera 5 can move on its own while camera 5 remains stationary. This increases the practicality of the invention and expands its application range. In this embodiment, two dimensions refer to the entire surface captured by camera 5. The image captured by this invention can detect changes in the horizontal and vertical directions of the object. The main detection is the dimension of the direction of motion. It can also detect the direction of the object's vertical shaking.
[0073] The first bracket 1 has a trapezoidal shape with an open bottom, and the length of the top of the first bracket 1 is less than the distance between the two bottom ends. The first bracket 1 is snapped onto and fixed to the linear module 3. In this embodiment, the fixing is a common connection method in the art, such as bolt connection.
[0074] The structure of the second support 2 is the same as that of the first support 1, and the first support 1 and the second support 2 are arranged in parallel. The first support 1 and the second support 2 are located at the two ends of the linear module 3, respectively, and together provide support for the linear module 3.
[0075] Motor 4 is a stepper motor. During operation, motor 4 drives the linear module 3 to move, and the linear module 3 drives the camera 5 to move.
[0076] Linear module 3 is a mature existing technology product, and its model number is: IX-08N-P10-500-1K-CK-02.
[0077] The bottom of the linear module 3 is provided with a first connector 31. The first connector 31 includes a connector base plate 32 and a connecting support block 33. The connecting base plate 32 is a rectangular plate structure. The connecting support block 33 includes a connecting support block base plate 331 and a connecting support block connecting plate 332. The connecting support block base plate 331 and the connecting support block connecting plate 332 are perpendicularly connected to each other. The connecting support block base plate 331 and the connector base plate 32 are connected by bolts. The connecting support block connecting plate 332 is connected to the camera 5 by bolts.
[0078] The connecting support block base plate 331 is provided with a connecting support block base plate through hole 333, and the connecting support block connecting plate 332 is provided with a connecting support block connecting plate through hole 334. The bolt passes through the connecting support block base plate through hole 333 and connects to the connecting component base plate 32. After the connecting bolt passes through the connecting support block connecting plate through hole 334, it is connected to the camera 5.
[0079] The linear module 3 has a linear module detection component 34 on its side. The linear module detection component 34 includes a detection component connecting base plate 341 and a detection component block 342. The detection component connecting base plate 341 is connected to the linear module 3 by bolts, and the detection component block 342 is connected to the detection component connecting base plate 341 by bolts.
[0080] In this embodiment, the number of linear module detection components 34 located at one end of the linear module 3 is two and they are arranged in parallel. The detection component connection base plate 341 is a plate-shaped structure bent at a right angle. The bottom of the detection component block 342 has an "n"-shaped structure.
[0081] There is a connecting piece base plate stopper 321 on the connecting piece base plate 32. The connecting piece base plate stopper 321 is connected to the connecting piece base plate 32 by bolts. The connecting piece base plate stopper 321 has a "convex"-shaped structure. During the movement of the connecting piece base plate stopper 321, it can pass through the through slot in the middle of the "n"-shaped structure of the detection component block 342.
[0082] The camera 5 is an existing mature technical product, and its model is: MER-160-227U3M / C-L. In the use of the present invention, the linear module 3 drives the camera 5 to move, and then the camera 5 takes real-time pictures.
[0083] The purpose of the present invention is to provide a method for detecting two-dimensional displacement of pixels based on a sliding window, which detects the two-dimensional displacement of an object with a gray body surface and calculates the image of the gray scale slope at fixed intervals of pixels. The principle is shown in Figures 1 and 2. Figures 1 and 2 are gray scale images of two adjacent frames of the surface of a billet workpiece. Due to the movement of the billet, Figure 2 has a displacement relative to Figure 1. and . Select a small window in Image 1 and calculate the gray scale histogram within the window.
[0084] The core of this method is that instead of directly comparing gray scale values or one-dimensional projections, it calculates the gray scale slope of fixed-interval pixel points within a sliding window as a new feature descriptor to characterize the local gray scale change pattern of the image, and realizes the precise matching of the image and the calculation of the pixel movement amount by comparing these slope sequences. To solve the problems that may exist in traditional methods, such as high computational complexity, sensitivity to noise, or insufficient utilization of detailed information.
[0085] Those of ordinary skill in the art will realize that the embodiments described here are to help the reader understand the principles of the present invention, and it should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those of ordinary skill in the art can make various other specific deformations and combinations that do not depart from the essence of the present invention according to the technical revelations disclosed in the present invention, and these deformations and combinations are still within the protection scope of the present invention.
Claims
1. A real-time two-dimensional displacement detection method based on histogram similarity, characterized in that, Includes the following steps: S1. Input the original image and the image to be matched; S2. If the image is in color, first convert it to grayscale, then convert it to a grayscale chart; S3. Select a fixed number of rows or columns of the image and convert them to a grayscale chart; S4. Define a fixed-length window on the grayscale chart; S5. Determine the sampling interval for calculating the grayscale slope within the window; S6. For a series of sampling points, calculate the adjacent sampling points (x i y i ) and (x j y j ); S7. Convert the image to be matched into a grayscale statistical image, and move a window of the same size across the grayscale statistical image; S8. For the k-th candidate window, set its sequence S current,k With reference sequence S ref Compare; S9. If the difference δ(sref,i,scurrent,k,i) of a certain window is less than or equal to a certain preset threshold T (i.e., the point is considered to be a successful match), then cast a vote for that candidate window; the number of votes for the Kth window: ; where 1(.) is the indicator function (takes 1 if the condition is true, otherwise takes 0); the higher the number of votes, the better the matching degree; S10, after all n candidate windows have finished voting, compare their vote counts Vk; find the candidate window with the highest number of votes, and its index k* is the best matching window; the estimated pixel movement (Δx, Δy) is: Δx = x k∗ − x ref Δy=y k∗ -y ref .
2. The two-dimensional displacement real-time detection method based on histogram similarity according to claim 1, characterized in that: In S3, rows are used to calculate the x-direction, and columns are used to calculate the y-direction.
3. The two-dimensional displacement real-time detection method based on histogram similarity according to claim 1, characterized in that: In S5, the sampling interval is to calculate a slope every 3 pixels.
4. The two-dimensional displacement real-time detection method based on histogram similarity according to claim 1, characterized in that: The formula for calculating the slope m of adjacent sampling points in S6 is: Calculate the slope between all adjacent sampling points to form a sequence of values Sref={m1,m2,...mn}.
5. The two-dimensional displacement real-time detection method based on histogram similarity according to claim 1, characterized in that: The movement in S7 is in units of one pixel. Each movement obtains a window sequence, and all window sequences Scurrent,k={sk,1,sk,2,...,sk,n} are obtained.
6. The two-dimensional displacement real-time detection method based on histogram similarity according to claim 1, characterized in that: The S current,k Voting value V k It is obtained through voting.