Qingwu Shi, Maotong Qin, Xu DuThis email address is being protected from spambots. You need JavaScript enabled to view it., and Huaqi ZhaoThis email address is being protected from spambots. You need JavaScript enabled to view it.
School of Information and Electronic Engineering, Jiamusi University, Jiamusi 154007, China
Received: August 14, 2025 Accepted: September 30, 2025 Publication Date: October 24, 2025
Copyright The Author(s). This is an open access article distributed under the terms of the Creative Commons Attribution License (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are cited.
In the modern pharmaceutical industry, automated pill counting is a critical step in the production process. However, traditional methods often fail to meet the demands of high-speed and real-time detection in terms of accuracy and efficiency. This paper, motivated by the application of strip-type pill counting machines in pharmaceutical manufacturing, proposes a pill counting and missing pill detection method within elongated strip plate holes using the YOLOv12 model. The method is capable of identifying three pill states-missing pill, single pill, and two pills vertically overlapped within a single slot-and then determines the pill quantity based on the corresponding identified states. In this study, a custom dataset was constructed, and the collected images were manually annotated. The CBAM (Convolutional Block Attention Module) attention mechanism was integrated into the YOLOv12 model to enhance its focus on small pill targets and critical regions. Additionally, negative samples were incorporated into the dataset to improve the model’s ability to distinguish between background and missing pill states. With a parameter size of 2.6 M and a computational complexity of 6.4 GFLOPs, the model maintains low computational cost and lightweight characteristics while achieving high-precision detection of pill quantities and missing pill states.
[1] X. Yao, (2021) “Current Situation and Development Prospects of Traditional Chinese Medicine Industry" Chinese Traditional and Herbal Drugs 52(17): 5115 5119. DOI: CNKI:SUN:ZCYO.0.2021-17-001.
[2] Z. Fan, (2022) “Design of an Automatic Pill Counting System Based on a Single-Chip Microcomputer" Plant Maintenance Engineering (09): 113–114. DOI: 10.16621/j.cnki.issn1001-0599.2022.05.49.
[3] Y. Ruidong. “Research on High-Precision Pill Counting Machine Control System Based on ARM". (mathesis). Shandong University, 2015.
[4] J. Yang, C. Dou, L. Xin, W. Liu, and X. Zhou, (2018) “Research on tablet granule counting algorithm based on visual matching technology" Packaging Engineering 39(19): 175–180. DOI: 10.19554/j.cnki.1001-3563.2018.19.031.
[5] G. Liu. “Design of Counting Machine Control System Based on DSP and PLC". (mathesis). Nanchang Hangkong University, 2013.
[6] Z. Wang, J. Chen, and R. Ai, (2017) “Development Trend and Application Prospect of Photoelectric Detection Technology" Sichuan Cement (03): 152. DOI: CNKI: SUN:SCSA.0.2017-03-149.
[7] Q.SunandJ.Cai,(2020)“Detection System of Flat Plate Counting Machine Based on FPGA" Light Industry Machinery 38(03): 69–73. DOI: CNKI:SUN:QGJX.0. 2020-03-014.
[8] C. Phromlikhit, F. Cheevasuvit, and S. Yimman. “Tablet counting machine base on image processing”. In: The 5th 2012 Biomedical Engineering International Conference. 2012, 1–5. DOI: 10.1109/BMEiCon.2012.6465508.
[9] J. Moon, S. Lim, H. Lee, S. Yu, and K.-B. Lee, (2022) “Smart Count System Based on Object Detection Using Deep Learning" Remote Sensing 14(15): 3761. DOI: 10.3390/rs14153761.
[10] A. D. Nguyen, H. H. Pham, H. T. Trung, Q. V. H. Nguyen,T.N.Truong,andP.L.Nguyen,(2023)“High accurate and explainable multi-pill detection framework with graph neural network-assisted multimodal data fusion" Plos One 18(9): e0291865. DOI: 10.48550/arXiv.2303.09782.
[11] Y. Yao, J. Cai, and Q. Liu, (2018) “Detection method of flat plate counting machine based on machine vision" Optical Instruments 40(04): 9–14. DOI: CNKI:SUN: GXYQ.0.2018-04-002.
[12] M. Hao, K. Sun, T. Liu, and G. Wang, (2023) “Design of high-speed online pill counting and packaging system based on machine vision" Techniques of Automation and Applications 42(06): 38–40. DOI: 10.20033/j.1003-7241.(2023)06-0038-03.
[13] J. Zhang and W. Zhu, (2018) “Counting of circular overlapping particles based on depth image processing technology" Information Technology (06): 71–75+80. DOI: 10.13274/j.cnki.hdzj.2018.06.015.
[14] A. Hu and Z. Li, (2018) “Counting machine system based on improved Faster R-CNN" Packaging Engineering 39(09): 141–145. DOI: 10.19554/j.cnki.1001 3563.2018.09.025.
[15] H.-J. Kwon, H.-G. Kim, and S.-H. Lee, (2022) “Pill Detection Model for Medicine Inspection Based on Deep Learning" Chemosensors 10(1): DOI: 10.3390/chemosensors10010004.
[16] R.Girshick,J.Donahue,T.Darrell,andJ.Malik.“Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation”. In: 2014 IEEE Confer ence on Computer Vision and Pattern Recognition. 2014, 580–587. DOI: 10.1109/CVPR.2014.81.
[17] J. Redmon, S. Divvala, R. Girshick, and A. Farhadi. “You Only Look Once: Unified, Real-Time Object De tection”. In: 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2016, 779–788. DOI: 10.1109/CVPR.2016.91.
[18] J. Ma, Y. Zhou, Z. Zhou, Y. Zhang, and L. He, (2025) “Toward smart ocean monitoring: Real-time detection of marine litter using YOLOv12 in support of pollution mitigation" Marine Pollution Bulletin 217: 118136. DOI: https: //doi.org/10.1016/j.marpolbul.2025.118136.
[19] J. Bu. “Research on PCB surface defect detection method based on improved YOLOX". (mathesis). Liaoning University of Science and Technology, 2023. DOI: 10.26923/d.cnki.gasgc.2023.000088.
[20] R. Khanam and M. Hussain, (2025) “A Review of YOLOv12: Attention-Based Enhancements vs. Previous Versions" arXiv arXiv:2504.11995: DOI: https: //doi.org/10.48550/arXiv.2504.11995.
[21] H.W.Ting, S. L. Chung, C. F. Chen, et al., (2020) “A Drug Identification Model Developed Using Deep Learning Technologies: Experience of a Medical Center in Tai wan" BMC Health Services Research 20: 312. DOI: 10.1186/s12913-020-05166-w.
[22] J. Chen and X. Wang, (2024) “Dense small object detection algorithm for UAV aerial images based on improved YOLOv5" Computer Engineering and Applications 60(03): 100–108.
[23] R. Sapkota, M. Flores-Calero, R. Qureshi, et al., (2025) “YOLOadvances to its genesis: a decadal and comprehensive review of the You Only Look Once (YOLO) series" Artificial Intelligence Review 58: 274. DOI: 10.1007/s10462-025-11253-3.
[24] S. Yin, L. Wang, M. Shafiq, L. Teng, A. A. Laghari, and M.F. Khan, (2023) “G2Grad-CAMRL: An Object Detection and Interpretation Model Based on Gradient Weighted Class Activation Mapping and Reinforcement Learning in Remote Sensing Images" IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing 16: 3583–3598. DOI: 10.1109/ JSTARS.2023.3241405.
[25] S. Woo, J. Park, J.-Y. Lee, and I. S. Kweon. “CBAM: Convolutional Block Attention Module”. In: Computer Vision– ECCV 2018: 15th European Conference, Munich, Germany, September 8–14, 2018, Proceedings, Part VII. 2018, 3–19. DOI: 10.1007/978-3-030-01234 2_1.
[26] Q. Shi, S. Yin, K. Wang, et al., (2022) “Multichannel convolutional neural network-based fuzzy active contour model for medical image segmentation" Evolving Systems 13: 535–549. DOI: 10.1007/s12530-021-09392-3.
[27] C. Zhang. “Research on rotated object detection method based on convolutional neural networks". (mathesis). University of Electronic Science and Technology of China, 2023. DOI: 10.27005/d.cnki.gdzku.2023.002432.
[28] Y.Pan.“Research on FPGA acceleration technology of feature extraction in visual inspection". (phdthesis). Hefei University of Technology, 2021. DOI: 10.27101/d.cnki.ghfgu.2021.000005.
[29] X. Liang. “Research on pill coating defect detection technology based on machine vision". (mathesis). Chongqing University of Science and Technology, 2023. DOI: 10.27854/d.cnki.gcqkj.2023.000357.
[30] Z. Wu. “Research and application of online pill defect detection system based on machine vision". (mathesis). Tianjin Polytechnic University, 2023. DOI: 10.27357/d.cnki.gtgyu.2023.001211.
[31] L. Liang. “Research on particle counting and defect detection system based on visual tracking". (mathesis). South China University of Technology, 2014.
[32] W. Zhou, B. Sun, L. Shi, and S. Yang, (2025) “Research on potato leaf disease detection method based on YOLO model" Automation Instrumentation 40(05): 71–75. DOI: 10.19557/j.cnki.1001-9944.2025.05.014.
We use cookies on this website to personalize content to improve your user experience and analyze our traffic. By using this site you agree to its use of cookies.