How to Detect Rotten Fruits Using Image Processing in Python?

A guide on detecting rotten fruits using image processing in Python.

Iqra Anwar
9 min readDec 6, 2021
Photo by Jonas Kakaroto on Unsplash

Introduction to Detection of Rotten Fruits(DRF)

Freshness provides one of the essential characteristics for consumers. Consumers prefer fresh fruits rather than rotten ones when it comes to hygiene. An efficient fruit detection system is required to facilitate humans. So, for the easiness of people, this desktop application is proposed, named “Detection of Rotten Fruits (DRF)” by using Artificial Intelligence and Computer Vision. DRF is a desktop application for detecting rottenness in fruits that can be used to indicate the fruits according to their rottenness. Evaluation of fruits relies on the availability of fruit images which are stored in a trained model. This report describes how; through Convolutional Neural Network (CNN) we can find rottenness in fruits. This document will also describe how the system will take input as an image and provide output in the form of accuracy through CNN. This concept will solve the issue of rottenness without using any sensors and extra machines. This idea could be the best-fit solution. It can be used by common people too.

Detection of Rotton Fruits

Fruit Detection Using Image Processing

This report document explains how we can find rottenness in fruits through Artificial Intelligence (AI), Computer Vision (CV), and Convolutional Neural Network (CNN). Nowadays, Artificial Intelligence (AI) is an emerging technology; it is not only part of computing sciences, but it is becoming the basic need of the living population. The vast majority of us know the sentiment of purchasing natural fruits, just to discover that they are effectively ruined. The primary grounds of this project are to bring a system that can easily detect the rottenness of fruits and evaluate the accuracy of the rottenness of fruits through the camera and classify whether the fruit is rotten or fresh according to the accuracy of their rottenness/freshness.

Background Survey of Fruit Detection Using Image Processing

The human eye can detect or analyze the rottenness of fruits, but it is difficult. So, for the easiness of people, we want to develop a desktop application named “Detection of Rotten Fruits (DRF)” by using Artificial Intelligence, CNN, and Computer Vision. The purpose of DRF is to detect and evaluate the accuracy of the rottenness of fruits through the camera and classify them according to the accuracy of their rottenness.

Problem Statement of Fruit Detection

The human eye can detect or analyze the rottenness of fruits, but it is difficult. So, for the easiness of people, we want to develop a desktop application named “Detection of Rotten Fruits” (DRF) by using Artificial Intelligence, CNN, and Computer Vision. The purpose of DRF is to detect and evaluate the accuracy of the rottenness of fruits through images captured through cameras and classify them according to the accuracy of their rottenness.

Motivation

The problem caused by the uncertainty of rottenness of fruits can be overcome by this creative rottenness detector application without any chemical treatment which could damage the nutritional value. We aim to develop this desktop application, especially for the Pakistani nations, as we talk about the developed countries, they already have expensive gadgets for the detection of fruits, and our nation cannot afford those costly gadgets and sensors. Thus, this project will help not only help sellers but also buyers for knowing the rottenness of fruits.

Scope of Fruit Detection Project

The problem caused by the uncertainty of rottenness of fruits can be overcome by this creative rottenness detector application without any chemical treatment which could damage the nutritional value. We aim to develop this desktop application, especially for Pakistan, as we talk about the developed countries, they already have expensive gadgets for the detection of fruits, and our nation cannot afford those costly gadgets and sensors. Thus, this project will help not only help sellers but also buyers for knowing the rottenness of fruits.

What are the Limitations of Fruit Detection?

This study is limited to:

• Evaluation of fruits relies on the availability of fruits images which are stored in the trained model

• New fruits cannot be detected and recognized unless the model is re-trained with the new dataset

• DRF is a desktop application, and it cannot be used on mobile

• For now, it cannot detect multiple fruits at a time

Project Significance

This project has developed an approach for the problem, to find the rottenness of fruits’ & evaluate the accuracy of rottenness in fruits present in the image. By using Convolutional Neural Network (CNN) and CV techniques, DRF provides the accuracy of an image captured via the camera.

RESEARCH STUDY: FRUIT FRESHNESS DETECTION USING CNN

This paper has proposed the Fruit Freshness Detection Using CNN Approach to expand the accuracy of the fruit freshness detection with the help of size, shape, and colour-based techniques by associating Convolution Neural Network (CNN). The framework starts the method by tapping the fruit’s picture. At that point, the picture is moved to the filtration level where the properties like size, shape, and colour of fruit tests are pulled back [1].

Research Paper: Fruits and Vegetables Quality Evaluation Using Computer Vision

The goal of this paper is to give a practically identical overview of computer vision and image processing methods in the food business and furthermore image features, image descriptors, and quality analysis of fruits and vegetables on the basis of colour, shape, size, and surface and the sort of infection present. Wide strategies for example KNN, SVM, Artificial Neural Network (ANN), and Deep Learning/Convolutional Neural Network (CNN) [2]

Research Paper: CNN-Based Model for Fruit Detection and Grading

In this paper, they are taking the instances of apples. Li and M. Zang in 2000 had the option of apple shading with the assistance of hereditary neural organization calculation with 90% precision. Mahjong et al. in 2019 built up the framework which can review apples with the assistance of neural organization and hereditary calculations which give the exactness of 91.67%. The framework will chip away at single shot multi-box discovery which implies that it can review different apples which are available in an edge[3]

LITERATURE REVIEW

Literature View analysis that has been done concerning the challenges faced in the agricultural business in Pakistan and how DRF is going to overcome these challenges and issues. A technical overview is provided that covers the technology of computer vision and CNN. This part attempts to develop a comprehensive analysis of how these visual features are applied to the human perception that can assist to identify at which percentage the fruit has decayed.

Requirement Gathering

We gathered our dataset from Kaggle [16] and then classified it into two classes named Rotten Fruit and Fresh Fruit.

METHODOLOGY

We have been looking for different solutions and CNN is the best-fit solution we have found. Convolutional Neural Networks (CNNs) are a group of Artificial Neural Networks that are applied unremarkably to tasks such as object detection and classification in the image process. It includes multiple layers that assist in classification and detection. The property assesses Convolutional Neural Networks: Propagation time, which is the time it takes for the classification of an image, and precision, which is how precise the prediction is. CNN image classification takes an input image, processes it, and classifies it according to certain categories.

We used the 3-layered CNN model in order to attain better accuracy.

3-layered CNN

EXPERIMENT AND RESULT

Experiment: The dataset for the experiment was collected through Kaggle and It was classified into two classes named Rotten fruits and Fresh fruits. Each class is further divided into two categories as Train and Test. The complete dataset was used for the implementation of the CNN model. We used 67% data for training and 33% for testing.

Result: The proposed idea includes the detection and classification methods by using CNN and Computer Vision techniques. App utilization contains a series of steps. Firstly, the Image can be selected either by capturing through a camera or can directly be selected from the device by using chose from files button. Upon pressing the calculate button result will be shown of that particular image. The result will show that either the fruit is Rotten or Fresh within its accuracy.

CONCLUSION

The main reason to propose this idea is to replace the manual assessment. As we all are well aware of the fact that with the agricultural revolution, People are more concerned about their health and prefer to use fresh fruits for their diets. In the past, sensor-based machines were being used to detect the rottenness of fruits whereas DRF is a desktop application that is going to solve this issue without using any sensors and additional gadgets. This project explores the classification of rotten fruits based on a dataset gathered from Kaggle. So, the conclusion is that the problem regarding the rottenness of fruits can be overcome by this idea. The accuracy and loss curve was generated by using various combinations of hidden layers and models of CNN. This idea can be the best-fit solution because It can be utilized even by common people. The applications in the play store are not providing accurate results but DRF shows the 90% accuracy of the rottenness of fruits, among 10 images every 2 images may not be classified properly.

Code of Detect Rotten Fruits Using Image Processing Python

Github: IqraBaluch

References

[1]. Harsh, K. K. Jha, S. Srivastava, A. Raj, and S. Raghav, “Fruit Freshness Detection Using Cnn Approach,” no. 06, pp. 456–463, 2020.

[2] A. Bhargava and A. Bansal, “Fruits and vegetables quality evaluation using computer vision: A review,” J. King Saud Univ. — Comput. Inf. Sci., 2018, doi: 10.1016/j.jksuci.2018.06.002.

[3] M. K. Singh, “REVIEW PAPER ON CNN BASED COMPUTER VISION,” no. 08, pp. 1367–1371, 2020.

[4] Z. Du, X. Zeng, X. Li, X. Ding, J. Cao, and W. Jiang, “Recent advances in imaging techniques for bruise detection in fruits and vegetables,” Trends Food Sci. Technol., vol. 99, no. June 2019, pp. 133–141, 2020, doi: 10.1016/j.tifs.2020.02.024.

[5] T. Nishi, S. Kurogi, and K. Matsuo, “Grading fruits and vegetables using RGB-D images and convolutional neural network,” 2017 IEEE Symp. Ser. Comput. Intell. SSCI 2017 — Proc., vol. 2018- Janua, pp. 1–6, 2018, doi: 10.1109/SSCI.2017.8285278.

[6] F. López Laso, “Diseases Detection in Citrus Fruits Using Convolutional Neural Networks,” p. 68, 2018, [Online]. Available: http://openaccess.uoc.edu/webapps/o2/bitstream/1

0609/81449/5/flopez215TFM0618memoria.pdf. [7] D. K. Soni, N. Sharma, I. Kaushik, and B. Bhushan, “Producing energy using blind man stick,” Proc. — 2020 IEEE 9th Int. Conf. Commun. Syst. Netw. Technol. CSNT 2020, pp. 173–178, 2020, doi: 10.1109/CSNT48778.2020.9115766. [8] K. Kuchangi and J. Prakash, “Spoilage Detection in Raspberry Fruit Based on Spectral Imaging Using Convolutional Neural Networks,” p. 75, 2018.

[9] K. Roy, S. S. Chaudhuri, S. Bhattacharjee, S. Manna, and T. Chakraborty, “Segmentation techniques for rotten fruit detection,” 2019 Int. Conf. Opto-Electronics Appl. Opt. Optronix 2019, pp. 1–4, 2019, doi: 10.1109/OPTRONIX.2019.8862367.

[10] J. Chen et al., “Flexible and Adhesive Surface Enhance Raman Scattering Active Tape for Rapid Detection of Pesticide Residues in Fruits and Vegetables,” Anal. Chem., vol. 88, no. 4, pp. 2149–2155, 2016, doi: 10.1021/acs.analchem.5b03735.

[11] F. Sinesio, A. Saba, M. Peparaio, E. Saggia Civitelli, F. Paoletti, and E. Moneta, “Capturing consumer perception of vegetable freshness in a simulated real-life taste situation,” Food Res. Int., vol. 105, no. July 2017, pp. 764–771, 2018, doi: 10.1016/j.foodres.2017.11.073.

[12] O. Kemiklioglu, Emine; Ozen, “Design of a

Sensor to Detect Fruit Freshness,” vol. 4, no. 1, pp. 1–6, 2018.

[13] S. Kammar, S. . Kulkarni, U. . Kulkarni, R. K, and R. Hegadi, “Detection of freshness of fruits using electrical method,” Int. J. Eng. Trends Technol., vol. 23, no. 2, pp. 90–92, 2015, doi: 10.14445/22315381/ijett-v23p217.

[14] D. El Khaled, N. Novas, J. A. Gazquez, R. M. Garcia, and F. Manzano-Agugliaro, Fruit and vegetable quality assessment via dielectric sensing, vol. 15, no. 7. 2015.

[15] Suganya, “a Fruit Quality Inspection Sytem Using Faster Region Convolutional,” pp. 6717–6720, 2019.

[16] https://www.kaggle.com/sriramr/fruits-fresh-and rotten-for-classification

--

--

Iqra Anwar

Future Data Scientist on a mission to turn complex data into impactful insights. Passionate about AI, ML, and building solutions that shape the future.