<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>E. M. T. Caballero, A. M. R. Duke, Implementation of artificial neural networks
using NVIDIA digits and OpenCV for cofee rust detection, in:</journal-title>
      </journal-title-group>
      <issn pub-type="ppub">1613-0073</issn>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.1109/ICACTM.2019</article-id>
      <title-group>
        <article-title>Control Process of Cocoa Beans Through Computer Vision: Concept</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Rodrigo Espinal</string-name>
          <email>rodriespinal@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jóse Luis Ordoñez-Avila</string-name>
          <email>ez@unitec.edu</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Angie Carolina Santos Fernández</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maria Elena Perdomo</string-name>
          <email>maria_perdomo@unitec.edu</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Engineering, Central American University of Technology</institution>
          ,
          <addr-line>(Unitec), San Pedro Sula 21102</addr-line>
          ,
          <country country="HN">Honduras</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2020</year>
      </pub-date>
      <volume>5</volume>
      <issue>11</issue>
      <fpage>297</fpage>
      <lpage>303</lpage>
      <abstract>
        <p>Cocoa beans are often manually classified according to their quality status, a process that can be timeconsuming and prone to human error. The aim of this research was the development of a data acquisition system using artificial vision for the elaboration of a difuse neural network. This research includes a review of cocoa processes, quality tests for beans, open-source computer vision libraries, and adaptive neuro-fuzzy systems. The algorithm was tested using an adaptive neuro-fuzzy inference system (ANFIS) with a fuzzy interface in the MATLAB mathematical application. The Gaussian membership function was used and the network training consisted of 500 epochs. In the test, 24 beans were evaluated and 22 were correctly classified, resulting in an accuracy rate and an F1 score of 92%. These results suggests that our approach using computer vision is a viable method for classifying cocoa beans their physical defects or deformities.</p>
      </abstract>
      <kwd-group>
        <kwd>computer vision</kwd>
        <kwd>algorithm</kwd>
        <kwd>neuro-fuzzy networks</kwd>
        <kwd>cocoa beans</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>CEUR
ceur-ws.org</p>
    </sec>
    <sec id="sec-2">
      <title>1. Introduction</title>
      <p>There are several procedures currently used to assess the quality of cocoa beans. One of the
methods is known as the cut-test, which is based on color changes registered during fermentation.
This test is used to determine if the bean is properly fermented and to ensure its quality [1].
Another method is a visual test where the person in charge observes the outside of the bean for
physical defects and determines its quality as good or bad. However, these methods are quite
subjective as they depend on the farmer’s experience and judgment. Cocoa processing involves
several stages, including harvesting, fermentation, drying, and storage. During harvesting, ripe
cobs are removed from trees and opened to extract the moist cocoa beans [2]. Fermentation
helps eliminate slime or mucilage and is the stage where biochemical transformations occur
that reduce bitterness and trigger internal reactions, which modifies the composition of the
nEvelop-O
(M. E. Perdomo)
CEUR
Workshop
Proceedings
cocoa beans and promotes the formation of aroma and flavor precursors [ 3]. Finally, during the
drying stage, humidity is reduced, and the formation of flavor and aroma is completed [ 4].</p>
      <p>In this study, we proposed a computer vision algorithm for feature extraction of cacao bean
images and an artificial neural fuzzy inference system to classify the cocoa beans according to
their quality. Fuzzy logic, proposed by Zadeh in 1965 [5], is a popular computing framework
that uses fuzzy set theory, fuzzy if-then rules, and fuzzy reasoning. By integrating the fuzzy
systems with ANN models, an efective tool is obtained that takes advantage of the learning
characteristics of the ANN models and performs equally well as an inference fuzzy model. As
proposed by Jang [6], an artificial neural fuzzy inference system takes inputs and fuzzifies them
using membership functions. The objective of this research was to develop a computer vision
algorithm and an artificial neural fuzzy inference system that helps in the quality control process
of cocoa beans by classifying them based on their status. The first section of this experiment
is the Method, where the methodology of this experiment is explained. The second section
describes the feature extraction of the cocoa bean’s with the algorithm, including data collection
and information. The third section explains the development and training of the artificial neural
fuzzy inference system model. In the final section, the model is evaluated, and the results are
analyzed.</p>
      <sec id="sec-2-1">
        <title>1.1. State of the Art</title>
        <p>In the cacao sector, there are numerous investigations regarding the quality of cacao beans.
Bueno [7] stated that the demand for high-quality cacao products is expected to rise due to
advances in technology. Computer vision has made great strides [8] in the agricultural sector.
Computer vision solutions can help sort produce by weight, color, size, maturity, and identify
defects, among other factors [9]. Combining multivariate statistics with image analysis has
become a dominant tool to deal with several problems in the food sector. Multiple techniques are
used for classifying cocoa beans by their quality. One such technique involves using a multiclass
ensemble and least-squares support vector machine based on color features, as shown in the
work of [1]. Feature extraction is an example of artificial intelligence that can be used to reduce
the amount of data under processing while still maintaining the fundamental data [10]. In a
study by [11], feature extraction was used for cocoa bean digital image classification prediction
for smart farming applications. Additionally, [12] extracted and analyzed physical features of
cocoa beans using image processing and a pre-trained neural network. In [13], an SVM-classifier
was used to classify cocoa beans by their fermentation degree. Artificial neural networks (ANNs)
have been used in various works, such as those of [14] and [15], as instruments to model
nonlinear trends within the data where there are complicated relationships to be modeled. ANNs
are useful when the theoretical relationship between input and output variables is lacking,
such as in the case of fermentation index and color of cocoa beans in [14]. Backpropagation
and Principal Component Analysis (PCA) Artificial Neural Networks were used in the work of
[15] to classify cocoa beans by their quality. Moreover, in [9], image analysis combined with a
random forest algorithm was used to classify cocoa beans by the grade of fermentation.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>2. Method and Data</title>
      <p>This experiment was conducted in three stages: data collection and feature extraction, algorithm
and adaptive neuro-fuzzy inference system development, and evaluation. In the data collection
stage, we gathered photographs of cocoa beans with and without physical deformations from the
Association of Agro-forestry Producers of the Choloma River basin. A total of 198 photographs
were collected and grouped based on the bean’s defects or deformations. While most of the
beans were of good quality, some had defects or deformations such as flat, united, broken, or
sprouted cocoa beans.</p>
      <p>During the algorithm development stage, we used a statistical sample of 174 cocoa beans to
collect, analyze, and train an adaptive neuro-fuzzy inference system. The aim was to predict
the quality status of the cocoa beans based on their contour area, surface area, and perimeter.
    (  ) =
    (  ) =
   =</p>
      <p>+</p>
      <p>+</p>
      <p>+  
   =
 =</p>
      <p>+</p>
      <p>+  
 1 Score = 2 ∗    ∗</p>
      <p>+ 
Specifically, the adaptive neuro-fuzzy inference system was designed to predict whether the
beans were of good or bad quality, meaning they had any of the deformations mentioned earlier.
We used the information gathered from the statistical sample to make the prediction.</p>
      <p>
        In the evaluation phase, we analyzed the results of the predictions using four categories: true
positives (correctly evaluated beans), true negatives (correctly evaluated beans), false positives
(incorrectly evaluated beans), and false negatives (incorrectly evaluated beans). We used these
results to calculate several metrics, including the model’s accuracy (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ), sensitivity (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ), specificity
(
        <xref ref-type="bibr" rid="ref3">3</xref>
        ), false positive rate (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ), and F1-Score (
        <xref ref-type="bibr" rid="ref5 ref6 ref7">5-7</xref>
        ), using the method described by [16].
    =   (
        <xref ref-type="bibr" rid="ref4">4</xref>
        )
  +
      </p>
      <p>
        To obtain the F1 score, we calculated precision and recall and passed them to the formula
described in [16] to evaluate the model’s performance. Finally, we evaluated the performance
and accuracy of the neuro-fuzzy inference system using 24 out-of-sample observations.
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        )
(
        <xref ref-type="bibr" rid="ref3">3</xref>
        )
(
        <xref ref-type="bibr" rid="ref5">5</xref>
        )
(
        <xref ref-type="bibr" rid="ref6">6</xref>
        )
(
        <xref ref-type="bibr" rid="ref7">7</xref>
        )
      </p>
      <sec id="sec-3-1">
        <title>2.1. Data Collection</title>
        <p>The data collection process for this experiment was a crucial step in ensuring the accuracy
and reliability of the results. To gather a representative sample of cocoa beans, we visited the
Association of Agroforestry Producers of the Choloma River basin, a group of farmers who
specialize in producing high-quality cacao beans. With the cooperation of the farmers, we were
able to collect a total of 198 photographs of cocoa beans, carefully selected to represent both
good quality and poor quality beans. To ensure consistency in our data collection process, all
photographs were taken at the same distance and under the same lighting conditions, minimizing
any potential sources of variability that could afect the quality of the images. Furthermore, the
poor-quality beans were classified based on their physical deformations, which included flat
cocoa beans, multiple united cocoa beans, broken cocoa beans, and sprouted cocoa beans, as
shown in Figure 1. By classifying the poor-quality beans in this way, we were able to capture a
range of common defects that can afect the quality of cocoa beans.</p>
      </sec>
      <sec id="sec-3-2">
        <title>2.2. Data Preprocessing</title>
        <p>During the data preprocessing step, we aimed to ensure that the extracted features were accurate
and reliable. To achieve this, we performed several operations on the collected images. Firstly,
we resized the images to a uniform size to facilitate their analysis. Then, we applied several
iflters, including gray-scale, threshold, and median blur, to enhance the image quality and
facilitate feature extraction. We also used the Canny edge detection algorithm to accurately
detect the contour of the cocoa beans. This allowed us to extract the contour area, surface area,
and perimeter of each bean using the OpenCV functions cv.contourArea, cv.arcLength, and
np.histogram, as shown in Figure 2. These features were used as inputs to the neuro-fuzzy
interface, which was designed to classify the beans as either good or bad based on their physical
deformations. To train the neuro-fuzzy interface, we used a statistical finite sample of 174 beans,
which were representative of the population of cocoa beans in the Choloma River basin. This
dataset was used to calibrate the interface and to ensure that it could accurately predict the
quality status of the beans.</p>
      </sec>
      <sec id="sec-3-3">
        <title>2.3. Artificial Neural Fuzzy Inference System</title>
        <p>
          After the data preprocessing step, the extracted features were utilized to develop an artificial
neural fuzzy inference system. This system was designed to classify the cocoa beans based on
their physical deformations as either good quality or bad quality. The fuzzy plugin in Matlab
was used to implement this system. To train the ANFIS system, a set of input and output vectors
were utilized. These vectors were used to find the premise parameters for the membership
functions. In an artificial neural fuzzy inference system, the membership function is used to
represent the degree to which an input value belongs to a particular class. The Gaussian member
function was used for this system. It has a smooth curve and utilizes only two parameters: c
for locating center and σ for determining the width of the curve, as expressed mathematically
in (
          <xref ref-type="bibr" rid="ref8">8</xref>
          ). The fuzzy neural network was trained for 500 epochs to obtain the network shown in
Figure 3. Each input variable has its own set of membership functions, one for each class. These
membership functions are often graphically represented, with the x-axis representing the input
value and the y-axis representing the membership degree.
        </p>
        <p>(;  , ) =
 −(−) 2
2 2</p>
        <p>
          The ANFIS system generated 27 rules for handling quantitative formulation between contour
area, surface area, and bean perimeter in predicting the quality of cocoa beans. The relation
between the inputs and the outputs is shown in Figure 4. Overall, the artificial neural fuzzy
inference system was trained to predict whether the beans were of good quality or bad quality,
using the information gathered from the statistical sample.
(
          <xref ref-type="bibr" rid="ref8">8</xref>
          )
        </p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>3. Results</title>
      <p>To evaluate the performance of the artificial neural fuzzy inference system models, a preliminary
test was conducted using 24 cocoa beans that were not included in the training sample. The
Gaussian membership function was found to perform optimally, correctly classifying 14 beans
as positive (good) and 10 as negative (bad). Out of the 14 good beans, 12 were correctly identified
as true positives (TP), while all 10 bad beans were correctly identified as true negatives (TN).
The model produced 2 false positives and 0 false negatives. A summary of these results can be
found in Table I and Figure 5.</p>
      <p>The model achieved an F1-Score of 92%, demonstrating its ability to accurately classify cocoa
beans as either free of defects or with defects. Table II provides a summary of the evaluation
results.</p>
    </sec>
    <sec id="sec-5">
      <title>4. Conclusions</title>
      <p>A computer vision algorithm was developed to classify cocoa beans according to their quality
based on physical defects. The algorithm uses a classification artificial neural fuzzy
inference system to calculate bean physical characteristics such as contour area, surface area, and
perimeter, and then uses this information to classify the beans as either free of defects or with
defects. The algorithm was found to have an accuracy level of 92%, a sensitivity score of 100%,
a specificity score of 83% and an F1-Score of 92%. These results compare very well to previous
studies on defect detection in agro-products in Honduras, including the use of a neural network
for detecting red ring pest in oil palm [17], which had an accuracy of 98%; the identification of
coral beef disease using computer vision [18], which had an accuracy of 94%; and the detection
of cofee rust [ 19], which had an accuracy of 96%. This diference is because the authors used a
neural network to make their applications.</p>
      <p>One advantage of this study is that it can be implemented at a low cost, as it only requires
a phone camera to take pictures of the cocoa beans. Another advantage is that it eliminates
subjectivity in the classification of cocoa beans, as the decision is based on concrete and
enumerable data rather than human perception. Future work could focus on improving the
accuracy of the algorithm by incorporating more training data and fine-tuning the parameters
of the fuzzy neural network, or by exploring other machine learning techniques and considering
additional factors that may afect cocoa bean quality. By automating this process, we aim to
optimize time and enhance the quality of cocoa bean classification.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Adhitya</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Lawi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Hartono</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Mursalin</surname>
          </string-name>
          ,
          <article-title>Cocoa Beans Digital Image Classification Based On Color Features using Multiclass Ensemble Least-Squares Support Vector Machine</article-title>
          , ???? doi:10.4108/eai.20-
          <fpage>1</fpage>
          -
          <year>2018</year>
          .2281929.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>G. A. R.</given-names>
            <surname>Wood</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. A.</given-names>
            <surname>Lass</surname>
          </string-name>
          , Cocoa, Tropical agriculture series, 4th ed., repr. with corrections ed.,
          <string-name>
            <surname>Longman</surname>
            <given-names>Scientific</given-names>
          </string-name>
          &amp; Technical ; Wiley, ????
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>M. C.</given-names>
            <surname>López-Navarrete</surname>
          </string-name>
          ,
          <article-title>El proceso de fermentación del CACAO (theobroma cacao l</article-title>
          .)
          <volume>4</volume>
          (????). URL: https://revista-agroproductividad.org/index.php/agroproductividad/article/view/572, number:
          <fpage>1</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>J.</given-names>
            <surname>Nogales</surname>
          </string-name>
          , L. Graziani de Fariñas, L. Ortiz de Bertorelli,
          <article-title>Cambios físicos y químicos durante el secado al sol del grano de cacao fermentado en dos diseños</article-title>
          de cajones de madera¹
          <volume>56</volume>
          (????)
          <fpage>5</fpage>
          -
          <lpage>20</lpage>
          . URL: http://ve.scielo.org/scielo.php
          <article-title>?script=sci_abstract&amp;pid= S0002-192X2006000100001&amp;lng=es&amp;nrm=iso&amp;tlng=es, number: 1 Publisher: Instituto Nacional de Investigaciones Agrícolas (INIA).</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>L. A.</given-names>
            <surname>Zadeh</surname>
          </string-name>
          , Fuzzy sets
          <volume>8</volume>
          (????)
          <fpage>338</fpage>
          -
          <lpage>353</lpage>
          . URL: https://www.sciencedirect.com/science/ article/pii/S001999586590241X. doi:
          <volume>10</volume>
          .1016/S0019-
          <volume>9958</volume>
          (
          <issue>65</issue>
          )
          <fpage>90241</fpage>
          -
          <lpage>X</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.-S.</given-names>
            <surname>Jang</surname>
          </string-name>
          ,
          <article-title>ANFIS: adaptive-network-based fuzzy inference system 23 (?</article-title>
          ???)
          <fpage>665</fpage>
          -
          <lpage>685</lpage>
          . doi:
          <volume>10</volume>
          .1109/21.256541, conference Name:
          <source>IEEE Transactions on Systems, Man, and Cybernetics.</source>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>G. E.</given-names>
            <surname>Bueno</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K. A.</given-names>
            <surname>Valenzuela</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E. R.</given-names>
            <surname>Arboleda</surname>
          </string-name>
          ,
          <article-title>Maturity classification of cacao through spectrogram and convolutional neural network 8 (?</article-title>
          ???)
          <fpage>228</fpage>
          -
          <lpage>233</lpage>
          . URL: https://jtsiskom.undip. ac.id/index.php/jtsiskom/article/view/13733. doi:
          <volume>10</volume>
          .14710/jtsiskom.
          <year>2020</year>
          .
          <volume>13733</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>D. K.</given-names>
            <surname>Shetty</surname>
          </string-name>
          ,
          <string-name>
            <given-names>U.</given-names>
            <surname>Dinesh Acharya</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Malarout</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Gopakumar</surname>
          </string-name>
          ,
          <string-name>
            <surname>P. P.J.,</surname>
          </string-name>
          <article-title>A review of application</article-title>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>