Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

DIGITAL

IMAGE
PROCESSING
FRUIT DETECTION REPORT

Prepared by:MAHESH
2021UGECE36
02

ABSTRACT
A new method for classifying fruits using image processing
technique is proposed in this paper. The data set used had 70
apple images and 70 banana images for training and 25 images
of apple and 25 images of bananas for testing. RGB image was
first converted to HSI image. Then by using Otsu's thresholding
method region of interest was segmented by taking into account
only the HUE component image of the HSI image. Later, after
background subtraction, a total of 36 statistical and texture
features were extracted with the help of the coefficients
obtained by applying wavelet transformation on the segmented
image using Haar filter. Extracted features were given as inputs
to a SVM classifier to classify the test images as apples and
bananas. As KNN classification method did not give 100%
accuracy while classification SVM classification method was
used. 140 sample images of apples and bananas were used for
training and 25 images of banana and 25 images of apples were
used for testing the proposed algorithm. The proposed algorithm
gave 100% accuracy rate.
02

Introduction
In recent years, advanced agricultural automation has increased
productivity by reducing production costs and manual labor
while increasing yield and quality [1]. However, many tasks are
still completed manually and limitations exist in automating tasks
on a large scale.
The main motivation and uses for this project are:
• Decrease food waste by identifying rotten fruit in a batch
at an early stage to prevent spreading to other fruits during
transportation or storage. Can be employed at large
agricultural scales and also at local grocery stores when
receiving new fruit stock.
• Increase efficiency at the agricultural level by automating
the prediction of fruit states and therefore optimizing
harvests • Identifying fruit with a network can ease
cashiers’ jobs when processing fruit as currently cashiers
need to remember serial codes to input into the register
(minimizing human computer interactions)
03

LITERATURE
SURVEY
Before the recent machine learning (ML) advances, the main
approach for fruit state identification was with OpenCV and
image segmentation, which produced decent results but has
limitations. Recently ML approaches for quality of fruit
identification have been investigated by many researchers,
resulting in papers regarding feature analysis, architecture
choice, and reframing fruit feature detection as an image
segmentation problem (i.e fruit vs. background) [5-7]. Upon
further research, we have found that the use of a CNN model
outperforms non ML computer vision approaches

Fruit identification using ML has also been explored by


agricultural companies. For example, SeeTree is a leading
agri-tech company that uses deep learning to help robots
optimize the harvesting process [9]. They implemented drones
to automatically identify ripeness of oranges on trees as
shown below, and overcame issues of small datasets and
noise in photos.
03 PROPOSED
METHODOLOGY
03

Illustration/Figure
05

RESULTS AND
DISCUSSIONS
05

RESULTS AND
DISCUSSIONS
05
CONCLUSION
05
CODE

import numpy as np
from keras.preprocessing.image import load_img,
img_to_array
from keras.models import load_model
from flask import Flask, jsonify, request

model = load_model('FV.h5')

labels = {0: 'apple', 1: 'banana', 2: 'beetroot', 3: 'bell


pepper', 4: 'cabbage', 5: 'capsicum', 6: 'carrot',
7: 'cauliflower', 8: 'chilli pepper', 9: 'corn', 10:
'cucumber', 11: 'eggplant', 12: 'garlic', 13: 'ginger',
14: 'grapes', 15: 'jalepeno', 16: 'kiwi', 17: 'lemon', 18:
'lettuce',
19: 'mango', 20: 'onion', 21: 'orange', 22: 'paprika',
23: 'pear', 24: 'peas', 25: 'pineapple',
26: 'pomegranate', 27: 'potato', 28: 'raddish', 29:
'soy beans', 30: 'spinach', 31: 'sweetcorn',
32: 'sweetpotato', 33: 'tomato', 34: 'turnip', 35:
'watermelon'}
05
CODE
def prepare_image(img_path):
img = load_img(img_path, target_size=(224, 224, 3))
img = img_to_array(img)
img = img / 255
img = np.expand_dims(img, [0])
answer = model.predict(img)
y_class = answer.argmax(axis=-1)
print(y_class)
y = " ".join(str(x) for x in y_class)
y = int(y)
res = labels[y]
print(res)
return res.capitalize()

app = Flask(_name_)

@app.route('/predict', methods=['POST'])
def infer_image():
if 'file' not in request.files:
return jsonify(error="Please try again. The Image doesn't exist")

file = request.files.get('file')
img_bytes = file.read()
img_path = "./upload_images/test.jpg"
with open(img_path, "wb") as img:
img.write(img_bytes)
result = prepare_image(img_path)
return jsonify(prediction=result)

if _name_ == '_main_':
app.run(debug=False, host='0.0.0.0'
05
REFERENCES

https://www.bing.com/search?
pglt=41&q=python+online+compiler&cvid=54a743eb079
045c3a7dc56bb3db12672&aqs=edge.2.69i57j0l8.6491j0
j1&FORM=ANNTA1&PC=HCTS

https://codewithcurious.com/projects/

https://stackoverflow.com/questions/46610689/how-
to-import-cv2-in-python3

You might also like