Measuring the gap between two objects is known as distance calculation within a specified space. In the case of [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics), the [bounding box](https://www.ultralytics.com/glossary/bounding-box) centroid is employed to calculate the distance for bounding boxes highlighted by the user.
Distance will be an estimate and may not be fully accurate, as it is calculated using 2-dimensional data, which lacks information about the object's depth.
### How do I calculate distances between objects using Ultralytics YOLOv8?
To calculate distances between objects using [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics), you need to identify the bounding box centroids of the detected objects. This process involves initializing the `DistanceCalculation` class from Ultralytics' `solutions` module and using the model's tracking outputs to calculate the distances. You can refer to the implementation in the [distance calculation example](#distance-calculation-using-ultralytics-yolov8).
### What are the advantages of using distance calculation with Ultralytics YOLOv8?
Using distance calculation with Ultralytics YOLOv8 offers several advantages:
- **Localization Precision:** Provides accurate spatial positioning for objects.
Yes, you can perform distance calculation in real-time video streams with Ultralytics YOLOv8. The process involves capturing video frames using [OpenCV](https://www.ultralytics.com/glossary/opencv), running YOLOv8 [object detection](https://www.ultralytics.com/glossary/object-detection), and using the `DistanceCalculation` class to calculate distances between objects in successive frames. For a detailed implementation, see the [video stream example](#distance-calculation-using-ultralytics-yolov8).
### How do I delete points drawn during distance calculation using Ultralytics YOLOv8?
To delete points drawn during distance calculation with Ultralytics YOLOv8, you can use a right mouse click. This action will clear all the points you have drawn. For more details, refer to the note section under the [distance calculation example](#distance-calculation-using-ultralytics-yolov8).
### What are the key arguments for initializing the DistanceCalculation class in Ultralytics YOLOv8?
The key arguments for initializing the `DistanceCalculation` class in Ultralytics YOLOv8 include:
-`names`: Dictionary mapping class indices to class names.
-`view_img`: Flag to indicate if the video stream should be displayed.
-`line_thickness`: Thickness of the lines drawn on the image.
-`line_color`: Color of the lines drawn on the image (BGR format).
-`centroid_color`: Color of the centroids (BGR format).
For an exhaustive list and default values, see the [arguments of DistanceCalculation](#arguments-distancecalculation).