Skip to content

Instantly share code, notes, and snippets.

@mjcreativeventures
Created February 15, 2016 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjcreativeventures/46fede912660ae10311f to your computer and use it in GitHub Desktop.
Save mjcreativeventures/46fede912660ae10311f to your computer and use it in GitHub Desktop.
Object Detection
# IPython Notebook code
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
cctv_image = cv2.imread('0744_04.jpg')
# the 'cascade.xml' file is the file generated by the training script above
vehicle_classifier = cv2.CascadeClassifier('cascade.xml')
# various parameters can be passed to modify how objects are detected
vehicles = vehicle_classifier.detectMultiScale(cctv_image, 1.1, 2, maxSize=(100,100))
print 'Vehicles detected: %d' % (len(vehicles))
# draw a rectangle around every vehicle detected
for (x,y,w,h) in vehicles:
cv2.rectangle(cctv_image, (x,y), (x+w, y+h),(255,0,0),2)
plt.figure(figsize=(9,9))
plt.axis('off')
plt.imshow(cv2.cvtColor(cctv_image, cv2.COLOR_BGR2RGB))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment