It is important to understand the factors underlying gradecrossing crashes and to examine potential solutions. We have installed a camera in front of a locomotive to examine grade-crossing accidents (or near accidents). We present a computer vision system that automatically extracts possible near-accident scenes by detecting the activity of vehicles crossing in front of the train after signals are ignited. We present a fast algorithm to detect moving objects recorded by a moving camera with minimal computation. The moving object is detected by: 1) estimating the ego motion of the camera and 2) detecting and tracking feature points whose motion is inconsistent with the camera motion. We introduce a pseudoreal-time ego-motion (camera-motion) estimation method with a robust optimization algorithm. We present experiments on ego-motion estimation and moving-object detection. Our algorithm works in pseudoreal-time and we expect that our algorithm can be applied to real-time applications such as collision warning in the near future, with the development of hardware technology