Grocer-Ease: Grain Classification, Quality Prediction and Level Monitoring System

Keeping track of quality and availability of grains is time-taking and a burdening task. Hence, this paper proposes an architecture which will make classifying of grain, predicting quality and monitoring effortless, hence GROCER-EASE. It will help user to determine type and quality of grain, as well as notify user when level of grain becomes below some threshold value. In an overview it uses Image processing, and concepts of CNN and weighted NN-classifier. The complete system can be divided into two major modules. The first being the Grain detection and quality prediction module and second is the Level monitoring module. In Grain detection and quality prediction module, the grain is first classified using pre-trained CNN model. Once, the type of grain is known, different features are extracted like major-axis, minor-axis, lustre, area, roundness, aspect-ratio etc which is used for classifying the grain within its class. Weighted NNclassifier is used for determining the type of rice/pulse (dal) (can be scaled to any number of grains with appropriate dataset) The quality-index is determined based on number of foreign particles present, area of lustre in grain particles, aspect ratio etc. Secondly, in Level monitoring System, a pretrained CNN model is used to determine level of grain in container (which can be placed at a distance). This module records level a defined frequency and notifies the user of the decreased level, once the level goes below a pre-defined threshold. The system proposed can prove to be useful in public sector if installed in modular kitchen setups and can provide a complete solution for better handling of groceries.

INTRODUCTION As Day-to-day life becomes busy, it is of great importance for us to take good care of our health. To maintain a good health, intake of proper food is a must. Thus, it is very important for us to choose wisely what we intake. Sadly, in this busy life, most people fail to maintain a quality intake. This causes many diseases and breakdown of health in general.
The food industry has been growing at a very fast pace to meet the needs quantitatively at a cost of lower quality. There is a need to keep a check on the quality of food one intakes. Many researches are going on from a long time to incorporate proper measures for this purpose. Food quality is an important food requirement, because food consumers are susceptible to any form of contamination that may occur during the collection and processing.
As India is the highest producer of pulse and rice (agriculture) across the globe, many varieties of rice and pulses are produced and is very difficult to identify each variety and determine the quality of it. The quality of food is an important factor for proper nourishment and today's market should be free of adulterated food grains. These grains consist of several impurities like stones, damaged seeds, broken granules etc. The addition of impurities in food affects the composition and quality of food. There is no convenient method to identify these inferior quality grains in the market. Human perception based on visual inspection has long been recognized as a guide to quality assessment but the results are not accurate and reliable.
When the food, especially grains available for public intake is degrading with such a high rate, keeping track of quality surely needs assistance and idea. Also, its more often than never that we lose track of the availability of food in household until we run out it. These problems are very common and a solution to this is of high interest. Having a complete household solution, which keeps track of all the availability and quality of groceries we need would ease dayto-day life.
So, we fixating on the burning need of an assistance which can guide us about the quality of grain and can also keep track of the availability of the grains, we decided to pursue this idea as our final year project. The system which we have built has two major modules. First one is Classifying and Quality Determining Module and the second one is Level monitoring module. Level monitoring system, which would keep track of the necessary grain availability and notify before the user runs out of it. Quality determination module determines the detailed information of quality of grain. This can help the user to know the quality of grain available in the market.
We have used Machine learning and Image processing to our dispense in making of this project, which can detect decrease in level and quality of the grain. In system we have built, the user can upload image of the grain before buying and can determine the quality. Also, with a pi cam setup along with raspberry pi, the system can keep constant track of the availability of the grain, and notify when the level goes below certain pre-decided threshold. The flow of the project consists different layers and all the layers work in sync to give best possible output. The system first determines the type of grain, followed by classification of type of grain and finally the quality index. Hence, giving complete knowledge about the grain. Various morphological factors are used amongst which size, roundness, lustre, foreign particles, fullness, texture are few to mention. We hope the project we built proves to be of some relevance and is capable of having some impact on common.
II. RELATED WORKS Food quality detection has been a focus of research since long time now. Many approaches have been used to design quality detection models. Some paper [1] have used principal component analysis, canny edge and comparison for rice grain identification and quality analysis. The model was accurate but slow. [6] Some have also used the image processing technique based on principal component analysis to detect quality. One of the papers referred [8] worked on Image Processing Based with Bayesian Regularization Learning Algorithm for detection of quality of wheat grains. In this paper the features used were less in number, but the system gave reasonable efficiency.
The paper [2] proposes system to monitor food grain and maintain storage system at home mainly using IoT. Another paper studied [3] classify the varieties of grain using ANN.
The paper [4] has used back-propagation neural network for rice grain classification. [9] present the way to detect foreign bodies in grain using ANN.
All the papers mentioned and many other gave a thorough insight for making of this paper. They gave the basic idea that using a well-trained CNN model can be used to detect grains and the morphological characters extracted by image processing techniques can be used detect the variety and quality of grains too.

III. PROPOSED SYSTEM
The system is divided into two modules:

A. Grain detection and Quality Prediction Module
This module detects the quality of grains of uploaded image. It mainly focuses on morphological features of the grain particles to detect the quality. In this module concepts of CNN, image processing and NN classifier is used.
Steps followed in this module are-

Pre-processing of image
This sub-module processes the input image by-• Binarization using thresholding (Converting the image into grayscale) • Applying averaging filter (Used to suppress either the high frequencies in the image, i.e. smoothing the image, or the low frequencies, i.e. enhancing or detecting edges in the image) • Erosion (erosion removes pixels on object boundaries) • Dilation (Dilation adds pixels to the boundaries of objects in an image) • These enhances the morphological features to be extracted.

Identification of grain
This sub-module accepts the pre-processed image. Uses CNN-model to detect the grain. The model is trained using 200 images for each grain. These images are taken from distance of 10cm -20 cm distance in varying lighting conditions.

Morphological features extraction
Once the type of grain is detected then the morphological features respective to the grain is detected. Morphological features such as length of grain particles, width of particles, total area and perimeter of one particle, lustre present or not if present area of lustre, presence of foreign body. All these features extracted are stored in a csv file which is further used for classification.

Grain variety detection
In this sub-module the variety of grain is determined based on the morphological features extracted. These features are grain specific and each feature is allotted weight which makes sure the participation of features in determination of grain variety is based on importance of the feature.

Quality Prediction
The quality is determined in form of an index whose value can range from 0 to 1. This index is calculated based on various features. These features are Number of foreign particles, size of foreign particle, lustre, aspect ratio, roundness, fullness etc.

B. Level Monitoring 1. Acquiring Input Image
The input image is captured using pi-camera setup in an reasonable distance and lighting condition. These images were taken every 30 minutes.

Processing and Determination of Level of grain
The image input is processed and input into pre-trained CNN model which determines the level of grain.

Comparison and Notification
The level detected is compared to pre-determined threshold value. If the level is found to be below the threshold value appropriate notification is given to the user.

Storage of data in Cloud and Comparison
• Data gathered from the previous step is stored in cloud (to be done)/file (for local) which is compared to pre-set threshold • Notification system (to be done) • This submodule is triggered when data predicted satisfies threshold condition. • Cart Building and Ordering (to be done) • This sub-module is triggered along with notification system to place order.

IV. ALGORITHMS
The following Concepts of Machine Learning are used at the proposed systems disposal-

Weighted NN Classifier
Weighted KNN is a modified version of k nearest neighbours. One of the many issues that affect the performance of the KNN algorithm is the choice of the hyperparameter k. If k is too small, the algorithm would be more sensitive to outliers. If k is too large, then the neighbourhood may include too many points from other classes. Another issue is the approach to combining the class labels. The simplest method is to take the majority vote, but this can be a problem if the nearest neighbours vary widely in their distance and the closest neighbours more reliably indicate the class of the object.

CNN
The algorithm applies a single neural network to the full image, and then divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities. a single CNN simultaneously predicts multiple bounding boxes and class probabilities for those boxes. CNN trains on full images and directly optimizes detection performance. the entire image during training and test time so it implicitly encodes contextual information about classes as well as their appearance. It learns generalizable representations of objects so that when trained on natural images and tested on artwork, the algorithm outperforms other top detection methods. The most important feature of C-CNN is that it is very efficient and fast in Realtime.

Mobile Camera
Mobile camera is the source of image. End-User can upload image of the grain for which the result is responded as Type of grain, category of grain and quality index.

User Dashboard
User Dashboard is the User Interface in which the user can interact with the system. The option to upload image and then segment to view result can be viewed on this interface. The results consist of grain, variety of grain, and quality of grain.

Notification System
The notification system notifies customer of the alarming level of grain before it runs out.

Camera
Pi Cam which is compatible with Raspberry Pi is used, and uploads image every 30 mins. This image is sent to Raspberry pi connected to pi cam over Bluetooth.

Raspberry Pi
In this Raspberry Pi the trained model is uploaded and is processed to save the calculated data of level of grain in each container Here the level detection data is stored and computed. Any alarming level is notified through notification system.

Cloud
Cloud is used to store the data recorded in regular time interval. This data is used to compare and notify user, when needed.

Containers
These containers are placed on a shelf mounted on wall at a distance of 1.5 m from Pi-camera which takes image of this shelf from which the level of grain in each container is detected. VII. RESULT AND TESTING The proposed system showed the output of 90.06% for quality detection module and 96% accuracy for level detection module.
The system is also resonably fast as it takes response time of 20 -50 seconds in quality module and 7 -15 seconds in level detection module. The system is tested under various lighting condition with variety of image quality and I sfound to perform as expected. Some of the sample cases are discussed in the Table I And Table II. The output of various pre-processing steps is illustrated in Figure 3. Various morphological features extracted is illustrated in Figure 4. The snapshots of endproduct is shown in Figure 5 and Figure  6.   In this research article, we developed a system which can classify and determine quality of grain and can also monitor level of grain from time to time. In the grain detection and quality prediction module we have used CNN to detect the grain. Image processing is used to extract various relevant morphological features which is then used by NN classifier to detect the variety of the grain. Then these features along with few more is used to predict the quality index.
In the level monitoring module, we use CNN to our disposal for detection of level. The system developed was reasonably accurate and functioned efficiently.

IX. FUTURE WORK
The accuracy can be elevated by considering various other conditions while building the dataset. The system can be trained to perform on many more grain types. A mobile application can be developed to make the end user experience better.