📧 Project Description
This project implements a real-time cabbage detection and counting system leveraging YOLO deep learning models for precision agriculture.
The system automatically detects cabbages, assigns each a unique tracking ID, and counts them as they cross a defined virtual boundary line.
By combining object detection, tracking, and line-based counting logic, it provides accurate yield estimation and monitoring for agricultural environments.
The program processes each frame of a video (or live camera feed), annotates the detected cabbages with bounding boxes and tracking IDs, and dynamically updates the count on-screen.
🎯 Core Objectives
-
🌿 Detect cabbages in real time using a custom-trained YOLO model.
-
🧮 Track and count unique cabbages as they cross a predefined line.
-
📈 Ensure accuracy through persistent object IDs and historical tracking.
-
💾 Save annotated videos for monitoring and reporting.
-
🖥️ Provide on-screen overlays for clear visualization and debugging.
-
⚙️ Support both video file input and live camera streams.
✨ Key Features
✅ Real-Time Detection: Uses YOLO for fast and accurate cabbage recognition.
✅ Tracking with Unique IDs: Maintains consistency of objects across frames using built-in tracking.
✅ Line Crossing Counter: Increments count only when objects cross a virtual boundary line.
✅ Smart Visualization: Displays bounding boxes, IDs, center points, and count overlay.
✅ Customizable Line: Adjustable virtual line for flexible counting zones.
✅ Video Output: Automatically saves annotated video for post-analysis.
✅ Efficient Processing: Skips alternate frames for faster real-time inference.
✅ Debug Mode: Optional mouse tracking for pixel coordinate inspection.
🛠️ Technologies Used
| Component | Details |
|---|---|
| Language | Python 3.x |
| Model | YOLO (best.pt custom-trained on cabbage dataset) |
| Libraries | ultralytics, cv2, cvzone, numpy |
| Tracking Method | YOLO built-in tracking (.track() with persist=True) |
| Visualization | OpenCV drawing and cvzone overlays |
| Video Output | MP4 output with annotated bounding boxes and counts |
📌 Use Cases
-
🌾 Agricultural Yield Estimation: Count cabbages or similar crops in drone or static footage.
-
🚜 Field Monitoring: Track crop growth and density across seasons.
-
🧮 Automated Harvest Counting: Estimate total production or packing quantities.
-
📷 Smart Farming Analytics: Integrate counts into dashboards or IoT systems.
-
🧠 AI Research: Extendable to multi-class crop counting or pest detection tasks.
🔮 Possible Enhancements
-
☁️ Cloud Integration: Upload counts and video summaries to cloud dashboards.
-
📊 Data Logging: Store frame-wise counts in CSV or databases.
-
🔔 Alert System: Notify when a specific threshold of count is reached.
-
🌐 Web Dashboard: Real-time display using Flask or Streamlit.
-
🤖 Multi-Class Support: Extend to detect and count multiple crop types.
-
📡 Drone Feed Integration: Apply to aerial field monitoring in smart farms.
✅ Conclusion
The Smart Cabbage Counting System using YOLO and OpenCV is a powerful example of AI-driven precision agriculture.
By combining deep learning–based object detection with real-time tracking and counting logic, it automates the tedious task of manual crop counting.
This system enhances productivity, reduces labor costs, and provides accurate data insights — paving the way for smarter, data-driven agricultural management and scalable farm automation.

Reviews
There are no reviews yet.