The problem
Grain traders, millers and farmer-producer groups still grade grain mostly by eye: an inspector scoops a sample, looks at kernel size, color uniformity and visible defects, and assigns a grade from experience. That is slow, subjective, and two inspectors can grade the same lot differently. Instrumental lab analysis exists but is out of reach for small operations. Computer vision fills this middle ground: a camera, controlled lighting and a classifier that measures exactly the features an inspector looks at — color, size, shape and texture — and applies the same decision every time. This project builds that system as a classical machine-learning pipeline: no deep-learning black box, just interpretable handcrafted features and an SVM or Random Forest classifier trained on labeled reference samples you photograph and label yourself. Because the features are inspectable, the report and viva discussion can explain why a sample got its grade — kernel-size distribution, discoloration share, broken-kernel rate — which is exactly the kind of explainability deep models cannot offer.
How it works
- A grain sample is photographed on a matte uniform background with even diffuse lighting at a fixed camera height.
- OpenCV converts the image to HSV and segments kernels from the background via thresholding plus morphological cleanup.
- Contour detection extracts every kernel and computes size and shape features — area, perimeter, aspect ratio, circularity, equivalent diameter.
- HSV color histograms and GLCM texture features (contrast, homogeneity, energy) are computed per kernel.
- Features are normalized with StandardScaler and fed to the trained SVM or Random Forest classifier for per-kernel predictions.
- Per-kernel predictions are aggregated by majority vote into the sample grade; batch mode writes per-sample grades and feature summaries to a report.
Tech stack:
- Python 3.10, scikit-learn (SVM, Random Forest, StandardScaler)
- OpenCV (segmentation, contour extraction, color histograms)
- scikit-image (GLCM texture features)
- NumPy, pandas (feature tables and grade reports)
- Jupyter notebook (buyer-run training and evaluation)
- Matplotlib (feature distributions, confusion matrix plots)
- Flask demo app with sample-image upload interface
| Parameter | Value |
|---|---|
| Model | SVM (RBF kernel) or Random Forest classifier in scikit-learn |
| Features | HSV color histograms, contour size/shape measures, GLCM texture (contrast, homogeneity, energy) |
| Segmentation | HSV thresholding plus morphological cleanup on uniform-background photos |
| Grade classes | Configurable (e.g. premium / average / poor) by majority vote of per-kernel predictions |
| Evaluation | Accuracy, confusion matrix, per-class F1 — computed by the notebook on your validation samples during your build |
| Input | Sample photographs on a uniform background with even lighting |
| Output | Per-sample grade, per-kernel predictions, batch grade report |
| Imaging setup | Matte uniform background, fixed camera height, even diffuse lighting |
Project features
- Kernel segmentation from sample photos via HSV thresholding and morphological cleanup
- Per-kernel size and shape features: area, perimeter, aspect ratio, circularity, equivalent diameter
- HSV color histogram features capturing discoloration and color uniformity
- GLCM texture features (contrast, homogeneity, energy) for surface and damage cues
- SVM (RBF kernel) and Random Forest classifiers in scikit-learn with StandardScaler normalization
- Sample-level grading by majority vote over per-kernel predictions, with configurable grade classes
- Batch mode that grades many samples and writes a per-sample grade report
- Evaluation notebook computing accuracy, confusion matrix and per-class F1 on your validation samples
What is included
- Complete source code (segmentation, feature extraction, training, grading, reporting, demo app)
- Jupyter training and evaluation notebook (buyer-run procedure: label reference samples, train, evaluate)
- Project report PDF (background, feature design, methodology, evaluation, error analysis)
- PPT presentation for final review
- Viva Q&A preparation document (GLCM, SVM, color spaces, segmentation, grading logic)
- Setup guide (environment, imaging setup, labeling reference samples, grading your own samples)
Limitations & prerequisites
- The classifier is only as good as the labeled reference samples you provide: it cannot recognize defects or varieties absent from the training labels, and the report documents this openly.
- Grading depends on imaging discipline — inconsistent lighting, background or camera height shifts feature distributions, so the setup guide fixes the imaging protocol.
- The system measures appearance features only; moisture content, internal pests and chemical quality are outside a camera's view and need laboratory tests.
Frequently Asked Questions
Why use handcrafted features instead of a CNN?
Grain grading is a feature-explainable problem: color histograms, kernel size and texture map directly onto what human inspectors judge. Handcrafted features train in seconds on a CPU, need far fewer labeled samples, and let the report explain each grade decision — strengths a viva examiner appreciates.
What is a GLCM texture feature?
The gray-level co-occurrence matrix (Haralick et al., 1973) counts how often pairs of gray levels occur at a fixed offset in the image. From it come contrast, homogeneity and energy — numbers that capture surface roughness and damage that color and size miss.
How do I get training data?
You photograph and label your own reference samples: spread known-grade grain on the uniform background, image it with the documented protocol, and label each sample's grade. The notebook walks through labeling, training and evaluation as one procedure.
How is the classifier evaluated?
The included notebook computes accuracy, the confusion matrix and per-class F1 on your held-out validation samples, with feature-distribution plots — the report documents the procedure and your own build's numbers.
How many grade classes can it have?
Any number you label — premium/average/poor is the default example, but the classes, majority-vote rule and thresholds are all configurable in the code.
Can it detect insect damage or moisture?
No. It grades what the camera can see: size, shape, color and texture. Moisture, internal infestation and chemical properties need lab instruments; the report states this boundary explicitly. Suitable for B.E./B.Tech final-year projects in Computer Science, AI/ML and Data Science.
Components & software requirements
- Python 3.10, scikit-learn (SVM, Random Forest, StandardScaler)
- OpenCV (segmentation, contour extraction, color histograms)
- scikit-image (GLCM texture features)
- NumPy, pandas (feature tables and grade reports)
- Jupyter notebook (buyer-run training and evaluation)
- Matplotlib (feature distributions, confusion matrix plots)
- Flask demo app with sample-image upload interface
Delivery information
Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.
Support terms
Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.