Microglial cells are a type of glial cells that make up 10–15% of all brain cells, and they play a significant role in neurodegenerative disorders and cardiovascular diseases. Despite their vital role in these diseases, developing fully automated microglia counting methods from immunohistological images is challenging. Current image analysis methods are inefficient and lack accuracy in detecting microglia due to their morphological heterogeneity. This study presents development and validation of a fully automated and efficient microglia detection method using the YOLOv3 deep learning-based algorithm. We applied this method to analyse the number of microglia in different spinal cord and brain regions of rats exposed to opioid-induced hyperalgesia/tolerance. Our numerical tests showed that the proposed method outperforms existing computational and manual methods with high accuracy, achieving 94% precision, 91% recall, and 92% F1-score. Furthermore, our tool is freely available and adds value to exploring different disease models. Our findings demonstrate the effectiveness and efficiency of our new tool in automated microglia detection, providing a valuable asset for researchers in neuroscience.