Vehicle detection, count and classification in Python

Manisha picture Manisha · May 15, 2014 · Viewed 7.3k times · Source

I have to ultimately count the total number of vehicles in a video, distinguish between cars and trucks and color of the vehicles detected. I am using OpenCV, Python and SimpleCV for this. What I have done so far is: 1. Background subtraction 2.used find.Blobs() to find the blobs

based on the size of the blob, I can distinguish between cars and trucks. However, as I am finding the number of blobs on the foreground mask, all the blobs are white. So my question is how can I find out the color of the vehicles detected?

Answer

user3258790 picture user3258790 · Jun 15, 2014

You are assuming that the vehicles are mainly one colour, therefore you are looking for the mean colour of each blob, no? This should draw a rectangle around each blob of width 3, with the rectangle colour being the mean colour.

Feel free to optimise :)

for blob in blobs:
    a=blob.meanColor()
    mc=(int(a[0]), int(a[1]), int(a[2]))
    rect=blob.boundingBox()
    img.drawRectangle(rect[0], rect[1], rect[2], rect[3], mc, 3)
img.show()