Search code examples
python-2.7opencvblobbackground-subtractionsimplecv

Vehicle detection, count and classification in Python


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?


Solution

  • 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()