Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Identifying black cars with OpenCV in Python

Hello,

I'm using OpenCV in Python to identify cars in a parking lot. It works fine when the color of the car is different than black.

Here is my code. It basically applies a canny and counts the white points:

cv2.imshow("image", image)
cv2.waitKey()

# Gray scale and blur
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 5, 10, 10)
blur = cv2.GaussianBlur(gray,(5,5),0)        
cv2.imshow("blur", blur)
cv2.waitKey()

# Apply canny
edged = cv2.Canny(blur, 30, 200)
cv2.imshow("Edged", edged)
cv2.waitKey()

# Result
points = cv2.countNonZero(edged)

Here is the result for a white car:

white car

But the code doesn't work well with the shadows of the others cars:

shadows

And even worst with black cars:

black car

How do I fix this problem? Do I need to change my method? Maybe the canny isn't the best.

I'm using this image of the parking:

parking

Any tip will be very helpful,

Thanks