π± Plant Counting Framework An end-to-end pipeline for counting plants in drone imagery β from raw aerial images through automated filtering, manual labeling, and COCO/YOLO annotation export.
Overview This framework was built to process high-resolution DJI drone photographs of crop fields. It automates the tedious parts of dataset creation: filtering out irrelevant image tiles using HSV-based green detection, presenting candidate patches to a human labeler via a web UI, storing labels in MongoDB, and exporting the result as YOLO-format annotations ready for model training.
Pipeline DJI Drone Images
β
βΌ
-
Green Coverage Analysis (start.py)
-
Convert to HSV color space
-
Detect green pixels (plants)
-
Filter images with < 20% green coverage
-
Plot coverage distribution (mean / std)
β
βΌ
-
-
Image Tiling & Filtering (webapp.py)
-
Split full-res DJI images into 60Γ80 px patches
-
Drop tiles with < 20% green coverage
β
βΌ
-
-
Web-based Labeling UI (webapp.py + Flask)
-
Serve each patch to a human annotator
-
Label: plant present (yes) or not (no)
-
Store bounding box + label in MongoDB Atlas
β
βΌ
-
-
Annotation Export (/convert endpoint)
-
Read labels from MongoDB
-
Write YOLO-format .txt annotation files
-
Copy images into coco/images/ directory
β
βΌ
-
COCO/YOLO Dataset β ready for model training
Features HSV green detection β automatically discards image tiles that contain no meaningful plant coverage Tile splitting β chops large drone frames into 60Γ80 px patches for patch-level labeling Flask labeling app β browser-based UI to label patches one at a time; no annotation software required MongoDB Atlas storage β labels and bounding boxes are persisted to a cloud database YOLO export β converts stored labels to normalized YOLO .txt format alongside copied images Statistics & visualization β start.py plots the green-coverage distribution across a dataset
Tech Stack Component Technology Image processing OpenCV, Pillow Web framework Flask Database MongoDB Atlas (flask_pymongo) Visualization Matplotlib, SciPy Image source DJI drone (field/aerial) Label format YOLO (normalized bounding boxes)
Project Structure Plant-counting-Framework/
βββ images/ # Raw DJI drone images (input)
βββ coco/
β βββ images/ # Copied images for training
β βββ data/ # YOLO annotation .txt files
βββ serving_static/
β βββ static/
β βββ images/ # Tiled patches served to labeler
β βββ script/ # Frontend JavaScript
βββ templates/ # Flask HTML templates
βββ Gmaps/ # Google Maps integration
βββ GoogleEarth/ # Google Earth imagery
βββ start.py # Green coverage analysis & filtering
βββ webapp.py # Flask labeling app + export
βββ convertCoco.py # COCO conversion utility
βββ readProp.py # Property reader
βββ split.py # Image splitting utility
Getting Started
- Clone the repository git clone https://github.com/kvsandy/Plant-counting-Framework.git
cd Plant-counting-Framework 2. Install dependencies pip install flask flask-pymongo opencv-python pillow scipy matplotlib numpy 3. Add your drone images Place your DJI images inside the images/ directory:
images/
βββ DJI_0444.JPG
βββ DJI_0446.JPG
βββ ... 4. Analyze green coverage (optional pre-filter) python start.py
This scans the images2/ folder, removes images with less than 20% green coverage, and plots the distribution of the remaining images. 5. Configure MongoDB Update the connection string in webapp.py to point to your own MongoDB Atlas cluster:
app.config["MONGO_URI"] = "mongodb+srv://:@.mongodb.net/label_db" 6. Run the labeling web app python webapp.py
Open http://localhost:5000 in your browser. The app will:
Automatically tile your DJI images into 60Γ80 px patches Filter out tiles with insufficient green coverage Present each patch for you to label as plant or not plant 7. Export to YOLO format Once labeling is complete, visit:
This reads your labels from MongoDB and writes YOLO-format annotation files to coco/labels/ alongside the source images in coco/images/.
Label Format Exported annotations follow the YOLO format:
<class_id> <x_center> <y_center>
0 = plant present 1 = no plant All values are normalized to [0, 1] relative to the source image dimensions.
Requirements Python 3.7+ MongoDB Atlas account (free tier works) DJI drone images (or any high-resolution field photos)
Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you'd like to change.
License MIT