mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 05:24:22 +08:00
Add millimeters in solutions/distance_caculation.py
+ object-cropping.md
visuals (#7860)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
afb0cb1057
commit
492f397ae2
@ -37,7 +37,7 @@ Here's a compilation of in-depth guides to help you master different aspects of
|
||||
- [Objects Counting in Regions](region-counting.md) 🚀 NEW: Explore counting objects in specific regions with Ultralytics YOLOv8 for precise and efficient object detection in varied areas.
|
||||
- [Security Alarm System](security-alarm-system.md) 🚀 NEW: Discover the process of creating a security alarm system with Ultralytics YOLOv8. This system triggers alerts upon detecting new objects in the frame. Subsequently, you can customize the code to align with your specific use case.
|
||||
- [Heatmaps](heatmaps.md) 🚀 NEW: Elevate your understanding of data with our Detection Heatmaps! These intuitive visual tools use vibrant color gradients to vividly illustrate the intensity of data values across a matrix. Essential in computer vision, heatmaps are skillfully designed to highlight areas of interest, providing an immediate, impactful way to interpret spatial information.
|
||||
- [Instance Segmentation with Object Tracking](instance-segmentation-and-tracking.md) 🚀 NEW: Explore our feature on Object Segmentation in Bounding Boxes Shape, providing a visual representation of precise object boundaries for enhanced understanding and analysis.
|
||||
- [Instance Segmentation with Object Tracking](instance-segmentation-and-tracking.md) 🚀 NEW: Explore our feature on [Object Segmentation](https://docs.ultralytics.com/tasks/segment/) in Bounding Boxes Shape, providing a visual representation of precise object boundaries for enhanced understanding and analysis.
|
||||
- [VisionEye View Objects Mapping](vision-eye.md) 🚀 NEW: This feature aim computers to discern and focus on specific objects, much like the way the human eye observes details from a particular viewpoint.
|
||||
- [Speed Estimation](speed-estimation.md) 🚀 NEW: Speed estimation in computer vision relies on analyzing object motion through techniques like [object tracking](https://docs.ultralytics.com/modes/track/), crucial for applications like autonomous vehicles and traffic monitoring.
|
||||
- [Distance Calculation](distance-calculation.md) 🚀 NEW: Distance calculation, which involves measuring the separation between two objects within a defined space, is a crucial aspect. In the context of Ultralytics YOLOv8, the method employed for this involves using the bounding box centroid to determine the distance associated with user-highlighted bounding boxes.
|
||||
|
@ -16,6 +16,15 @@ Object cropping with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
|
||||
- **Reduced Data Volume**: By extracting only relevant objects, object cropping helps in minimizing data size, making it efficient for storage, transmission, or subsequent computational tasks.
|
||||
- **Enhanced Precision**: YOLOv8's object detection accuracy ensures that the cropped objects maintain their spatial relationships, preserving the integrity of the visual information for detailed analysis.
|
||||
|
||||
|
||||
## Visuals
|
||||
|
||||
| Airport Luggage |
|
||||
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|
||||
|  |
|
||||
| Suitcases Cropping at airport conveyor belt using Ultralytics YOLOv8 |
|
||||
|
||||
|
||||
!!! Example "Object Cropping using YOLOv8 Example"
|
||||
|
||||
=== "Object Cropping"
|
||||
|
@ -121,21 +121,7 @@ class DistanceCalculation:
|
||||
centroid2 (point): Second bounding box data
|
||||
"""
|
||||
pixel_distance = math.sqrt((centroid1[0] - centroid2[0]) ** 2 + (centroid1[1] - centroid2[1]) ** 2)
|
||||
return pixel_distance / self.pixel_per_meter
|
||||
|
||||
def plot_distance_and_line(self, distance):
|
||||
"""
|
||||
Plot the distance and line on frame
|
||||
Args:
|
||||
distance (float): Distance between two centroids
|
||||
"""
|
||||
cv2.rectangle(self.im0, (15, 25), (280, 70), (255, 255, 255), -1)
|
||||
cv2.putText(
|
||||
self.im0, f"Distance : {distance:.2f}m", (20, 55), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 0), 2, cv2.LINE_AA
|
||||
)
|
||||
cv2.line(self.im0, self.centroids[0], self.centroids[1], self.line_color, 3)
|
||||
cv2.circle(self.im0, self.centroids[0], 6, self.centroid_color, -1)
|
||||
cv2.circle(self.im0, self.centroids[1], 6, self.centroid_color, -1)
|
||||
return pixel_distance / self.pixel_per_meter, (pixel_distance / self.pixel_per_meter) * 1000
|
||||
|
||||
def start_process(self, im0, tracks):
|
||||
"""
|
||||
@ -166,8 +152,10 @@ class DistanceCalculation:
|
||||
centroid = self.calculate_centroid(self.selected_boxes[trk_id])
|
||||
self.centroids.append(centroid)
|
||||
|
||||
distance = self.calculate_distance(self.centroids[0], self.centroids[1])
|
||||
self.plot_distance_and_line(distance)
|
||||
distance_m, distance_mm = self.calculate_distance(self.centroids[0], self.centroids[1])
|
||||
self.annotator.plot_distance_and_line(
|
||||
distance_m, distance_mm, self.centroids, self.line_color, self.centroid_color
|
||||
)
|
||||
|
||||
self.centroids = []
|
||||
|
||||
|
@ -519,6 +519,51 @@ class Annotator:
|
||||
self.im, label, (int(mask[0][0]) - text_size[0] // 2, int(mask[0][1]) - 5), 0, 0.7, (255, 255, 255), 2
|
||||
)
|
||||
|
||||
def plot_distance_and_line(self, distance_m, distance_mm, centroids, line_color, centroid_color):
|
||||
"""
|
||||
Plot the distance and line on frame.
|
||||
|
||||
Args:
|
||||
distance_m (float): Distance between two bbox centroids in meters.
|
||||
distance_mm (float): Distance between two bbox centroids in millimeters.
|
||||
centroids (list): Bounding box centroids data.
|
||||
line_color (RGB): Distance line color.
|
||||
centroid_color (RGB): Bounding box centroid color.
|
||||
"""
|
||||
(text_width_m, text_height_m), _ = cv2.getTextSize(
|
||||
f"Distance M: {distance_m:.2f}m", cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2
|
||||
)
|
||||
cv2.rectangle(self.im, (15, 25), (15 + text_width_m + 10, 25 + text_height_m + 20), (255, 255, 255), -1)
|
||||
cv2.putText(
|
||||
self.im,
|
||||
f"Distance M: {distance_m:.2f}m",
|
||||
(20, 50),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.8,
|
||||
(0, 0, 0),
|
||||
2,
|
||||
cv2.LINE_AA,
|
||||
)
|
||||
|
||||
(text_width_mm, text_height_mm), _ = cv2.getTextSize(
|
||||
f"Distance MM: {distance_mm:.2f}mm", cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2
|
||||
)
|
||||
cv2.rectangle(self.im, (15, 75), (15 + text_width_mm + 10, 75 + text_height_mm + 20), (255, 255, 255), -1)
|
||||
cv2.putText(
|
||||
self.im,
|
||||
f"Distance MM: {distance_mm:.2f}mm",
|
||||
(20, 100),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.8,
|
||||
(0, 0, 0),
|
||||
2,
|
||||
cv2.LINE_AA,
|
||||
)
|
||||
|
||||
cv2.line(self.im, centroids[0], centroids[1], line_color, 3)
|
||||
cv2.circle(self.im, centroids[0], 6, centroid_color, -1)
|
||||
cv2.circle(self.im, centroids[1], 6, centroid_color, -1)
|
||||
|
||||
def visioneye(self, box, center_point, color=(235, 219, 11), pin_color=(255, 0, 255), thickness=2, pins_radius=10):
|
||||
"""
|
||||
Function for pinpoint human-vision eye mapping and plotting.
|
||||
|
Loading…
x
Reference in New Issue
Block a user