examples/object_counting.ipynb
中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية
<a href="https://github.com/ultralytics/ultralytics/actions/workflows/ci.yml"></a> <a href="https://console.paperspace.com/github/ultralytics/ultralytics"></a> <a href="https://colab.research.google.com/github/ultralytics/ultralytics/blob/main/examples/object_counting.ipynb"></a> <a href="https://www.kaggle.com/models/ultralytics/yolo26"></a> <a href="https://ultralytics.com/discord"></a>
Welcome to the Ultralytics YOLO26 🚀 notebook! <a href="https://github.com/ultralytics/ultralytics">YOLO26</a> is the latest version of the YOLO (You Only Look Once) AI models developed by <a href="https://ultralytics.com">Ultralytics</a>. This notebook serves as the starting point for exploring the various resources available to help you get started with YOLO26 and understand its features and capabilities.
YOLO26 models are fast, accurate, and easy to use, making them ideal for various object detection and image segmentation tasks. They can be trained on large datasets and run on diverse hardware platforms, from CPUs to GPUs.
We hope that the resources in this notebook will help you get the most out of YOLO26. Please browse the YOLO26 <a href="https://docs.ultralytics.com/guides/object-counting/"> Object Counting Docs</a> for details, raise an issue on <a href="https://github.com/ultralytics/ultralytics">GitHub</a> for support, and join our <a href="https://ultralytics.com/discord">Discord</a> community for questions and discussions!
</div>pip install ultralytics and dependencies and check software and hardware.
!uv pip install ultralytics
import ultralytics
ultralytics.checks()
Object counting with Ultralytics YOLO11 involves accurate identification and counting of specific objects in videos and camera streams. YOLO11 excels in real-time applications, providing efficient and precise object counting for various scenarios like crowd analysis and surveillance, thanks to its state-of-the-art algorithms and deep learning capabilities.
| Logistics | Aquaculture |
|---|---|
| Conveyor Belt Packets Counting Using Ultralytics YOLO26 | Fish Counting in Sea using Ultralytics YOLO26 |
import cv2
from ultralytics import solutions
# Open the video file
cap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
# Get video properties: width, height, and frames per second (fps)
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
# Define points for a line or region of interest in the video frame
line_points = [(20, 400), (1080, 400)] # Line coordinates
# Initialize the video writer to save the output video
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Initialize the Object Counter with visualization options and other parameters
counter = solutions.ObjectCounter(
show=True, # Display the image during processing
region=line_points, # Region of interest points
model="yolo26n.pt", # Ultralytics YOLO26 model file
line_width=2, # Thickness of the lines and bounding boxes
)
# Process video frames in a loop
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
# Use the Object Counter to count objects in the frame and get the annotated image
results = counter(im0)
# Write the annotated frame to the output video
video_writer.write(results.plot_im)
# Release the video capture and writer objects
cap.release()
video_writer.release()
# Close all OpenCV windows
cv2.destroyAllWindows()
For more information on counting objects with Ultralytics, you can explore the comprehensive Ultralytics Object Counting Docs. This guide covers everything from basic concepts to advanced techniques, ensuring you get the most out of counting and visualization.
At Ultralytics, we are committed to providing cutting-edge AI solutions. Here are some key resources to learn more about our company and get involved with our community:
YOLO26 is the latest evolution in the YOLO series, offering state-of-the-art performance in object detection and image segmentation. Here are some essential resources to help you get started with YOLO26:
These resources are designed to help you leverage the full potential of Ultralytics' offerings and YOLO26. Whether you're a beginner or an experienced developer, you'll find the information and support you need to succeed.