Object counting Real time from drone video

I am beginner to Yolo object detection. I have a video from drone which shot the region of palm and coconut trees. I fine tuned yolov8 model with custom dataset. Now while predicting the input is video. I am confused whether overlapping will be there while counting and how can we be sure that all frames are captured and not overlapped and duplicated while counting.

Hello! :wave:

Welcome to the world of YOLO and object detection! It’s great to hear you’ve fine-tuned a YOLOv8 model for drone imagery. Your question about avoiding overlapping and duplication during object counting is a common concern, and I’d be happy to help clarify.

To ensure accurate counting without duplication or overlap, you can make use of object tracking techniques in YOLO. Object tracking assigns unique IDs to detected objects across video frames, which helps in maintaining consistency and prevents double-counting. Here’s how you can implement it:

Steps to Avoid Overlaps and Ensure Accuracy

  1. Use Tracking Mode: YOLO has a built-in track mode that integrates tracking algorithms like ByteTrack or BoTSort. These algorithms link detections across frames, ensuring objects are counted only once as they move through the video.

    Example command:

    yolo track model=path/to/your/model.pt source=path/to/drone/video.mp4 tracker=bytetrack.yaml
    

    This will process your video and track objects while avoiding duplication.

  2. Define Regions (Optional): If you want to count objects within specific areas of the frame, you can use region counting. This ensures you’re only counting objects that pass through defined zones. You can refer to the Region Counting Guide for more details.

  3. Confidence Threshold: Set an appropriate confidence threshold for detections (e.g., --conf 0.5) to reduce false positives. This helps in counting only valid objects.

  4. Persistent Tracking: Use the persist=True argument in the tracker to ensure object IDs are maintained across longer sequences, even if objects temporarily disappear from the frame.

Example Python Code for Tracking and Counting

Here’s an example of how you can use YOLO in Python for tracking and counting objects:

from ultralytics import YOLO

# Load your fine-tuned YOLO model
model = YOLO("path/to/your/model.pt")

# Run tracking on video
results = model.track(source="path/to/drone/video.mp4", tracker="bytetrack.yaml", show=True)

# Process the tracked results
for result in results:
    print(f"Frame {result.frame_idx}: {len(result.boxes)} objects detected")

Additional Considerations

  • Frame Drops: Ensure the video processing captures all frames. If you’re using OpenCV or similar tools, check the frame rate (fps) and confirm no frames are skipped during processing.
  • Evaluation: Validate the counts by manually reviewing a few frames to verify the accuracy of the tracking.

You’re on the right track! Feel free to explore more about YOLOv8 Tracking and Object Counting for practical examples and insights.

Happy coding and best of luck with your project! :palm_tree::movie_camera:

Thankyou very much. I will implement this and check the results.