With the developing technology, technological blessings make human life easier and help them every day. Unmanned aerial vehicles (UAV), which is one of the technological blessings, have shown themselves in many fields, especially in fields such as the military, defense industry, photography, and hobby. With the development of defense systems with UAVs, the security of railways has also been left to UAVs. In this study, while the foreign matter separation is made on the railway by using the deep learning model in real-time, the image taken on the UAV is simultaneously controlled by using the image processing method. The fact that the deep learning model has a 0.99 mAP rate increases the reliability of the model.