Machine Learning and Queuing Algorithm Integration for Real-Time Citrus Size Classification on an Industrial Sorting Machine
Abstract
1. Introduction
- A lightweight lemon classification model (LCM) by size implemented on an SBC in real time.
- A peduncle detection model (PDM) whose results generate a feature that is useful for the lemon size classification algorithm. These features, in combination with other geometric features, are used to train the LCM. The inference time for the lemon peduncle detection is low enough to be executed in real time as part of the feature extraction process.
- An image processing algorithm that extracts features from lemon images, which a trained model evaluates.
- The queuing algorithm is executable on an 8-bit microcontroller, which manages the activation times of the ejector solenoids that send the lemons to the appropriate chutes.
- The integration of the above modules into a lemon classification system in an existing industrial lemon sorting system. Due to its modularity, this system is easy to maintain and cost-effective.
2. Materials and Methods
2.1. Analysis of Existing Lemon Classifier Machine
2.2. Hardware and Components
- Single Board Computer (Raspberry Pi 4 model B+, Raspberry Pi Holdings plc, South Wales, United Kingdom).
- Microcontroller (Arduino Mega 2560, Arduino AG, Monza, Italy).
- Camera (Model: HT-SUA134GC-T1V Huateng USB 3.0, Huateng Vision, Shenzhen, China).
- Mosfet-based solenoid driver board.
- Opto-isolation and attenuation module.
- Led lighting ring.
- The SBC hosts the software that captures the images of lemons from the camera, processes those images, and determines the size to which the citrus fruit belongs. Based on the generated size, it sends commands to the microcontroller to activate the solenoids responsible for separating the lemons. Another feature of this software is that it receives configuration parameters to perform various classifications of lemons according to the user’s requirements.
- The microcontroller hosts the software routines that receive input signals from the OBC and send signals to the solenoids via a signal amplifier board to separate the lemon fruits.
2.3. Lemon Images Dataset
2.4. FOMO-Based Peduncle Position Estimation
2.5. Feature Extraction for Size-Based Lemon Classification
- Contour area (in pixels).
- Contour perimeter (in pixels).
- Length of major axis LMaA (in pixels).
- Length of minor axis LMiA (in pixels).
- LMaA/LMiA ratio.
- Peduncle over major axis ratio. To estimate this ratio, the software detects the lemon peduncle and computes the distance to the centroid of the binary images. Then, the software computes the ratio of this distance and one half of the major axis.
2.6. Queuing Algorithm to Activate the Ejector Solenoids
3. Results
3.1. Color Space Selection
3.2. Peduncle Detection
3.3. Dataset Balancing Strategy
3.4. Evaluation of Classifiers
3.5. Execution Times and Memory Usage Estimation
3.6. On-Field Test of the Vision System
4. Conclusions and Future Work
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Lozano, E. Citrus Annual; Technical Report MX2023-0064; United States Department of Agriculture (USDA), Monterrey Agricultural Trade Office: Monterrey, Mexico, 2023.
- Secretaría de Desarrollo Rural, Pesca y Acuacultura. Tamaulipas Líder en Exportación de Limón Italiano. 2017. Available online: https://www.tamaulipas.gob.mx/desarrollorural/2017/04/tamaulipas-lider-en-exportacion-de-limon-italiano/ (accessed on 2 December 2025).
- Castillo-González, E.; De Medina-Salas, L.; Giraldi-Díaz, M.R.; Velásquez-De La Cruz, R.; Jiménez-Ochoa, J.R. Environmental Impacts Associated with the Production and Packing of Persian Lemon in Mexico through Life-Cycle Assessment. Clean Technol. 2024, 6, 551–571. [Google Scholar] [CrossRef]
- Peleg, K. Produce Handling, Packaging and Distribution; AVI Publishing Company: Westport, CT, USA, 1985. [Google Scholar]
- Zacarias, J.R.O.; Sullca-Mendoza, Y.C.; Valenzuela-Lino, Y.S.; Del Carpio-Ramirez, S.I.; Moggiano, N.; Coaquira-Rojo, C. Simulation of an Automated Tahitian lemon grading system based on computer vision. In Proceedings of the 2022 IEEE 13th Annual Ubiquitous Computing, Electronics & Mobile Communication Conference (UEMCON), New York, NY, USA, 26–29 October 2022; pp. 0283–0289. [Google Scholar] [CrossRef]
- Khojastehnazhand, M.; Omid, M.; Tabatabaeefar, A. Development of a lemon sorting system based on color and size. Afr. J. Plant Sci. 2010, 4, 122–127. [Google Scholar]
- Phate, V.R.; Malmathanraj, R.; Palanisamy, P. Classification and weighing of sweet lime (Citrus limetta) for packaging using computer vision system. J. Food Meas. Charact. 2019, 13, 1451–1468. [Google Scholar] [CrossRef]
- Hernández, A.; Ornelas-Rodríguez, F.J.; Hurtado-Ramos, J.B.; González-Barbosa, J.J. Accuracy Comparison Between Deep Learning Models for Mexican Lemon Classification. In Proceedings of the Telematics and Computing: 10th International Congress, WITCOM 2021, Virtual Event, 8–12 November 2021; Proceedings 10. Springer: Cham, Switzerland, 2021; pp. 62–73. [Google Scholar]
- Rawung, B.H.; Djamal, E.C.; Yuniarti, R. Classification of lemon fruit ripe using convolutional network. AIP Conf. Proc. 2023, 2714, 030029. [Google Scholar] [CrossRef]
- Granados-Vega, B.V.; Maldonado-Flores, C.; Gómez-Navarro, C.S.; Warren-Vega, W.M.; Campos-Rodríguez, A.; Romero-Cano, L.A. Development of a Low-Cost Artificial Vision System as an Alternative for the Automatic Classification of Persian Lemon: Prototype Test Simulation. Foods 2023, 12, 3829. [Google Scholar] [CrossRef] [PubMed]
- Jahanbakhshi, A.; Momeny, M.; Mahmoudi, M.; Zhang, Y.D. Classification of sour lemons based on apparent defects using stochastic pooling mechanism in deep convolutional neural networks. Sci. Hortic. 2020, 263, 109133. [Google Scholar] [CrossRef]
- Hanh, L.D.; Bao, D.N.T. Autonomous lemon grading system by using machine learning and traditional image processing. Int. J. Interact. Des. Manuf. (IJIDeM) 2023, 17, 445–452. [Google Scholar] [CrossRef]
- Zhu, Q.; Zhang, S. Research on lemon quality grading detection based on improved YOLOv5s. In Proceedings of the Third International Conference on Electronic Information Engineering, Big Data, and Computer Technology (EIBDCT 2024), Beijing, China, 26–28 January 2024; SPIE: Bellingham, WA, USA, 2024; Volume 13181, pp. 606–610. [Google Scholar]
- Sanyal, S.; Adhikary, R.; Choudhury, S.J. Revolutionizing lemon grading: An automated CNN-based approach for enhanced quality assessment. Int. J. Inf. Technol. 2024, 16, 4155–4166. [Google Scholar] [CrossRef]
- Arifin, K.N.; Rupa, S.A.; Anwar, M.M.; Jahan, I. Lemon and Orange Disease Classification using CNN-Extracted Features and Machine Learning Classifier. arXiv 2024, arXiv:2408.14206. [Google Scholar] [CrossRef]
- Mukhtar, T.; Jamil, S.; Arif, U.; Razzaq, W.; Wasif, M. Lemon Grading and Sorting Using Computer Vision. Eng. Proc. 2021, 12, 55. [Google Scholar]
- Chen, Y.; An, X.; Gao, S.; Li, S.; Kang, H. A deep learning-based vision system combining detection and tracking for fast on-line citrus sorting. Front. Plant Sci. 2021, 12, 622062. [Google Scholar] [CrossRef] [PubMed]
- Yu, Y.; An, X.; Lin, J.; Li, S.; Chen, Y. A vision system based on CNN-LSTM for robotic citrus sorting. Inf. Process. Agric. 2024, 11, 14–25. [Google Scholar] [CrossRef]
- Yılmaz, E.K.; Adem, K.; Kılıçarslan, S.; Aydın, H.A. Classification of lemon quality using hybrid model based on Stacked AutoEncoder and convolutional neural network. Eur. Food Res. Technol. 2023, 249, 1655–1667. [Google Scholar] [CrossRef]
- Janampa-Paitan, C.; Flores-Llallico, J.E.; Orellana-Garcia, B.F.; Baca, H.A.V. Automated Sorting System for Tahiti Lemons Using Raspberry PI. In Proceedings of the 2023 8th Asia-Pacific Conference on Intelligent Robot Systems (ACIRS), Xi’an, China, 7–9 July 2023; pp. 128–134. [Google Scholar]
- Chakraborty, S.K.; Subeesh, A.; Dubey, K.; Jat, D.; Chandel, N.S.; Potdar, R.; Rao, N.G.; Kumar, D. Development of an optimally designed real-time automatic citrus fruit grading–sorting machine leveraging computer vision-based adaptive deep learning model. Eng. Appl. Artif. Intell. 2023, 120, 105826. [Google Scholar] [CrossRef]
- Hymel, S.; Banbury, C.; Situnayake, D.; Elium, A.; Ward, C.; Kelcey, M.; Baaijens, M.; Majchrzycki, M.; Plunkett, J.; Tischler, D.; et al. Edge impulse: An mlops platform for tiny machine learning. arXiv 2022, arXiv:2212.03332. [Google Scholar]
- Banbury, C.; Jongboom, J.; Situnayake, D.; Moreau, L.; Reddi, V.J. FOMO: Faster Objects, More Objects—Real-Time Object Detection on Constrained Devices. arXiv 2022, arXiv:2204.03635. [Google Scholar]
- Chawla, N.V.; Bowyer, K.W.; Hall, L.O.; Kegelmeyer, W.P. SMOTE: Synthetic Minority Over-sampling Technique. J. Artif. Intell. Res. 2002, 16, 321–357. [Google Scholar] [CrossRef]
- Pedregosa, F.; Varoquaux, G.; Gramfort, A.; Michel, V.; Thirion, B.; Grisel, O.; Blondel, M.; Prettenhofer, P.; Weiss, R.; Dubourg, V.; et al. Scikit-learn: Machine Learning in Python. J. Artif. Intell. Res. 2011, 12, 2825–2830. [Google Scholar]













| Lemon Size Class Label | Number of Images |
|---|---|
| 75 | 545 |
| 95 | 535 |
| 115 | 361 |
| 140 | 624 |
| 165 | 519 |
| 200 | 543 |
| Total | 3127 |
| Classifier | SMOTE % | Accuracy Without Penduncle over Major Axis Ratio | Accuracy with Penduncle over Major Axis Ratio |
|---|---|---|---|
| RF | 0 | 0.8642 | 0.8706 |
| 20 | 0.8610 | 0.8722 | |
| 50 | 0.8610 | 0.8722 | |
| KNN | 0 | 0.8402 | 0.8382 |
| 20 | 0.8498 | 0.8530 | |
| 50 | 0.8498 | 0.8530 | |
| SVM | 0 | 0.8562 | 0.8530 |
| 20 | 0.8610 | 0.8530 | |
| 50 | 0.8610 | 0.8530 | |
| DT | 0 | 0.8514 | 0.8466 |
| 20 | 0.8563 | 0.8544 | |
| 50 | 0.8563 | 0.8544 | |
| GB | 0 | 0.8562 | 0.8594 |
| 20 | 0.8646 | 0.8695 | |
| 50 | 0.8646 | 0.8695 | |
| MLP | 0 | 0.8594 | 0.8546 |
| 20 | 0.8691 | 0.8699 | |
| 50 | 0.8691 | 0.8699 |
| Model | Img_ Width | Img_ Height | Resize_ Mode | Col_dep | 32-Bit Accuracies | 8-Bit Accuracies | ||
|---|---|---|---|---|---|---|---|---|
| Validation | Test | Validation | Test | |||||
| 1 | 224 | 224 | fit-long | Grayscale | 88.6% | 61.8% | 87.2% | 63.2% |
| 2 | 96 | 96 | squash | Grayscale | 89.1% | 78.8% | 86.9% | 78.8% |
| 3 | 96 | 96 | fit-short | RGB | 87.8% | 75.0% | 86.7% | 75.0% |
| 4 | 224 | 224 | squash | RGB | 89.7% | 73.8% | 88.0% | 70.0% |
| Classifier | Best Parameters | SMOTE % | Improves with Penduncle-Based Attribute | CV Score | Accuracy |
|---|---|---|---|---|---|
| RF | ‘max_depth’: 10, ‘max_features’: ‘sqrt’, ‘min_samples_leaf’: 2, ‘n_estimators’: 200 | 50% | YES | 0.8778 | 0.8722 |
| KNN | n_neighbors: 9, p: 1, weights: ‘distance’ | 50% | YES | 0.8498 | 0.8530 |
| SVM | ‘C’: 5.0, ‘gamma’: ‘auto’, ‘kernel’: ‘rbf’ | 50% | NO | 0.8646 | 0.8610 |
| DT | ‘criterion’: ‘gini’, ‘max_depth’: None, ‘min_samples_leaf’: 16 | 50% | NO | 0.8544 | 0.8563 |
| GB | ‘learning_rate’: 0.1, ‘max_depth’: 5, ‘n_estimators’: 100, ‘subsample’: 0.8 | 50% | NO | 0.8711 | 0.8646 |
| MLP | ‘activation’: ‘relu’, ‘alpha’: 0.01, ‘hidden_layer_sizes’: (50, 50, 50, 50, 50, 50, 50), ‘learning_rate’: ‘constant’, ‘solver’: ‘adam’ | 50% | YES | 0.8684 | 0.8699 |
| Classifier | Class | Precision | Recall | F1-Score |
|---|---|---|---|---|
| KNN | 75 | 0.933962 | 0.908257 | 0.920930 |
| 95 | 0.864078 | 0.831776 | 0.847619 | |
| 115 | 0.738636 | 0.902778 | 0.812500 | |
| 140 | 0.875000 | 0.840000 | 0.857143 | |
| 165 | 0.845238 | 0.682692 | 0.755319 | |
| 200 | 0.824000 | 0.944954 | 0.880342 | |
| macro avg | 0.846819 | 0.851743 | 0.845642 | |
| weighted avg | 0.853891 | 0.849840 | 0.848610 | |
| micro avg | 0.849840 | 0.849840 | 0.849840 | |
| SVM | 75 | 0.944444 | 0.935780 | 0.940092 |
| 95 | 0.916667 | 0.822430 | 0.866995 | |
| 115 | 0.733333 | 0.916667 | 0.814815 | |
| 140 | 0.884298 | 0.856000 | 0.869919 | |
| 165 | 0.823529 | 0.673077 | 0.740741 | |
| 200 | 0.801587 | 0.926606 | 0.859574 | |
| macro avg | 0.850643 | 0.855093 | 0.848689 | |
| weighted avg | 0.858443 | 0.853035 | 0.852038 | |
| micro avg | 0.853035 | 0.853035 | 0.853035 | |
| Decision Tree | 75 | 0.933333 | 0.899083 | 0.915888 |
| 95 | 0.855769 | 0.831776 | 0.843602 | |
| 115 | 0.752941 | 0.888889 | 0.815287 | |
| 140 | 0.866142 | 0.880000 | 0.873016 | |
| 165 | 0.857143 | 0.634615 | 0.729282 | |
| 200 | 0.804688 | 0.944954 | 0.869198 | |
| macro avg | 0.845003 | 0.846553 | 0.841045 | |
| weighted avg | 0.850853 | 0.846645 | 0.844270 | |
| micro avg | 0.846645 | 0.846645 | 0.846645 | |
| Gradient Boosting | 75 | 0.952381 | 0.917431 | 0.934579 |
| 95 | 0.865385 | 0.841121 | 0.853081 | |
| 115 | 0.732558 | 0.875000 | 0.797468 | |
| 140 | 0.876033 | 0.848000 | 0.861789 | |
| 165 | 0.860759 | 0.653846 | 0.743169 | |
| 200 | 0.801527 | 0.963303 | 0.875000 | |
| macro avg | 0.848107 | 0.849784 | 0.844181 | |
| weighted avg | 0.855494 | 0.849840 | 0.848170 | |
| micro avg | 0.849840 | 0.849840 | 0.849840 | |
| MLP | 75 | 0.968750 | 0.853211 | 0.907317 |
| 95 | 0.836364 | 0.859813 | 0.847926 | |
| 115 | 0.720430 | 0.930556 | 0.812121 | |
| 140 | 0.875000 | 0.840000 | 0.857143 | |
| 165 | 0.835443 | 0.634615 | 0.721311 | |
| 200 | 0.796875 | 0.935780 | 0.860759 | |
| macro avg | 0.838810 | 0.842329 | 0.834430 | |
| weighted avg | 0.846767 | 0.838658 | 0.837189 | |
| micro avg | 0.838658 | 0.838658 | 0.838658 | |
| Random Forest | 75 | 0.944444 | 0.935780 | 0.940092 |
| 95 | 0.909091 | 0.841121 | 0.873786 | |
| 115 | 0.767442 | 0.916667 | 0.835443 | |
| 140 | 0.899160 | 0.856000 | 0.877049 | |
| 165 | 0.857143 | 0.692308 | 0.765957 | |
| 200 | 0.807692 | 0.963303 | 0.878661 | |
| macro avg | 0.864162 | 0.867530 | 0.861832 | |
| weighted avg | 0.870686 | 0.865815 | 0.864508 | |
| micro avg | 0.865814 | 0.865814 | 0.865814 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Hernández-Mier, Y.; Nuño-Maganda, M.A.; Polanco-Martagón, S.; Cantú-Castro, Á.D.; Posada-Gómez, R.; Barrón-Zambrano, J.H. Machine Learning and Queuing Algorithm Integration for Real-Time Citrus Size Classification on an Industrial Sorting Machine. Processes 2026, 14, 164. https://doi.org/10.3390/pr14010164
Hernández-Mier Y, Nuño-Maganda MA, Polanco-Martagón S, Cantú-Castro ÁD, Posada-Gómez R, Barrón-Zambrano JH. Machine Learning and Queuing Algorithm Integration for Real-Time Citrus Size Classification on an Industrial Sorting Machine. Processes. 2026; 14(1):164. https://doi.org/10.3390/pr14010164
Chicago/Turabian StyleHernández-Mier, Yahir, Marco Aurelio Nuño-Maganda, Said Polanco-Martagón, Ángel Dagoberto Cantú-Castro, Rubén Posada-Gómez, and José Hugo Barrón-Zambrano. 2026. "Machine Learning and Queuing Algorithm Integration for Real-Time Citrus Size Classification on an Industrial Sorting Machine" Processes 14, no. 1: 164. https://doi.org/10.3390/pr14010164
APA StyleHernández-Mier, Y., Nuño-Maganda, M. A., Polanco-Martagón, S., Cantú-Castro, Á. D., Posada-Gómez, R., & Barrón-Zambrano, J. H. (2026). Machine Learning and Queuing Algorithm Integration for Real-Time Citrus Size Classification on an Industrial Sorting Machine. Processes, 14(1), 164. https://doi.org/10.3390/pr14010164

