Context. Road traffic is continually increasing The traveled miles of vehicles increased by almost 10% from 2010 to 2019 in the USA .With increase in traffic, the risk of collisions increases as well. The Bureau of transportation statistics (BTS) of the USA reports that crashes data has increased by 24 percent from 2010 to 2019. BTS reports 2,740,000 injuries and 36,096 fatalities in USA in 2019. One means to reduce the number of crashes is by analysing the safety of roads. The main parameters to evaluate the safety of roads is statistical analysis of historical crash data. However, crashes do not happen frequently and, thus, do not help predict future crashes. Therefore, the literature introduced the concept of surrogate safety analysis, which uses various measurements, other than the number of crashes, to evaluate the safety of roads. Problem. One such measure is post encroachment times (PETs). PETs are defined as time difference between the departure of a road user from an encroachment zone and entry of another road user in the the same zone. PETs are computed by analysing in real time traffic. PETs can be computed among vehicles but also between vehicles and pedestrians and cyclists. Several approaches already exist to compute PETs but have limitations, in particular accuracy, generality, and the practicality of their solutions. In addition to PET values, speed is another metric that can be used to determine the severity of conflicts. Calculating the average and momentary speeds of motorized road users can be beneficial in case studies. Solution. This thesis presents a novel algorithm and its implementation, in the form of a library, to calculate PETs in real time. This library can use any type of detection and perception technologies, including lidars, optic cameras and radars as sources of inputs, and classical or new deep learning techniques as object detection and classification algorithms. Also, it can detect and calculate PET between any types of road users with any types of movements. The hyper parameters of the library are customizable and can be tuned for different scenarios. Moreover our library calculates average and momentary speed of road users to demonstrate more information for PET conflicts. Validation. We implemented and deployed our library on the infrastructure of our industrial partner, BlueCityTechnology. BlueCityTechnology uses Lidar technologies to monitor road intersections in several cities world-wide. We set up an experiment to manually validate data at multiple intersections. Using the result of this manual validation as ground truth, we validated our library and reported 86.29% F1-score for our PET detection module . Conclusion. Our library improves greatly the state-of-the-art and is currently used in real-world applications. Municipalities have been using PET reports of BlueCity solution to conduct before and after case studies to detect and solve possible problems at intersections.