Skip to content

Repository files navigation

🌱 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

  β”‚

  β–Ό
  1. 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)

      β”‚

      β–Ό

  2. Image Tiling & Filtering (webapp.py)

    • Split full-res DJI images into 60Γ—80 px patches

    • Drop tiles with < 20% green coverage

      β”‚

      β–Ό

  3. 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

      β”‚

      β–Ό

  4. 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

  1. 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:

http://localhost:5000/convert

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages