{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "PN1cAxdvd61e" }, "source": [ "
\n", "\n", " \n", " \n", "\n", " [中文](https://docs.ultralytics.com/zh/) | [한국어](https://docs.ultralytics.com/ko/) | [日本語](https://docs.ultralytics.com/ja/) | [Русский](https://docs.ultralytics.com/ru/) | [Deutsch](https://docs.ultralytics.com/de/) | [Français](https://docs.ultralytics.com/fr/) | [Español](https://docs.ultralytics.com/es/) | [Português](https://docs.ultralytics.com/pt/) | [Türkçe](https://docs.ultralytics.com/tr/) | [Tiếng Việt](https://docs.ultralytics.com/vi/) | [العربية](https://docs.ultralytics.com/ar/)\n", "\n", " \"Ultralytics\n", " \"Run\n", " \"Open\n", " \"Open\n", " \"Discord\"\n", "\n", "Welcome to the Ultralytics YOLO26 🚀 notebook! YOLO26 is the latest version of the YOLO (You Only Look Once) AI models developed by Ultralytics. 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.\n", "\n", "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.\n", "\n", "We hope that the resources in this notebook will help you get the most out of YOLO26. Please browse the YOLO26 Object Counting Docs for details, raise an issue on GitHub for support, and join our Discord community for questions and discussions!\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": { "id": "o68Sg1oOeZm2" }, "source": [ "# Setup\n", "\n", "pip install `ultralytics` and [dependencies](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml) and check software and hardware.\n", "\n", "[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) [![Downloads](https://static.pepy.tech/badge/ultralytics)](https://clickpy.clickhouse.com/dashboard/ultralytics) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "9dSwz_uOReMI", "outputId": "fd3bab88-2f25-46c0-cae9-04d2beedc0c1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ultralytics 8.3.174 🚀 Python-3.11.13 torch-2.6.0+cu124 CUDA:0 (Tesla T4, 15095MiB)\n", "Setup complete ✅ (2 CPUs, 12.7 GB RAM, 42.2/112.6 GB disk)\n" ] } ], "source": [ "!uv pip install ultralytics\n", "import ultralytics\n", "\n", "ultralytics.checks()" ] }, { "cell_type": "markdown", "metadata": { "id": "m7VkxQ2aeg7k" }, "source": [ "# Object Counting using Ultralytics YOLO26 🚀\n", "\n", "## What is Object Counting?\n", "\n", "Object counting with [Ultralytics YOLO11](https://github.com/ultralytics/ultralytics/) 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.\n", "\n", "## Advantages of Object Counting?\n", "\n", "- **Resource Optimization:** Object counting facilitates efficient resource management by providing accurate counts, and optimizing resource allocation in applications like inventory management.\n", "- **Enhanced Security:** Object counting enhances security and surveillance by accurately tracking and counting entities, aiding in proactive threat detection.\n", "- **Informed Decision-Making:** Object counting offers valuable insights for decision-making, optimizing processes in retail, traffic management, and various other domains.\n", "\n", "## Real World Applications\n", "\n", "| Logistics | Aquaculture |\n", "|:-------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------:|\n", "| ![Conveyor Belt Packets Counting Using Ultralytics YOLO26](https://github.com/RizwanMunawar/ultralytics/assets/62513924/70e2d106-510c-4c6c-a57a-d34a765aa757) | ![Fish Counting in Sea using Ultralytics YOLO26](https://github.com/RizwanMunawar/ultralytics/assets/62513924/c60d047b-3837-435f-8d29-bb9fc95d2191) |\n", "| Conveyor Belt Packets Counting Using Ultralytics YOLO26 | Fish Counting in Sea using Ultralytics YOLO26 |" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Cx-u59HQdu2o" }, "outputs": [], "source": "import cv2\n\nfrom ultralytics import solutions\n\n# Open the video file\ncap = cv2.VideoCapture(\"path/to/video.mp4\")\nassert cap.isOpened(), \"Error reading video file\"\n\n# Get video properties: width, height, and frames per second (fps)\nw, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))\n\n# Define points for a line or region of interest in the video frame\nline_points = [(20, 400), (1080, 400)] # Line coordinates\n\n# Initialize the video writer to save the output video\nvideo_writer = cv2.VideoWriter(\"object_counting_output.avi\", cv2.VideoWriter_fourcc(*\"mp4v\"), fps, (w, h))\n\n# Initialize the Object Counter with visualization options and other parameters\ncounter = solutions.ObjectCounter(\n show=True, # Display the image during processing\n region=line_points, # Region of interest points\n model=\"yolo26n.pt\", # Ultralytics YOLO26 model file\n line_width=2, # Thickness of the lines and bounding boxes\n)\n\n# Process video frames in a loop\nwhile cap.isOpened():\n success, im0 = cap.read()\n if not success:\n print(\"Video frame is empty or video processing has been successfully completed.\")\n break\n\n # Use the Object Counter to count objects in the frame and get the annotated image\n results = counter(im0)\n\n # Write the annotated frame to the output video\n video_writer.write(results.plot_im)\n\n# Release the video capture and writer objects\ncap.release()\nvideo_writer.release()\n\n# Close all OpenCV windows\ncv2.destroyAllWindows()" }, { "cell_type": "markdown", "metadata": { "id": "QrlKg-y3fEyD" }, "source": "# Additional Resources\n\n## Community Support\n\nFor more information on counting objects with Ultralytics, you can explore the comprehensive [Ultralytics Object Counting Docs](https://docs.ultralytics.com/guides/object-counting/). This guide covers everything from basic concepts to advanced techniques, ensuring you get the most out of counting and visualization.\n\n## Ultralytics ⚡ Resources\n\nAt 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:\n\n- [Ultralytics HUB](https://ultralytics.com/hub): Simplify your AI projects with Ultralytics HUB, our no-code tool for effortless YOLO training and deployment.\n- [Ultralytics Licensing](https://ultralytics.com/license): Review our licensing terms to understand how you can use our software in your projects.\n- [About Us](https://ultralytics.com/about): Discover our mission, vision, and the story behind Ultralytics.\n- [Join Our Team](https://ultralytics.com/work): Explore career opportunities and join our team of talented professionals.\n\n## YOLO26 🚀 Resources\n\nYOLO26 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:\n\n- [GitHub](https://github.com/ultralytics/ultralytics): Access the YOLO26 repository on GitHub, where you can find the source code, contribute to the project, and report issues.\n- [Docs](https://docs.ultralytics.com/): Explore the official documentation for YOLO26, including installation guides, tutorials, and detailed API references.\n- [Discord](https://ultralytics.com/discord): Join our Discord community to connect with other users, share your projects, and get help from the Ultralytics team.\n\nThese 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." } ], "metadata": { "accelerator": "GPU", "colab": { "gpuType": "T4", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }