Plant Disease Detection
1. Introduction
Plant Disease Detection is a project that leverages computer vision and machine learning to identify diseases in plants based on leaf images. This system helps farmers and gardeners quickly identify diseases and take corrective actions. It uses image classification models to detect and categorize diseases effectively.
2. Prerequisites
• Python: Install Python 3.x from the official Python
website.
• Required Libraries:
- tensorflow/keras: Install using pip
install tensorflow
- opencv-python: Install using pip
install opencv-python
- numpy: Install using pip install
numpy
- matplotlib: Install using pip install
matplotlib
• Dataset: A collection of labeled images of healthy and diseased plant leaves.
• Trained model: A deep learning model trained on the dataset.
3. Project Setup
1. Create a Project Directory:
- Name your project folder, e.g., `Plant_Disease_Detection`.
- Inside this folder, create the Python script file
(`plant_disease_detection.py`).
2. Install Required Libraries:
Ensure TensorFlow, OpenCV, and other dependencies are installed using `pip`.
4. Writing the Code
Below is an example code snippet for the Plant Disease Detection system:
import cv2
import numpy as np
from tensorflow.keras.models import load_model
# Load pre-trained model
model = load_model('plant_disease_model.h5')
# Load label names
labels = ['Healthy', 'Disease1', 'Disease2', 'Disease3']
# Function to preprocess the image
def preprocess_image(image):
image = cv2.resize(image, (128, 128))
image = np.expand_dims(image, axis=0)
image = image / 255.0
return image
# Function to predict disease
def predict_disease(image):
processed_image = preprocess_image(image)
prediction =
model.predict(processed_image)
return labels[np.argmax(prediction)]
# Main function
def main():
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
cv2.imshow('Original', frame)
# Simulate real-time detection
prediction =
predict_disease(frame)
cv2.putText(frame,
f"Prediction: {prediction}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1,
(255, 0, 0), 2)
cv2.imshow('Plant Disease
Detection', frame)
if cv2.waitKey(1) & 0xFF ==
ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
5. Key Components
• Image Preprocessing: Resizes and normalizes input images
for the model.
• Model Prediction: Uses a trained deep learning model to classify the input
image.
• Real-Time Visualization: Displays predictions on the video feed.
6. Testing
1. Ensure the trained model (`plant_disease_model.h5`) is available in the project directory.
2. Run the script:
python plant_disease_detection.py
3. Verify the predictions for healthy and diseased leaf images.
7. Enhancements
• Dataset Expansion: Include more types of plant diseases in
the dataset.
• Mobile Application: Integrate the model into a mobile app for field use.
• Advanced Models: Use state-of-the-art architectures like EfficientNet for
improved accuracy.
8. Troubleshooting
• Incorrect Predictions: Retrain the model with a larger and
more diverse dataset.
• Model Loading Errors: Verify the path and compatibility of the model.
• Performance Issues: Optimize image processing and model inference steps.
9. Conclusion
The Plant Disease Detection system provides an efficient solution for identifying plant diseases early. It is a valuable tool for farmers and agricultural professionals, reducing losses and improving crop yield.