# Quality and Defect Inspection of Green Coffee Beans Using a Computer Vision System
## 4 Results and Analysis  
The experimental set-up is shown in Figure 10. A printed circuit board was designed to carry out the machine vision process. The printed circuit was designed to be interfaced directly with the Arduino board. This makes it a compact, portable and good-looking set-up. The system requires 96 milliseconds to acquire the image, process it and give the resultant quality of the coffee beans. This allows us to inspect even 625 coffee images per minute.  
Similar to Figures 9 and 11-16 show the 2D plotting of the four features of the coffee beans chosen to be evaluated and used in the algorithm. 2D plots of the features allow us to better understand the results and the functioning of the \(k\)-nearest neighbor algorithm.  
Figure 9: 3D plot for the \(k\)-nearest neighbor algorithm using the training set.  
Figure 11: 2D plot of roundness and color features used for the \(k\)-nearest neighbor algorithm using the training set.  
Figure 12: 2D plot of area and color features used for the \(k\)-nearest neighbor algorithm using the training set.  
Figure 10: Experimental set-up.  
Figure 14: 2D plot of eccentricity and color features used for the \(k\)-nearest neighbor algorithm using the training set.  
Figure 13: 2D plot of area and roundness features used for the \(k\)-nearest neighbor algorithm using the training set.  
Figure 15: 2D plot of eccentricity and roundness features used for the \(k\)-nearest neighbor algorithm using the training set.  
Those bad coffee beans (red dots) plotted in Figure 11 with a color feature greater than 0.3 are the coffee beans that present the sour and black defect type. The coffee beans with the sour defect type bring a high color feature; however, the black beans bring an even higher color feature that allow to easily distinguish the coffee beans with these two defect types from the others. Because a queried coffee bean with these kind of defect types would be plotted far from the good coffee beans' location due to its high color feature, its quality is expected to be lower; that is, these kinds of defects affect the quality percentage more than the other defect types shown in Figure 1. This is consistent with the literature because black and sour coffee beans are very prejudicial for the coffee taste [38].  
Those beans in Figure 11 with roundness lower than 0.3 represent the very long berry and/or broken beans that have a low value for the roundness feature. This allows us to easily distinguish the very long berry and/or broken beans from the others. Those bad coffee beans (red dots) plotted in Figure 12 with area feature lower than 0.5 represent the coffee beans that are very small. Then, this allows to easily distinguish the coffee beans with the small defect type from the others. Figures 11-16 help us illustrate this.  
The very long berry coffee beans present an eccentricity greater than 0.75 due to their long shape, which makes it easier to distinguish the very long berry beans from the others, even from the broken beans. Figures 14-16 illustrate this.  
As very long berry coffee beans and broken beans present a similar roundness feature value, eccentricity was proposed to better differentiate between them. Figure 15 shows the 2D roundness and eccentricity features plot. Very long berry beans present a roundness lower than 0.3. However, very long berry coffee beans present a high eccentricity that set them apart from all the coffee beans.  
It can be seen that the good coffee beans (green dots) are always close to one another in the 2D plots. This is because a high-quality coffee bean must fulfil the correct features values to be considered a good coffee bean.  
A total of 444 coffee beans were used to test the accuracy of the machine vision. An accuracy percentage is found for the quality and defect type inspection, developing a confusion matrix. The accuracy percentage is also tested using different \(k\)-nearest neighbors in the classification algorithm. Finally, the standard deviation of the computed accuracy was tested as well.