Real-Time Multi-Pill Detection and Slot-Aware Counting in Blister Packs Using a Lightweight YOLOv8 Nano Framework

Authors

DOI:

https://doi.org/10.21015/vtcs.v14i1.2436

Abstract

This paper introduces an object detection and recognition approach to identify the locations and the type of pills in images of multiple pills, using a limited dataset of single-pill images as training data. Medicine strips have become very popular for packaging pills and capsules; however, manually counting the number of pills remaining is inconvenient and imprecise. This project describes a mobile-based system that automatically identifies and counts occupied and vacant pill slots in medicine strip images using deep learning methods. Images of medicine strips were gathered from the real world and manually annotated into two categories: filled pills and empty slots. A YOLOv8 Nano object detector model was chosen for its speed and low computational requirements. The model was trained on Google Colab using GPU resources to learn the visual patterns of pills and empty spaces. To enable deployment on mobile devices, the model was optimized and quantized into TensorFlow Lite with Int8 values, and this optimized model was subsequently incorporated into a Flutter Android application. Additional geometric logic was used to minimize false detections and enhance counting accuracy. The experimental findings indicate that the proposed system is capable of real-time identification and counting of pills on a mobile device with high accuracy. The solution is portable, effective, and applicable to healthcare tasks related to medication use and pharmacy-based smart systems.

References

L. Slawomirski, A. Auraaen, and N. Klazinga, "The economics of patient safety," Organisation for Economic Co-operation and Development (OECD), Mar. 2017. [Online]. Available: https://www.oecd.org/health/health-systems/The-economics-of-patient-safety-March-2017.pdf

Institute of Medicine, *Preventing Medication Errors*. Washington, DC, USA: The National Academies Press, 2007.

"Reducing and preventing adverse drug events to decrease hospital costs," PSNet, Mar. 6, 2005. [Online]. Available: https://psnet.ahrq.gov/issue/reducing-and-preventing-adverse-drug-events-decrease-hospital-costs

A. Weiss, W. Freeman, K. Heslin, and M. L. Barrett, "Adverse drug events in U.S. hospitals, 2010 versus 2014," Agency for Healthcare Research and Quality, 2018.

T. I. Chang et al., "Polypharmacy, hospitalization, and mortality risk: a nationwide cohort study," *Sci. Rep.*, vol. 10, no. 1, p. 18964, Nov. 2020.

P. S. Melnyk, Y. M. Shevchuk, and A. J. Remillard, "Impact of the dial access drug information service on patient outcome," *Ann. Pharmacother.*, vol. 34, no. 5, pp. 585–592, May 2000.

J. M. LeBlanc, E. C. Seoane-Vazquez, T. C. Arbo, and J. F. Dasta, "International critical care hospital pharmacist activities," *Intensive Care Med.*, vol. 34, no. 3, pp. 538–542, Mar. 2008.

E. Costerison and A. Graham, "Developing and promoting an intranet site for a drug information service," *Am. J. Health Syst. Pharm.*, vol. 65, no. 7, pp. 639–643, Apr. 2008.

J. H. Choi, J. Kim, S. Shanmugam, C. S. Yong, H. G. Choi, and B. K. Yoo, "Analysis on drug identification service and other drug-related queries in a hospital pharmacy," *Yakhak Hoeji*, vol. 52, no. 4, pp. 283–287, 2008.

Y. G. Tefera, B. M. Gebresillassie, A. A. Ayele, Y. B. Belay, and Y. K. Emiru, "The characteristics of drug information inquiries in an Ethiopian university hospital: a two-year observational study," *Sci. Rep.*, vol. 9, no. 1, p. 13835, Sep. 2019.

D. A. Almazrou, S. Ali, and J. A. Alzhrani, "Assessment of queries received by the drug information center at King Saud Medical City," *J. Pharm. Bioallied Sci.*, vol. 9, no. 4, pp. 246–250, 2017.

Y. Lee, U. Park, A. K. Jain, and S. Lee, "Pill-ID: matching and retrieval of drug pill images," *Pattern Recognit. Lett.*, vol. 33, no. 7, pp. 904–910, May 2012.

Z. Chen and S. Kamata, "A new accurate pill recognition system using imprint information," in *Proc. 6th Int. Conf. Machine Vision (ICMV 2013)*, London, U.K., Dec. 2013.

J. Yu, Z. Chen, and S. Kamata, "Pill recognition using imprint information by two-step sampling distance sets," in *Proc. 22nd Int. Conf. Pattern Recognition*, Stockholm, Sweden, Aug. 2014.

J. Yu, Z. Chen, S. Kamata, and J. Yang, "Accurate system for automatic pill recognition using imprint information," *IET Image Process.*, vol. 9, no. 12, pp. 1039–1047, Dec. 2015.

Y. F. Wong, H. T. Ng, K. Y. Leung, K. Y. Chan, S. Y. Chan, and C. C. Loy, "Development of fine-grained pill identification algorithm using deep convolutional network," *J. Biomed. Inform.*, vol. 74, pp. 130–136, Oct. 2017.

K. L. James, D. Barlow, R. McArtney, S. Hiom, D. Roberts, and C. Whittlesea, "Incidence, type and causes of dispensing errors: a review of the literature," *Int. J. Pharm. Pract.*, vol. 17, no. 1, pp. 9–30, Feb. 2009.

E. A. Flynn and K. N. Barker, "Effect of an automated dispensing system on errors in two pharmacies," *J. Am. Pharm. Assoc.*, vol. 46, no. 5, pp. 613–615, 2006.

S. Cho, B. Kim, E. Park, J. Kim, H. Ryu, and Y. Sung, "Usability evaluation of an image-based pill identification application," *J. Rheum. Dis.*, vol. 26, no. 2, p. 111, 2019.

Z. Yaniv et al., "The national library of medicine pill image recognition challenge: an initial report," in *IEEE Appl. Imag. Pattern Recognit. Workshop*, Oct. 2016.

X. Zeng, K. Cao, and M. Zhang, "MobileDeepPill: a small-footprint mobile deep learning system for recognizing unconstrained pill images," in *Proc. 15th Annu. Int. Conf. Mobile Systems, Applications, and Services (MobiSys'17)*, Niagara Falls, NY, USA, Jun. 2017.

N. Larios Delgado et al., "Fast and accurate medication identification," *NPJ Digit. Med.*, vol. 2, no. 1, p. 10, Feb. 2019.

W. Chang, L. Chen, C. Hsu, J. Chen, T. Yang, and C. Lin, "MedGlasses: a wearable smart-glasses-based drug pill recognition system using deep learning for visually impaired chronic patients," *IEEE Access*, vol. 8, pp. 17013–17024, 2020.

C. Szegedy et al., "Going deeper with convolutions," in *Proc. IEEE Conf. Computer Vision and Pattern Recognition (CVPR)*, Boston, MA, USA, Jun. 2015, pp. 1–9.

Y. Wang, J. Ribera, C. Liu, S. Yarlagadda, and F. Zhu, "Pill recognition using minimal labeled data," in *Proc. IEEE 3rd Int. Conf. Multimedia Big Data (BigMM'17)*, Laguna Hills, CA, USA, Apr. 2017, pp. 346–353.

A. Krizhevsky, I. Sutskever, and G. E. Hinton, "ImageNet classification with deep convolutional neural networks," *Commun. ACM*, vol. 60, no. 6, pp. 84–90, May 2017.

C. Yi and Y. Tian, "Text string detection from natural scenes by structure-based partition and grouping," *IEEE Trans. Image Process.*, vol. 20, no. 9, pp. 2594–2605, Sep. 2011.

R. Daou, K. Karam, H. Zeidan, A. Hayek, and J. Borcsok, "Design of a safe and smart medicine box," *Int. J. Biomed. Eng. Sci.*, vol. 5, pp. 1–13, 2018.

E. Peng, P. Peursum, and L. Li, "Product barcode and expiry date detection for the visually impaired using a smartphone," in *Proc. Int. Conf. Digital Image Computing Techniques and Applications (DICTA)*, Fremantle, WA, Australia, 2012, pp. 1–7.

M. Abdul Kader, M. Nayim Uddin, A. Mohammad Arfi, N. Islam, and M. Anisuzzaman, "Design & implementation of an automated reminder medicine box for old people and hospital," in *Proc. Int. Conf. Innovations in Science, Engineering and Technology (ICISET)*, Chittagong, Bangladesh, 2018, pp. 390–394.

M. Srinivas, P. Durgaprasadarao, and V. N. P. Raj, "Intelligent medicine box for medication management using IoT," in *Proc. 2nd Int. Conf. Inventive Systems and Control (ICISC)*, Coimbatore, India, 2018, pp. 32–34.

N. Banu, S. Thilaga, G. Vinothini, and S. Abirami, "Image-based label detection with voice output for visually challenged persons using classifiers," *Int. J. Eng. Res. Modern Educ.*, vol. 3, no. 1, pp. 25–29, 2018.

P. Ranjana and E. Alexander, "Health alert and medicine reminder using Internet of Things," in *Proc. IEEE Int. Conf. Computational Intelligence and Computing Research (ICCIC)*, Madurai, India, 2018, pp. 1–4.

R. Al-Shammary, D. Mousa, and S. E. Esmaeili, "The design of a smart medicine box," in *Iranian Conf. Electrical Engineering (ICEE)*, Mashhad, Iran, 2018, pp. 130–134.

H.-K. Wu, C.-M. Wong, P.-H. Liu, S.-P. Peng, X.-C. Wang, C.-H. Lin, and K.-H. Tu, "A smart pill box with reminder and consumption confirmation," 2015.

J. O. Gordon, R. S. Hadsall, and J. C. Schommer, "Automated medication-dispensing system in two hospital emergency departments," *Am. J. Health Syst. Pharm.*, vol. 62, pp. 1917–1923, 2005.

E. Y. Fung, B. Leung, D. Hamilton, and J. Hope, "Do automated dispensing machines improve patient safety?," *Can. J. Hosp. Pharm.*, vol. 62, pp. 516–519, 2009.

A. Carswell, K. Bennett, J. Hanson, B. Dalgliesh, and M. Wallis, "Implementation of distributed automated medication dispensing units in a new hospital: nursing and pharmacy experience," *J. Clin. Nurs.*, vol. 30, pp. 2863–2872, 2021.

Z. Wen and Y. Tao, "Building a rule-based machine-vision system for defect inspection on apple sorting and packing lines," *Expert Syst. Appl.*, vol. 16, pp. 307–313, 1999.

W. Chantara, J.-H. Mun, D.-W. Shin, and Y.-S. Ho, "Object tracking using adaptive template matching," *IEIE Trans. Smart Process. Comput.*, vol. 4, pp. 1–9, 2015.

X. Zhou et al., "Automated visual inspection of glass bottle bottom with saliency detection and template matching," *IEEE Trans. Instrum. Meas.*, vol. 68, pp. 4253–4267, 2019.

J.-Y. Chen et al., "Real-time FPGA-based template matching module for visual inspection application," in *Proc. IEEE/ASME Int. Conf. Advanced Intelligent Mechatronics (AIM)*, Kaohsiung, Taiwan, Jul. 2012, pp. 1072–1076.

I. Hussain, S. M. H. Zaidi, U. Khan, and A. Ahmed, "Sentiment analysis classification of ChatGPT tweets using machine learning and deep learning algorithms," *J. Comput. Biomed. Inform.*, vol. 8, no. 1, pp. 1–8, 2024.

S. M. Hassan, S. A. Ali, B. Hassan, I. Husain, M. Rafiq, and S. A. Awan, "Hybrid features binary classification of imbalance stroke patients using different machine learning algorithms," *Int. J. Biol. Biomed. Eng.*, vol. 16, pp. 154–160, 2022.

S. S. Shaukat, I. Husain, and I. A. Siddiqui, "An application of correspondence analysis, detrended correspondence analysis, and canonical correspondence analysis with reference to the vegetation and environment of calcareous hills around Karachi," *Int. J. Biol. Biotechnol.*, vol. 2, no. 3, pp. 617–627, 2005.

I. Husain, N. U. Khan, and S. S. Shaukat, "Mathematical techniques to study the spatial pattern of *Meloidogyne javanica* in relation to soil fungi and soil characteristics in a tomato-grown field," *Res. J. Recent Sci.*, vol. 4, no. 12, pp. 60–67, 2015.

S. Iqbal, S. Ahmed, B. Hassan, M. K. Abid, and I. Husain, "Enhancing lung cancer detection with hybrid machine learning: integrating ant colony optimization," *Tech. J. Univ. Eng. Technol. (UET) Taxila*, vol. 29, no. 3, pp. 74–86, 2024.

S. A. Awan, S. A. Ali, I. Husain, B. H. Quraishi, and S. M. A. Ashraf, "Proficient masked face recognition method using deep learning convolution neural network in COVID-19 pandemic," *Int. J. Circuits Syst. Signal Process.*, vol. 15, pp. 7172–7176, 2021.

S. M. Hassan, A. H. Khan, S. Shaikh, and I. Husain, "Making STEM subjects graphs accessible for blind and visually impaired students using Document Understanding Transformer (DONUT) model," *Int. J. Online Biomed. Eng.*, vol. 21, no. 14, pp. 4–19, 2025.

S. M. Hassan, I. K. Kerio, S. Ahmed, and I. Husain, "A hybrid approach to stance detection and sentiment analysis using BERT and VADER in Reddit discussions on the Israel–Palestine conflict," *Spectr. Eng. Sci.*, vol. 3, no. 10, pp. 1391–1401, 2025.

S. M. Hassan, S. Ahmed, I. Husain, B. H. Qureshi, S. A. Naz, and A. Razaque, "A hybrid AI-based university students queries chatbot using NLP and SBERT technologies," *Spectr. Eng. Sci.*, vol. 3, no. 3, pp. 275–288, 2025.

S. M. H. Zaidi et al., "Unsupervised classification of multi-class chart images: a comparison of customized CNNs and transfer learning techniques," *PeerJ Comput. Sci.*, vol. 11, p. e3148, 2025.

J. Redmon, S. Divvala, R. Girshick, and A. Farhadi, "You only look once: unified, real-time object detection," in *Proc. IEEE Conf. Computer Vision and Pattern Recognition (CVPR)*, Las Vegas, NV, USA, Jun. 2016.

"ultralytics/yolov5: v3.1 – Bug Fixes and Performance Improvements," Zenodo, Oct. 29, 2020. [Online]. Available: https://zenodo.org/record/4154370

K. He, X. Zhang, S. Ren, and J. Sun, "Deep residual learning for image recognition," in *Proc. IEEE Conf. Computer Vision and Pattern Recognition (CVPR)*, Las Vegas, NV, USA, Jun. 2016.

D. E. Rumelhart, G. E. Hinton, and R. J. Williams, "Learning representations by back-propagating errors," *Nature*, vol. 323, no. 6088, pp. 533–536, Oct. 1986.

C. A. Lester, J. Li, Y. Ding, B. Rowell, J. Yang, and R. A. Kontar, "Performance evaluation of a prescription medication image classification model: an observational cohort," *NPJ Digit. Med.*, vol. 4, no. 1, p. 118, Jul. 2021.

A. Cubuk, B. Zoph, D. Mane, V. Vasudevan, and Q. V. Le, "RandAugment: practical automated data augmentation with a reduced search space," 2019.

T.-Y. Liu et al., "Unbiased teacher for semi-supervised object detection," 2021.

Downloads

Published

2026-06-30

How to Cite

Hassan Zaidi, S. M., Husain, I., Ahmed, A., & Nazia Ashraf, S. (2026). Real-Time Multi-Pill Detection and Slot-Aware Counting in Blister Packs Using a Lightweight YOLOv8 Nano Framework. VAWKUM Transactions on Computer Sciences, 14(1), 202–215. https://doi.org/10.21015/vtcs.v14i1.2436