pycon 2012: militarizing your backyard: computer vision and the squirrel hordes
TRANSCRIPT
![Page 1: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/1.jpg)
Militarizing Your Backyard With Python:
Computer Vision and the Squirrel Hordes
Kurt GrandisPyCon 2012
![Page 2: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/2.jpg)
Overview
● Background & Goals● OpenCV
○ Working with Python● Detecting Squirrels
○ SVMs○ Squirrely features
● Shooting Squirrels● Wet Squirrels● Next Steps
![Page 4: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/4.jpg)
Squirrels...
![Page 5: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/5.jpg)
Sentry Water Gun
http://wiki.teamfortress.com/wiki/Sentry_Gun
![Page 6: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/6.jpg)
System
Sensor (Camera) Blob Detection
Squirrel Detection
Targeting Shoot the Squirrel
![Page 7: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/7.jpg)
OpenCV
Open Source Computer Vision● Image Processing● Video Analysis● Feature Detectors● Object Detection C, C++, Python Interfaces http://opencv.willowgarage.com/wiki/http://code.opencv.org
![Page 8: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/8.jpg)
Python & OpenCV
● Support for native Python structures● Works with numpy● Efficient data sharing
![Page 9: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/9.jpg)
Sensor : Webcam
![Page 10: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/10.jpg)
OpenCVimport cv cv.NamedWindow("camera raw", 1)capture = cv.CreateCameraCapture(0)img = cv.QueryFrame(capture)cv.ShowImage("camera raw", img)
# Convert to Gray Scalegray = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 1)cv.CvtColor(img, gray, cv.CV_BGR2GRAY) # Canny Edge Filtercv.Canny(gray, edges, 50, 200, 3)
![Page 11: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/11.jpg)
Blob Detection
How do I find regions of interest (i.e. Blobs)?● Birds● Squirrels● Neighbor Children cvBlobsLib http://opencv.willowgarage.com/wiki/cvBlobsLib
cvFindContours (OpenCV function)
![Page 12: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/12.jpg)
Background Subtraction
Foreground Segmentation Noisy Background Codebook Approach
![Page 13: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/13.jpg)
Squirrel Detection
![Page 14: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/14.jpg)
Support Vector Machines (SVMs)
Supervised Learning Classification Features libsvm http://www.csie.ntu.edu.tw/~cjlin/libsvm/
from svm import * ... c = my_trained_model.predict(vector)
![Page 15: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/15.jpg)
Squirrely Features
What is squirrel-ness? ● blob size● histogram analysis of blob● entropy of blob (texture)
![Page 16: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/16.jpg)
Blob Size
![Page 17: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/17.jpg)
Color Histogram
![Page 18: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/18.jpg)
Entropy
h_prob = [ h / histo_sum for h in histogram ] entropy = -sum( [p * math.log(p) for p in h_prob
if p != 0] )
Measure of randomness Calculate entropy for regions of the blob
● Overall Entropy● Stdev Entropy● Left Mean Entropy - Right Mean Entropy
![Page 19: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/19.jpg)
SVM & Classifing Blobs
● blob size● color histograms● entropy of blob (texture)
Classify!
![Page 20: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/20.jpg)
Shoot the Squirrel
![Page 21: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/21.jpg)
The Gun
![Page 22: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/22.jpg)
The Turret
![Page 23: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/23.jpg)
Python and Arduino
Arduino Uno pyserial Project Sentry Gunhttps://sites.google.com/site/projectsentrygun/
Python-On-A-Chiphttp://code.google.com/p/python-on-a-chip/
import serial arduino = serial.Serial(device, BAUD_RATE) arduino.write("a")
![Page 24: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/24.jpg)
Results
● Squirrels get wet● False positives extremely low● More satisfying if it camps the feeder● Need stronger firepower● Need larger water reservoir● Squirrels are extremely persistent...no really
![Page 25: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/25.jpg)
![Page 26: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/26.jpg)
Next Steps
● Better Optics● Stronger Firepower
○ Laminar water jet○ Pressurized water pump
● Python-On-A-Chip ● Bird Classifier & Counter
![Page 27: PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes](https://reader035.vdocuments.net/reader035/viewer/2022062418/55583792d8b42ac6078b495a/html5/thumbnails/27.jpg)
Questions?
[email protected]@kgrandis http://kurtgrandis.com/ no animals were harmed in the development of this project. Bird seed and other snacks were provided to all participants free of charge.