# Quality and Defect Inspection of Green Coffee Beans Using a Computer Vision System
## 1 Introduction  
More than two billion cups of coffee are consumed worldwide every day, which makes coffee the most important beverage commodity traded in world markets [1]. Thus, coffee consumption and the demand for high-quality coffee beans have been increasing over the years [2]. Important features in the selection process by physical appearance include color, morphology, shape and size [3]. Therefore, evaluating the quality of green coffee beans has become an important issue for market price, storage stability and general consumer acceptance. In some food industries, two techniques are usually implemented to identify and select coffee beans: manual and mechanical selection. The first technique is performed by personnel making a visual inspection of beans and is used to identify specific features of the beans and to choose the best ones; however, non-uniform selection can easily result from long working hours, a lack of training and workers' attitudes [4]. Furthermore, this manual procedure takes considerable time and can be inefficient when many beans are to be evaluated. In the second technique, mechanical sorting machines are used to grade the beans based on their size; however, these machines are not able to evaluate physical appearance and they could potentially damage the beans to their invasive sorting procedure [5]. Therefore, neither technique provides a good option to select the best quality of coffee beans, meaning that a more modern approach is required. Computer vision algorithms are a better option to classify and select food products. They automatically extract and analyze useful information from a specific object present in an image. In general, a computer vision algorithm for defect detection implies two main stages. The first one consists of an accurate segmentation of the objects from the background and the second one consists of an accurate defect identification by extracting and comparing the physical features of the objects. This technique has been widely used to evaluate the quality of fruits and vegetables [6; 7]. As reported by many authors, computer vision systems have been used for potato quality grading [4; 8], strawberry industrial classification [9], soybean quality evaluation [10], papaya disease recognition [11], apple sorting and quality inspection [12], classification of pepper seeds [13], quality evaluation in fresh-cut lettuce [14], grading of fried figs [5] and many other food products as discussed in [15]. In [16], the authors present an automatic leaf image classification system for sunflower crops using neural networks with selected features. In [17], the authors developed an ant colony optimization algorithm for the classification of plant species by inspecting their leaves. In [18], the authors present a growth stage detection system for apples and in [19] the authors developed a computer vision system for quality inspection in blueberries. Thus, this paper deals with this technique that is practical in identifying physical characteristics and classifying a large amount of food products. Only a few machine vision systems have been developed for the classification, defect detection, quality inspection or grading of coffee beans. In [20], a computer vision system was constructed with the objective of classifying coffee beans according to their color. Artificial neural network and Bayes classifier were used to achieve this purpose. Only one trait, color, was used to classify the coffee beans and detect the defect types is this paper, which restricts the accurate functioning and classification of the system. The present manuscript considers four bean traits for defect-type inspection, which makes it more reliable and allows to identify more defect types in coffee beans. In [21], an artificial neural network is proposed with the purpose of classifying coffee beans. Two algorithms were developed, one to determine ripeness of the coffee bean based on its color and one to detect the presence of the \"broca\" plague.