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, image_path = '/home/pi/pest_images/captured_image.jpg'
capture_image()
the system identifies and manages pests in real-time. This pest_type = predict_pest(image_path)
approach enhances pest control efficiency, reduces manual labor, if pest_type == 0:
print("No pest detected.")
and 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:
The pest detection and management system using Raspberry Pi print("Unknown pest detected.")