# Quality and Defect Inspection of Green Coffee Beans Using a Computer Vision System
## 1 Introduction
Only two defect types are considered in this manuscript; broken and very long berry beans were not taken into account for this paper. CIEAB Color space was used in two previous papers for color recognition; however, in [22], authors used hue-saturation value color representation and a hardware system to identify coffee fruits in four different maturation stages. In [23], the development of a system for the classification of coffee beans based on their ripeness is presented where the authors use block-based neural network and implement it with reconfigurable hardware, such as field programmable gate array (FPGAs). The authors in these papers only consider the color to grade the grain quality by its maturation stages, ignoring important defects such as small, very long berry or broken beans that are considered in the present manuscript and that are not detected by maturation stages identification. In addition, some conferences have reported machine vision systems for the classification of green coffee beans [24], for characterizing coffee beans from different towns [25], for automatic classification of defects in green coffee beans [26], for coffee black beans identification [27] and for the recognition of defects in coffee beans [28]. A low accuracy for the recognition of defects in coffee beans is presented in [28] and a low accuracy for the inspection of fade and broken beans is presented in [24]. Furthermore, in [27] only black beans are identified. Despite key technology towards the development of a machine vision for coffee beans inspection, few techniques have been presented to select green coffee beans and consider several physical characteristics for quality identification. The novelty of the present paper in this research field refers to the application of the presented techniques in the problem of inspection of green coffee beans. The techniques presented include size, morphology, shape and color inspection of the coffee beans for accurate quality and defects inspection, as well as a high accuracy inspection with regard to the bibliography. Thus, this paper presents an artificial vision system for green coffee beans quality and defects inspection. The system uses computer vision tools for image processing, the \(k\)-nearest neighbor algorithm for classification and an Arduino Mega board based on the ATmega 2560 (MicrochipTechnology, Chandler, AZ, USA) as a controller for external devices, such as an LCD screen (user interface). The development of the system implies different stages. The image acquisition was carefully carried out using an accurate illumination source. The image processing and the supervised learning algorithms were implemented using MATLAB. Finally, the system was tested to prove the quality of the green coffee bean defects inspection. Therefore, the main contributions of the paper are focused on obtaining:  
* An accurate and efficient machine vision integrated with an Arduino board for automatic quality and defects inspection of green coffee beans. * A source code programmed in MATLAB to process any amount of green coffee beans present in the images. * A statistical analysis of the quality and defects of green coffee beans to identify the best coffee beans with different physical characteristics. The rest of the paper is divided into four sections. Section 2 presents the background of the research topic and Section 3 presents the materials, methods and procedures carried out to build the system. Section 4 describes the test, the results, the analysis and discussion, and Section 5 concludes.