This research explores the application of computer vision using YOLOv5 Medium for automatic object detection in unmanned rail inspection systems. The proposed technique utilizes image processing to analysing pixel values and detect optical motion vehicles. This detection triggers control system responses, such as activating the inspection train's motor upon vehicle identification. The study demonstrates the effectiveness of YOLOv5 Medium in achieving high accuracy rates. Evaluations at various distances yielded promising results: 97.98% at 3 meters, 100% at 5 meters, 99.49% at 7 meters, and a perfect 100% at 9 meters. These findings suggest optimal system performance at a distance of 9 meters. Overall detection performance across all test distances remained consistently high, with sequential rates of 0.96, 0.97, 0.95, and 0.96. This research emphasizes the crucial role of several factors in maintaining system accuracy and performance. These include the efficacy of the colour segmentation algorithm, ambient lighting conditions, and camera resolution. Furthermore, the importance of extensive testing with a diverse dataset is highlighted to ensure the system's robustness and adaptability to various real-world scenarios.