As @neil said there is no simple answer. But I would like to tell you how I would approach this non-trivial task.
- Get as much data as possible. This is critical to get this task done. If you have small amount of data, higher the chance you would choose parameters that work on the data you have but it won’t work well when used on new videos. So this is key.
- I would start by looking at these videos to get a feel of what is happening. By feel, I mean, observe what features would be good to faithfully draw bounding boxes around the vehicles. Since you need to detect collision, bounding box dimension accuracy is critical. Because slightly larget bounding box could be detected as collision when there is none.
- You are using centroid, I think this won’t work because it does not matter where the vehicle centre is and vehicle boundaries matter more. And since vehicle size varies, constant threshold wont work for sure(assuming you use constant threshold). You need to use centroids to find the nearest vehicles around a vehicle and then find the distances between the bounding box. If any distance is negative can be detected as collision(accident).
- Yes, coming back to bounding box. It is important to preprocess the images(possibly gaussian blur, but its trial and error).
- After preprocessing, use adaptive thresholding methods(try the ones that opencv provides) and experiment with it. Use color information in the video(not just gray). Exploit the road color(if it is constant). If you could remove road from the picture, all you will be left with is vehicles. This makes your job easier. But it can be done only if road color has no artifacts, but doable.
Hope this helps and good luck 🙂