Abstract
In hospital environments, the precise management of toxic and narcotic medications is critical for public safety. Traditional object detection models using horizontal bounding boxes often struggle with the dense, overlapping arrangements typical of medical supplies. This paper proposes a specialized YOLOv5-based detector that utilizes rotated bounding boxes (RBB) to improve detection accuracy. By framing rotation as a classification problem and implementing a "mask-mapping" Non-Maximum Suppression (NMS), the proposed model achieves a mean Average Precision (mAP) of 0.811, significantly outperforming standard horizontal detectors.
Introduction
Managing high-risk medications requires high-precision automated systems to prevent illegal diversion and ensure patient safety. "Intelligent medicine cabinets" are increasingly used, but they rely on computer vision to count and identify drugs. Standard detectors like YOLO or Faster R-CNN use axis-aligned rectangles, which are suboptimal for long, thin ampoules or boxes tilted at various angles. In dense arrangements, horizontal boxes overlap excessively, causing Non-Maximum Suppression (NMS) to erroneously discard valid detections, leading to low recall and inaccurate counts.
Methodology
The researchers developed a modified YOLOv5-small architecture specifically for rotated object detection.
Rotated Bounding Box (RBB)
The core innovation is the transition from a 4-parameter box $(x, y, w, h)$ to a 5-parameter rotated box $(x, y, w, h, \theta)$. This allows the detector to align precisely with the object's orientation, minimizing empty space and overlap with adjacent items.
Angle as Classification
Instead of regressing the angle $\theta$ as a continuous value—which can lead to instability at boundary conditions—the authors treated it as a classification task. They evaluated two granularities: 90 classes ($1^\circ$ intervals) and 180 classes ($0.5^\circ$ intervals). This approach, combined with "circular smooth labels," helps the model handle the periodic nature of rotation where $0^\circ$ and $90^\circ$ are physically similar but numerically distant.
Model Architecture and Masked NMS
The overall pipeline follows a modified YOLOv5 structure, incorporating downward and upward blocks for feature extraction and fusion.
To maintain inference speed, the authors avoided complex polygon IoU calculations. Instead, they implemented "Masked NMS," which generates binary masks for predicted boxes and calculates IoU based on pixel-wise overlap. This approximation is computationally efficient and provides sufficient accuracy for real-time hospital use.
Experimental Results
The model was trained on a dataset of 38 medication types, using 6,000 synthetic images for pre-training and 523 real-world images for fine-tuning.
The best-performing variant, Ro_Yolo_180, achieved a mean Average Precision (mAP) of 0.811, a significant improvement over the standard horizontal YOLOv5's 0.728. Furthermore, the rotated detector showed a higher recall (0.689 vs. 0.648), demonstrating its superior ability to distinguish individual items in crowded trays where horizontal boxes would have merged them. Inference time remained under 300ms on an NVIDIA RTX 3060Ti, meeting the requirements for interactive use.
Conclusion
By incorporating rotation into the object detection framework, this research provides a robust solution for the automated monitoring of sensitive medical supplies. The use of angle classification and masked NMS offers a practical balance between detection precision and computational efficiency, paving the way for more reliable and safer intelligent medicine cabinets.
Summary updated