With the rapid increase in the number of electric vehicles, mobile charging robots have been attracting widespread attention worldwide. The primary task of a mobile charging robot, which enables intelligent charging for electric vehicles, is to identify and locate the charging ports. Currently, the detection of charging ports relies mainly on traditional algorithms, which suffer from low real-time performance and accuracy. Therefore, this paper proposes an improved algorithm network based on YOLOv5. It incorporates a target detection head (DYHEAD) based on the attention mechanism into YOLOv5s and utilizes SIoU as the loss function to enhance the accuracy and precision of object detection. The experiment shows that the improved algorithm achieved an average precision improvement of 3.4% and an mAP50 improvement of 2.7%. Simultaneously, with the integration of a depth camera, the algorithm successfully recognized and located three different standard charging ports. The recognition frame rate reached 85-90 frames per second, and the detection range exceeded 1.5 meters. Therefore, this algorithm can be used for the detection of charging ports in tasks involving mobile charging robots.