The work contained in this thesis has not been previously submitted to meet requirements for an award at this or any other higher education institution. To the best of my knowledge and belief, the thesis contains no material previously published or written by another person except where due reference is made. Currently most of the data for near-miss and SPAD incidents are collected from the reports made by train drivers. There is a doubt that all of the incidents that occurred are actually reported by train drivers, due to the subjectivity of near-miss events, and also disciplinary actions that v might be taken against train drivers, if they are responsible for any incidents.To identify the causal factors of railway collisions, the Cooperative Research Centre for Rail Innovation has initiated a research project to develop an automated data collection system to support railway collision analysis. The system collects data from trains' on-board computers, GPS receivers, and forward facing cameras. This thesis presents computer vision algorithms for automatically detecting near-miss and SPAD incidents from train cameras as part of this project.To automatically detect near-miss events from videos, we localize vehicles in each frame and calculate the distance of the vehicles to the railway. If the distance of a vehicle to the railway is less than a pre-defined distance, the event will be flagged as a near-miss incident for further analysis. Our proposed near-miss detection system consists of railway detection and segmentation, and vehicle detection and localization algorithms. We employ several computer vision techniques including image segmentation, convolutional neural networks, and 3D geometry reconstruction.In order to automatically detect SPAD incidents from videos, we detect railway signals as well as the state of the signals in each frame. An event will be flagged as a SPAD if a train passes a red signal. Our approach for detecting SPAD events consists of using morphological operations, different colour spaces, 3D geometry reconstruction, segmentation algorithms, and machine learning techniques.This thesis introduces algorithms for automatically detecting level crossing near-miss and SPAD incidents from video data obtained by forward facing cameras of trains. The accuracy rate of our near-miss detection system for detecting and segmenting railways on our railway dataset is 96% for day-time, and 93% for night-time videos. The system has 75% of precision and 81% of recall for detecting vehicles on this dataset. We compared our vehicle detector algorithm with the Deformable Part Models (DPM) and Regions with CNN features (R-CNN) object detectors. The recall rate of our algorithm is 29% higher than what can be achieved with DPM or R-CNN detectors on our railway dataset. We also present the results of detecting railway signals on more than 5,000 frames for our SPAD detection system. This thesis opens avenues for helping to identify the causal factors of train collisions.vi