~/dpkkmishra
LinkedIn

$ cd ../blog

feat(agriculture)

Grading grain with a phone camera

A computer-vision pipeline that screens pulse samples from photos, checks its own counts, and refuses to give a score it cannot stand behind.

computer visionOpenCVONNX RuntimeFastAPI

Grain is graded by people looking closely at a handful of it. That works, and it is slow and hard to audit. The goal here was a pipeline that screens a sample from a photo and produces a report someone can argue with.

Step one: fix the photo

Photos from the field are tilted, shadowed and taken from odd distances. Before anything is counted, the pipeline corrects perspective so the sample is seen flat. Skipping this step is how you get a model that works beautifully in the lab and nowhere else.

Count twice

The pipeline, built with FastAPI, OpenCV and NumPy, estimates the grains in more than one way and cross-checks the counts. When the estimates disagree, it withholds the quality score.

That sounds like a small decision. It is the most important one in the system. A number that is sometimes wrong, with no warning, teaches people to ignore every number. A system that says “retake the photo” earns trust for the times it does answer.

Classical first, learned second

Classical vision does the screening. A trained classifier for broken grains, discolouration and spots is evaluated through ONNX Runtime, behind the same interface, so it can prove itself before it is relied on.

A model needs data, so there is a workflow for collecting and labelling training photos. Unglamorous, and the reason the classifier has anything to learn from.

The report

A Next.js dashboard shows annotated reports: the photo, what was detected, and why the score is what it is. Graders can see the evidence, not just the verdict.

Lessons

  • Normalise the input before you get clever.
  • Disagreement between methods is information. Use it.
  • Explainable beats impressive when someone’s payment depends on the result.