/Computer-Vision-Based-Orange-Grader

An automated computer vision based orange grading system developed in Python with OpenCV and PyQt5.

Primary LanguagePythonMIT LicenseMIT

Computer-Vision-Based-Orange-Grader

In order to run this program, ensure you have Python 3, OpenCV, and PyQt5 installed on your computer. Then, download the source files, navigate to where you saved them in the terminal and run the 'main.py' file with 'python3 main.py'.

I have included six images in this repository which totals three specimens as an image is taken of each side of the fruit. If you would like to test your own images, save them to the 'images' folder, convert them to JPEG's, and ensure the file name is 13 characters long including the '.jpg' extension.

The Qt Stylesheet (QSS) that has been used was created by zypher606 and is available here: https://github.com/martinrotter/qt-material-stylesheet/blob/master/stylesheets/material-blue.qss

This project was completed as a part of my third year university course in which we were required to undertake a personal investigation within the realm of physical computing. Within this module both an academic report and supporting artefact was created. Right from the start of hearing about this module I was keen to pursue a topic related to computer vision as I feel it is a very applicable and fast growing industry, and is also a subject I have been very passionate about for the past year or so. Initially, I was looking into topics such as facial and emotional rcognition, traffic management and control, as well as various applications within agriculture. After much deliberation it was decided that I would pursue automated produce grading, in particular, the automated defect detection and grading of oranges. The full title for the project I have completed is; "The Effectiveness of a Colour Based Computer Vision Fruit Grading System in Comparison to those which Employ the Use of Neural Networks and Machine Learning Algorithms". The artefact I have created to support this investigation is a desktop application which takes two images of an orange as input, extract the defects, and then grades the oranges appropriately. After testing, it was found to be just under 60% accurate at grading the fruit.

The application was developed using a combinatin of Python, PyQt, and OpenCV. The user is displayed with an interface, which features six containers for the images and three buttons. The first two buttons allow the user to navigate their computers file system in order to chose an image file of an orange they wish to test. Upon pressing the grade specimen button, the images will be analysed and the features will be extracted. This is where OpenCV comes in. An HSV colour range was defined as a NumPy array that covers the colour orange, anything outside of this range will be converted to black and removed from the image. The majority of the defects that oranges have are discolourations, thus this was deemed an effective way of detecting defects. Once this image segmentation has occured, OpenCV's contouring functions are employed which allow all the areas in black on the inside of the orange are highlighted, counted, and have their area calculated. The total area of these defects is compared to total area of the specimen and the percentage that is damaaged is calculated. It is this figure that is used to grade the orange. The oranges themselves were split into three cateogires prior to grading; A, B, and C. A refers to specimens that have little or no defects, B refers to specimens with some defects, whereas C refers to specimens that have a large amount of the skin defected.