Skip to content

About

A Python-based soil nutrient analysis project focused on Nitrogen (N), Phosphorus (P), and Potassium (K) data analysis, visualization, and agricultural insights.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

NPK Soil Analysis & Fertility Prediction

Hybrid Eco-Smart Agriculture: Integrating Digital Sensors and Computer Vision for Precision Soil Nutrient Analysis and Intelligent Fertilizer Recommendation

Undergraduate CSE thesis project — Varendra University.

What this repo contains

File / Folder Purpose
npk_image_processing.py Computer vision pipeline: reads a soil test kit vial image, extracts an HSV color feature, and estimates N, P, K concentration (mg/L) via linear interpolation against a manufacturer-calibrated color chart.
images/ Raw dataset — one folder per soil sample (NPK 01, NPK 02, ...), each containing N.jpg, P.jpg, K.jpg vial photos taken in a controlled environment (same device, light, background).
Dataset/cv_of_npk_detection.csv N/P/K values estimated by the computer-vision pipeline, plus Temp, Moisture, Ph, and Fertility label, for all samples.
Dataset/eye_vision_of_npk_detection.csv Same samples, but N/P/K read manually by eye against the color chart — used as a comparison baseline for the CV pipeline.
fertilizer_recommendation.ipynb Machine learning notebook: trains and compares Random Forest, Decision Tree, SVM, and Logistic Regression to classify soil fertility (Low/Normal/High) from Temp, Moisture, Ph, N, P, K.
best_soil_fertility_model.joblib Final trained model (Random Forest, 93.33% test accuracy), saved for reuse.

Method summary

  1. Soil sample is mixed with water, left to settle, then reacted with N/P/K test reagents.
  2. Each vial's color is compared to a reference chart (values in mg/L) and also photographed in a fixed lighting/background setup.
  3. A computer vision pipeline (npk_image_processing.py) converts each image to HSV, computes a 0.7*Hue + 0.3*Saturation feature, and estimates the mg/L concentration via linear interpolation against the calibration points taken from the same chart.
  4. The resulting N, P, K values (plus Temp, Moisture, Ph) are used to train a fertility classifier (fertilizer_recommendation.ipynb).

Nutrient unit note

N, P, and K values throughout this project are reported in mg/L, matching the units printed on the physical soil test kit's reference color chart used to build the dataset and calibrate the CV pipeline. This keeps the computer-vision output consistent with the ground-truth labels it was calibrated against.

Requirements

pip install -r requirements.txt
pip install pandas numpy matplotlib seaborn scikit-learn joblib

Limitations

  • N/P/K ground truth comes from a single commercial colorimetric soil test kit, not certified laboratory chemical analysis.
  • Dataset is collected under one controlled imaging setup (same device, lighting, background) and has not yet been validated across multiple regions, soil types, or camera types.

About

A Python-based soil nutrient analysis project focused on Nitrogen (N), Phosphorus (P), and Potassium (K) data analysis, visualization, and agricultural insights.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages