OpenCV Python program for Vehicle detection
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9ef766b Sep 20, 2017
Permalink
Failed to load latest commit information.
.gitignore Initial commit Sep 19, 2017
LICENSE Initial commit Sep 19, 2017
README.md Update Sep 20, 2017
Vehicle detection.ipynb Update Sep 20, 2017
car1.jpg Update Sep 20, 2017
car2.jpg Update Sep 20, 2017
car3.jpg Update Sep 20, 2017
car4.jpg Update Sep 20, 2017
car5.jpg Update Sep 20, 2017
cars.xml Update Sep 20, 2017
result_car1.png Update Sep 20, 2017
result_car2.png Update Sep 20, 2017

README.md

opencv-car-detection

OpenCV Python program for Vehicle detection

import cv2
from matplotlib import pyplot as plt

car_cascade = cv2.CascadeClassifier('cars.xml')
img = cv2.imread('car3.jpg', 1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Detect cars
cars = car_cascade.detectMultiScale(gray, 1.1, 1)

# Draw border
for (x, y, w, h) in cars:
    cv2.rectangle(img, (x,y), (x+w,y+h), (0,0,255), 2)
    ncars = ncars + 1

# Show image
plt.figure(figsize=(10,20))
plt.imshow(img)

Demo

car2.jpg

Result

result_car2.png