This project is a web-based application that predicts the percentage of greenery (trees and vegetation) in an uploaded image. It uses deep learning for vegetation analysis and Flask for web application development. The goal is to facilitate the analysis of greenery in any given image, helping to track and promote environmental sustainability.
This project uses a U-Net model to predict the percentage of greenery in an image. The user uploads an image through a web interface, and the backend calculates and displays the percentage of the image covered by trees or vegetation.
- Flask: Web framework for handling HTTP requests and serving web pages.
- TensorFlow/Keras: Deep learning framework to load and use a pre-trained model for greenery detection.
- OpenCV: Used for image processing tasks, such as reading and resizing images.
- Leaflet: For displaying a map interface in the frontend.
- HTML/CSS/JavaScript: Frontend technologies for UI and interaction.
- Image Upload: Users can upload an image for analysis.
- Greenery Percentage Calculation: The application uses a pre-trained U-Net model to calculate the percentage of greenery (trees and vegetation) in the uploaded image.
- Map Integration: Users can interact with a map, and even capture a map image to analyze its greenery content.
- Real-Time Analysis: Instant prediction results are shown after the user uploads an image.
To run this project locally, follow these steps:
git clone https://github.com/yourusername/greenery-percentage-prediction.git
cd greenery-percentage-prediction
Create a virtual environment and install the required dependencies.
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
The pre-trained model is used for predicting the greenery percentage. You need to download the unet_forest_model.h5
model and place it in the models
directory.
- Download the model here and place it in the
models/
directory.
Start the Flask server:
python application.py
Visit http://127.0.0.1:5000
in your browser to interact with the application.
- Upload an image by clicking the “Choose File” button.
- Once the image is uploaded, the system will process it and display the greenery percentage.
- Use the map interface to capture map images and analyze the greenery percentage.
The image upload form allows the user to select and upload images of vegetation. Upon submitting the form, the backend processes the image and returns the greenery percentage.
The model predicts the percentage of greenery in the uploaded image using the U-Net architecture. The result is displayed on the webpage once the prediction is complete.
Here is the file structure of the project:
greenery-percentage-prediction/
├── application.py # Main Flask application file
├── index.html # Frontend HTML file with image upload and map interface
├── requirements.txt # List of dependencies
├── models/
│ └── unet_forest_model.h5 # Pre-trained model for greenery prediction
├── static/
│ └── css/
│ └── style.css # Custom CSS for styling the frontend
└── uploads/ # Directory for storing uploaded images
The model used in this application is based on the U-Net architecture, specifically trained for vegetation (forest) segmentation. The model takes an image as input and outputs a binary mask indicating areas covered by greenery. The percentage of greenery is then calculated based on the size of the green regions relative to the total image size.
Feel free to contribute to this project by forking the repository, making changes, and submitting pull requests.
- Fork this repository.
- Create a new branch (
git checkout -b feature-name
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-name
). - Create a new Pull Request.