Depth camera distance measurement

Before starting this function, you need to close the process of the big program and APP. If you need to start the big program and APP again later, start the terminal,

1. Function description

After the program is started, click the point in the pseudo-color image with the mouse. Within the effective data range of the depth camera, the screen will show the distance between the point and the depth camera.

2. Start and operate

2.1. Start

Terminal input,

After the program is started, the distance of the center point of the image is obtained by default. If the distance is not within the effective range of the depth camera, an error may be reported. The normal startup is as follows,

image-20240923170157740

The distance of the point will be printed in the image in millimeters, and the terminal will also display the distance.

2.2, Operation

Click any point in the pseudo-color image frame with the mouse, and a black dot will appear after clicking, indicating the location of the current point; the distance of the point will be displayed in the image, and the terminal will also display it synchronously,

image-20240923171000284

Here is a demonstration, I took a point on my hand, the distance is 47.3 cm, that is, 473 mm.

3. Program flow chart

image-20250417115949901

4. Core code analysis

Under the code path,

Import library

Define the image encoding format

Initialize data,

Define the click_callback function to handle the detected mouse event,

Write the callback function of the subscriber to process the received depth image topic data,