0% found this document useful (0 votes)
6 views3 pages

AI Agriculture Project Suite Guide

The document outlines a Python program for AI-based agriculture projects, featuring a menu with options for crop health monitoring, smart irrigation, crop yield prediction, soil health analysis, weather prediction, weed detection, and crop price forecasting. Each option includes basic simulations or analyses, such as image processing for crop health and weed detection, and simple predictive models for crop yield and prices. The program utilizes libraries like NumPy, Pandas, Matplotlib, and OpenCV for data handling and visualization.

Uploaded by

sonidevesh632
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

AI Agriculture Project Suite Guide

The document outlines a Python program for AI-based agriculture projects, featuring a menu with options for crop health monitoring, smart irrigation, crop yield prediction, soil health analysis, weather prediction, weed detection, and crop price forecasting. Each option includes basic simulations or analyses, such as image processing for crop health and weed detection, and simple predictive models for crop yield and prices. The program utilizes libraries like NumPy, Pandas, Matplotlib, and OpenCV for data handling and visualization.

Uploaded by

sonidevesh632
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import numpy as np

import pandas as pd
import [Link] as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from [Link] import RandomForestClassifier
from [Link] import accuracy_score, mean_squared_error
from [Link] import Sequential
from [Link] import Dense
import cv2
import os

# Menu for AI-based Agriculture Projects


def main_menu():
while True:
print("\nAI in Agriculture Project Suite")
print("1. Crop Health Monitoring")
print("2. Smart Irrigation System")
print("3. Crop Yield Prediction")
print("4. Soil Health Analysis")
print("5. Weather Prediction")
print("6. Weed Detection")
print("7. Crop Price Forecasting")
print("8. Exit")
choice = input("\nSelect an option (1-8): ")
if choice == '1':
crop_health_monitoring()
elif choice == '2':
smart_irrigation()
elif choice == '3':
crop_yield_prediction()
elif choice == '4':
soil_health_analysis()
elif choice == '5':
weather_prediction()
elif choice == '6':
weed_detection()
elif choice == '7':
crop_price_forecasting()
elif choice == '8':
print("Exiting... Goodbye!")
break
else:
print("Invalid choice. Please try again.")

# 1. Crop Health Monitoring (Basic Simulation)


def crop_health_monitoring():
print("\nCrop Health Monitoring")
image_path = input("Enter path to crop image: ")
if [Link](image_path):
image = [Link](image_path)
gray = [Link](image, cv2.COLOR_BGR2GRAY)
_, thresh = [Link](gray, 128, 255, cv2.THRESH_BINARY)
print("Image processed for crop health analysis.")
[Link]([Link](thresh, cv2.COLOR_BGR2RGB))
[Link]()
else:
print("Image not found. Please check the path.")
# 2. Smart Irrigation System
def smart_irrigation():
print("\nSmart Irrigation System")
soil_moisture = float(input("Enter soil moisture percentage (0-100): "))
if soil_moisture < 30:
print("Irrigation required.")
else:
print("Soil moisture is sufficient.")

# 3. Crop Yield Prediction


def crop_yield_prediction():
print("\nCrop Yield Prediction")
data = {'Rainfall': [100, 200, 150, 300, 250],
'Fertilizer': [20, 30, 25, 35, 30],
'Yield': [3000, 3500, 3200, 4000, 3700]}
df = [Link](data)
X = df[['Rainfall', 'Fertilizer']]
y = df['Yield']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)
model = LinearRegression()
[Link](X_train, y_train)
predictions = [Link](X_test)
print(f"Predicted Yield: {predictions}")
print(f"Mean Squared Error: {mean_squared_error(y_test, predictions)}")

# 4. Soil Health Analysis (Basic Simulation)


def soil_health_analysis():
print("\nSoil Health Analysis")
ph_level = float(input("Enter soil pH level (0-14): "))
if 6 <= ph_level <= 7.5:
print("Soil pH is optimal.")
else:
print("Soil pH is not ideal. Amendments required.")

# 5. Weather Prediction (Simple Simulation)


def weather_prediction():
print("\nWeather Prediction")
temp = float(input("Enter today's temperature (°C): "))
if temp > 35:
print("Hot weather expected.")
elif 25 <= temp <= 35:
print("Moderate weather expected.")
else:
print("Cold weather expected.")

# 6. Weed Detection (Basic Image Processing)


def weed_detection():
print("\nWeed Detection")
image_path = input("Enter path to field image: ")
if [Link](image_path):
image = [Link](image_path)
hsv = [Link](image, cv2.COLOR_BGR2HSV)
lower_green = [Link]([25, 40, 40])
upper_green = [Link]([90, 255, 255])
mask = [Link](hsv, lower_green, upper_green)
print("Weed detection completed.")
[Link](mask, cmap='gray')
[Link]()
else:
print("Image not found. Please check the path.")

# 7. Crop Price Forecasting (Simple Simulation)


def crop_price_forecasting():
print("\nCrop Price Forecasting")
past_prices = [1000, 1100, 1050, 1200, 1150]
future_price = [Link](past_prices) * 1.05
print(f"Predicted crop price next month: ₹{future_price:.2f}")

# Run the program


if __name__ == '__main__':
main_menu()

Common questions

Powered by AI

Image thresholding in crop health monitoring serves to simplify the visual information by converting a grayscale image to a binary image. This is achieved by setting a threshold value (128) and converting pixel values accordingly: pixels above the threshold are set to the maximum value (255), while those below are set to zero. This binary conversion helps in extracting and analyzing features critical for assessing crop health by highlighting specific areas of interest in the image, making them easier to process and evaluate .

The crop yield prediction model uses a Linear Regression approach. It processes input data consisting of 'Rainfall' and 'Fertilizer' as features to predict 'Yield'. The data is split into training and test sets with a 70/30 ratio. The model is trained on the training data, and predictions are made on the test set. The predicted crop yields are then compared against the actual yields using the mean squared error metric to evaluate the prediction accuracy .

The system determines the necessity for irrigation based on the soil moisture percentage. If the input soil moisture is below 30%, the system recommends that irrigation is required. Conversely, if the soil moisture is 30% or above, the system concludes that soil moisture is sufficient and irrigation is not necessary .

Crop yield prediction uses a Linear Regression model to learn relationships between features (Rainfall and Fertilizer) and the target variable (Yield) through training data. The approach involves splitting data, training the model, and evaluating it using mean squared error. In contrast, crop price forecasting applies a straightforward statistical method of averaging past prices and projecting future ones by a constant growth factor, reflecting a non-machine learning approach. This highlights a key difference where one utilizes data-driven learning and error evaluation, while the other relies on basic statistical projection without learning from data patterns beyond fixed percentage growth .

The crop price forecasting method uses a basic averaging technique on past prices. It calculates the mean of historical crop prices and projects future prices by multiplying the average by 1.05 (a 5% increase) to account for expected growth. The predicted crop price for the next month is derived this way, yielding a projected outcome of incrementally increased prices .

The weather prediction component classifies weather conditions based on the input temperature. If the temperature is greater than 35°C, it predicts hot weather; if the temperature falls between 25°C and 35°C inclusive, it predicts moderate weather; and if the temperature is below 25°C, it predicts cold weather. These classifications help in providing simple forecasts based on current temperature inputs .

The effectiveness of the Linear Regression model for crop yield prediction can be assessed using the given results. The model's predicted yields are compared with actual yields using the mean squared error (MSE) metric. A lower MSE indicates high prediction accuracy, suggesting the model effectively captures patterns in the relationship between rainfall, fertilizer usage, and yield. However, without specific MSE values or a comparison to other models, the absolute effectiveness cannot be fully determined .

The AI-based weed detection process involves using image processing techniques. First, an image of the field is loaded using OpenCV. The image is converted from BGR to HSV color space, which is more effective for segmenting images based on color. A mask is then created to identify green hues, which are typical of vegetation, using a range of HSV values (lower_green = [25, 40, 40] and upper_green = [90, 255, 255]). This highlights areas in the image that fall within this range, allowing detection of green plants such as weeds. Finally, the mask is displayed to visualize the detected weeds .

The AI-based agriculture project suite utilizes several software libraries and packages: Numpy and Pandas for data manipulation and analysis; Matplotlib and OpenCV for image processing and visualization; Scikit-learn for machine learning models, especially train-test splitting and regression; TensorFlow and Keras for building and training neural networks; and OpenCV for operations related to image processing, such as converting color spaces and making thresholds for binary images. Each library is critical for different parts of the process, from managing data (Pandas, Numpy) to visualizing and processing images (Matplotlib, OpenCV), and building predictive models (Scikit-learn, TensorFlow, Keras).

The system considers the soil pH level to be optimal if it lies between 6.0 and 7.5 inclusive. This range is deemed suitable for most agricultural purposes because it supports the availability of nutrients necessary for plant growth. Outside this range, the soil may require amendments to adjust its pH and create better conditions for plant health .

You might also like