Assignment Format
Assignment Format
ABSTRACT: CODING:
import cv2
import numpy as np
This project leverages the Raspberry Pi platform to develop a pest import tensorflow as tf
detection and management system aimed at improving agricultural from tensorflow.keras.models import load_model
productivity. The system utilizes a combination of sensors, import RPi.GPIO as GPIO
from time import sleep
cameras, and machine learning algorithms to detect and identify def capture_image():
common agricultural pests in real-time. By automating the process cap = cv2.VideoCapture(0)
of pest detection and management, this solution offers a cost- ret, frame = cap.read()
if ret:
effective, efficient, and scalable approach to pest control, reducing cv2.imwrite('/home/pi/pest_images/captured_image.jpg', frame)
the reliance on manual inspections and chemical pesticides. cap.release()
return frame
model = load_model('/home/pi/pest_detection_model.h5')
def preprocess_image(image_path):
image = cv2.imread(image_path)
INTRODUCTION: image = cv2.resize(image, (224, 224))
image = image.astype('float32') / 255.0
image = np.expand_dims(image, axis=0)
Agriculture is crucial for sustaining the global population, but return image
pests pose significant challenges, causing crop damage and def predict_pest(image_path):
processed_image = preprocess_image(image_path)
economic losses. Traditional pest management often involves prediction = model.predict(processed_image)
labour-intensive monitoring and heavy pesticide use, which can return np.argmax(prediction, axis=1)
GPIO.setmode(GPIO.BCM)
be environmentally harmful. GPIO.setup(18, GPIO.OUT)
def activate_sprinkler(duration):
GPIO.output(18, GPIO.HIGH)
This project leverages the Raspberry Pi platform to develop an sleep(duration)
automated pest detection and management system. Using GPIO.output(18, GPIO.LOW)
def main():
sensors, a camera, and a pre-trained machine learning model, the image_path = '/home/pi/pest_images/captured_image.jpg'
capture_image()
system identifies and manages pests in real-time. This approach pest_type = predict_pest(image_path)
enhances pest control efficiency, reduces manual labor, and if pest_type == 0:
print("No pest detected.")
minimizes pesticide dependence, promoting sustainable elif pest_type == 1:
print("Aphid detected. Activating sprinkler for 5 seconds.")
agriculture. By integrating affordable hardware with advanced activate_sprinkler(5)
software, the project offers a modern solution to improve elif pest_type == 2:
print("Caterpillar detected. Activating sprinkler for 10 seconds.")
agricultural productivity and sustainability. activate_sprinkler(10)
else:
print("Unknown pest detected.")
The pest detection and management system using Raspberry Pi
operates through four key steps: RESULT:
1. Image Capture: The Raspberry Pi camera captures images The pest detection and management system demonstrated effective identification of pests
such as aphids and caterpillars in test environments. The use of a pre-trained deep learning
of crops at regular intervals. model allowed for accurate classification of pests, leading to timely and appropriate
management actions. This automation significantly reduced manual labor and reliance on
2. Image Processing and Pest Detection: These images are chemical pesticides, offering a sustainable approach to pest management in agriculture. The
processed and analysed using a pre-trained convolutional Raspberry Pi-based system proved to be a cost-effective and scalable solution for real-time
pest control, enhancing crop health and productivity.
neural network (CNN) to identify the type and presence of
pests.
SIMULATION OUTPUT :
3. Management Actions: Depending on the pest identified, the
system triggers appropriate actions, such as activating a
sprinkler to apply pesticides or repellents.