SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Militarizing Your
 Backyard With Python:
Computer Vision and the Squirrel
            Hordes



                       Kurt Grandis
                       PyCon 2012
Overview
● Background & Goals
● OpenCV
  ○ Working with Python
● Detecting Squirrels
  ○ SVMs
  ○ Squirrely features
● Shooting Squirrels
● Wet Squirrels
● Next Steps
The Great Backyard Bird Count




http://www.birdsource.org/gbbc/
Squirrels...
Sentry Water Gun




                   http://wiki.teamfortress.com/wiki/Sentry_Gun
System


Sensor (Camera)   Blob Detection

                                          Targeting   Shoot the Squirrel


                     Squirrel Detection
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
Python & OpenCV
● Support for native Python structures
● Works with numpy
● Efficient data sharing
Sensor : Webcam
OpenCV
         import cv

         cv.NamedWindow("camera raw", 1)
         capture = cv.CreateCameraCapture(0)
         img = cv.QueryFrame(capture)
         cv.ShowImage("camera raw", img)




         # Convert to Gray Scale
         gray = cv.CreateImage(cv.GetSize(img),
                          cv.IPL_DEPTH_8U, 1)
         cv.CvtColor(img, gray, cv.CV_BGR2GRAY)


         # Canny Edge Filter
         cv.Canny(gray, edges, 50, 200, 3)
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)
Background Subtraction
Foreground Segmentation

Noisy Background

Codebook Approach
Squirrel Detection
Support Vector Machines (SVMs)
Supervised Learning                                from svm import *

                                                   ...

Classification                                     c = my_trained_model.predict(vector)




Features


libsvm http://www.csie.ntu.edu.tw/~cjlin/libsvm/
Squirrely Features




What is squirrel-ness?

● blob size
● histogram analysis of blob
● entropy of blob (texture)
Blob Size
Color Histogram
Entropy
          Measure of randomness

          Calculate entropy for regions of the blob

           ●   Overall Entropy
           ●   Stdev Entropy
           ●   Left Mean Entropy - Right Mean Entropy




          h_prob = [ h / histo_sum for h in histogram ]

          entropy =   -sum( [p * math.log(p)
                                 for p in h_prob
                                 if p != 0] )
SVM & Classifing Blobs
● blob size
● color histograms
● entropy of blob (texture)

                   Classify!
Shoot the Squirrel
The Gun
The Turret
Python and Arduino
Arduino Uno

pyserial                                     import serial

                                             arduino = serial.Serial(device, BAUD_RATE)


                                             arduino.write("a")




Project Sentry Gun
https://sites.google.com/site/projectsentrygun/

Python-On-A-Chip
http://code.google.com/p/python-on-a-chip/
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
Next Steps
● Better Optics
● Stronger Firepower
  ○ Laminar water jet
  ○ Pressurized water pump
● Python-On-A-Chip

● Bird Classifier & Counter
Questions?
kgrandis@gmail.com
@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.

Más contenido relacionado

La actualidad más candente

презентація діаграми в Excel
 презентація діаграми в Excel презентація діаграми в Excel
презентація діаграми в Excel
1cana1
 
Електронне навчання
Електронне навчанняЕлектронне навчання
Електронне навчання
OlgaBratischenko
 
вишивка шовковими стрічками
вишивка шовковими  стрічкамивишивка шовковими  стрічками
вишивка шовковими стрічками
Olena Pyzaenko
 
Giao trinh autodesk inventor professional insert
Giao trinh autodesk  inventor professional insertGiao trinh autodesk  inventor professional insert
Giao trinh autodesk inventor professional insert
Trung tâm Advance Cad
 
Single photon 3D Imaging with Deep Sensor Fusion
Single photon 3D Imaging with Deep Sensor FusionSingle photon 3D Imaging with Deep Sensor Fusion
Single photon 3D Imaging with Deep Sensor Fusion
David Lindell
 
засоби автоматизації процесу створення документа
засоби автоматизації процесу створення документазасоби автоматизації процесу створення документа
засоби автоматизації процесу створення документа
Elena Kostesnko
 

La actualidad más candente (20)

Урок 24 для 7 класу - Створення комп’ютерної моделі рівномірного прямолінійно...
Урок 24 для 7 класу - Створення комп’ютерної моделі рівномірного прямолінійно...Урок 24 для 7 класу - Створення комп’ютерної моделі рівномірного прямолінійно...
Урок 24 для 7 класу - Створення комп’ютерної моделі рівномірного прямолінійно...
 
Графіка для веб-середовища
Графіка для веб-середовищаГрафіка для веб-середовища
Графіка для веб-середовища
 
презентація діаграми в Excel
 презентація діаграми в Excel презентація діаграми в Excel
презентація діаграми в Excel
 
6 клас урок 4
6 клас урок 46 клас урок 4
6 клас урок 4
 
Visual cryptography for color images
Visual cryptography for color imagesVisual cryptography for color images
Visual cryptography for color images
 
Урок 1. Поняття комп'ютерної графіки. Растрові зображення, їхні властивості.
Урок 1. Поняття комп'ютерної графіки. Растрові зображення, їхні властивості.Урок 1. Поняття комп'ютерної графіки. Растрові зображення, їхні властивості.
Урок 1. Поняття комп'ютерної графіки. Растрові зображення, їхні властивості.
 
10 клас 15 урок. Поняття про мультимедійні дані та їх опрацювання.
10 клас 15 урок. Поняття про мультимедійні дані та їх опрацювання.10 клас 15 урок. Поняття про мультимедійні дані та їх опрацювання.
10 клас 15 урок. Поняття про мультимедійні дані та їх опрацювання.
 
Електронне навчання
Електронне навчанняЕлектронне навчання
Електронне навчання
 
вишивка шовковими стрічками
вишивка шовковими  стрічкамивишивка шовковими  стрічками
вишивка шовковими стрічками
 
1.1 Поштова служба Інтернету. Електронна скринька та електронне листування. Е...
1.1 Поштова служба Інтернету. Електронна скринька та електронне листування. Е...1.1 Поштова служба Інтернету. Електронна скринька та електронне листування. Е...
1.1 Поштова служба Інтернету. Електронна скринька та електронне листування. Е...
 
CIFAR-10
CIFAR-10CIFAR-10
CIFAR-10
 
цифрові фотоапарати та основи фотографії
цифрові фотоапарати та основи фотографіїцифрові фотоапарати та основи фотографії
цифрові фотоапарати та основи фотографії
 
Giao trinh autodesk inventor professional insert
Giao trinh autodesk  inventor professional insertGiao trinh autodesk  inventor professional insert
Giao trinh autodesk inventor professional insert
 
Урок 16. Розробка і створення відеофільму
Урок 16. Розробка і створення відеофільмуУрок 16. Розробка і створення відеофільму
Урок 16. Розробка і створення відеофільму
 
векторна і растрова графіка
векторна і растрова графікавекторна і растрова графіка
векторна і растрова графіка
 
Cong nghe cadcam
Cong nghe cadcamCong nghe cadcam
Cong nghe cadcam
 
Ai №8. Штучні нейронні мережі.
Ai №8. Штучні нейронні мережі.Ai №8. Штучні нейронні мережі.
Ai №8. Штучні нейронні мережі.
 
7 клас 4 урок. Практична робота № 1. «Електронне листування з використанням в...
7 клас 4 урок. Практична робота № 1. «Електронне листування з використанням в...7 клас 4 урок. Практична робота № 1. «Електронне листування з використанням в...
7 клас 4 урок. Практична робота № 1. «Електронне листування з використанням в...
 
Single photon 3D Imaging with Deep Sensor Fusion
Single photon 3D Imaging with Deep Sensor FusionSingle photon 3D Imaging with Deep Sensor Fusion
Single photon 3D Imaging with Deep Sensor Fusion
 
засоби автоматизації процесу створення документа
засоби автоматизації процесу створення документазасоби автоматизації процесу створення документа
засоби автоматизації процесу створення документа
 

Destacado

Destacado (8)

Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic Web
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101
 
Face Recognition using OpenCV
Face Recognition using OpenCVFace Recognition using OpenCV
Face Recognition using OpenCV
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learn
 
Java and OWL
Java and OWLJava and OWL
Java and OWL
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 

Similar a PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes

Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009
A Jorge Garcia
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
Edge AI and Vision Alliance
 
20110220 computer vision_eruhimov_lecture02
20110220 computer vision_eruhimov_lecture0220110220 computer vision_eruhimov_lecture02
20110220 computer vision_eruhimov_lecture02
Computer Science Club
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009
tudorprodan
 

Similar a PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes (20)

Simple APIs and innovative documentation
Simple APIs and innovative documentationSimple APIs and innovative documentation
Simple APIs and innovative documentation
 
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate ReptiliansUsing Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
 
People detection in a video
People detection in a videoPeople detection in a video
People detection in a video
 
Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009Seven waystouseturtle pycon2009
Seven waystouseturtle pycon2009
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Concurrency and Python - PyCon MY 2015
Concurrency and Python - PyCon MY 2015Concurrency and Python - PyCon MY 2015
Concurrency and Python - PyCon MY 2015
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
COSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer ToolsCOSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer Tools
 
Jvm profiling under the hood
Jvm profiling under the hoodJvm profiling under the hood
Jvm profiling under the hood
 
20110220 computer vision_eruhimov_lecture02
20110220 computer vision_eruhimov_lecture0220110220 computer vision_eruhimov_lecture02
20110220 computer vision_eruhimov_lecture02
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
 
肉体言語 Tython
肉体言語 Tython肉体言語 Tython
肉体言語 Tython
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
4Developers 2015: Gamedev-grade debugging - Leszek Godlewski
4Developers 2015: Gamedev-grade debugging - Leszek Godlewski4Developers 2015: Gamedev-grade debugging - Leszek Godlewski
4Developers 2015: Gamedev-grade debugging - Leszek Godlewski
 
Anil Thomas - Object recognition
Anil Thomas - Object recognitionAnil Thomas - Object recognition
Anil Thomas - Object recognition
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009
 
Intro
IntroIntro
Intro
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (16)

Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
Italy vs Albania Italy Euro 2024 squad Luciano Spalletti's full team ahead of...
 
Personal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley DennisPersonal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley Dennis
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
 
basketball evolution History Slides.pdf
basketball evolution  History Slides.pdfbasketball evolution  History Slides.pdf
basketball evolution History Slides.pdf
 
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics TradeTechnical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
Technical Data | Sig Sauer Easy6 BDX 1-6x24 | Optics Trade
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar Chart
 
Slovenia Vs Serbia Eurovision odds Slovenia have top.docx
Slovenia Vs Serbia Eurovision odds Slovenia have top.docxSlovenia Vs Serbia Eurovision odds Slovenia have top.docx
Slovenia Vs Serbia Eurovision odds Slovenia have top.docx
 
Cricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdf
 
Spain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docxSpain Vs Italy Spain to be banned from participating in Euro 2024.docx
Spain Vs Italy Spain to be banned from participating in Euro 2024.docx
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
 
Hire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls AgencyHire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
 
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
 
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdfCroatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
 
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call GirlsGenuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
 
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxAlbania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
 

PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes

  • 1. Militarizing Your Backyard With Python: Computer Vision and the Squirrel Hordes Kurt Grandis PyCon 2012
  • 2. Overview ● Background & Goals ● OpenCV ○ Working with Python ● Detecting Squirrels ○ SVMs ○ Squirrely features ● Shooting Squirrels ● Wet Squirrels ● Next Steps
  • 3. The Great Backyard Bird Count http://www.birdsource.org/gbbc/
  • 5. Sentry Water Gun http://wiki.teamfortress.com/wiki/Sentry_Gun
  • 6. System Sensor (Camera) Blob Detection Targeting Shoot the Squirrel Squirrel Detection
  • 7. 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
  • 8. Python & OpenCV ● Support for native Python structures ● Works with numpy ● Efficient data sharing
  • 10. OpenCV import cv cv.NamedWindow("camera raw", 1) capture = cv.CreateCameraCapture(0) img = cv.QueryFrame(capture) cv.ShowImage("camera raw", img) # Convert to Gray Scale gray = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 1) cv.CvtColor(img, gray, cv.CV_BGR2GRAY) # Canny Edge Filter cv.Canny(gray, edges, 50, 200, 3)
  • 11. 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)
  • 14. Support Vector Machines (SVMs) Supervised Learning from svm import * ... Classification c = my_trained_model.predict(vector) Features libsvm http://www.csie.ntu.edu.tw/~cjlin/libsvm/
  • 15. Squirrely Features What is squirrel-ness? ● blob size ● histogram analysis of blob ● entropy of blob (texture)
  • 18. Entropy Measure of randomness Calculate entropy for regions of the blob ● Overall Entropy ● Stdev Entropy ● Left Mean Entropy - Right Mean Entropy h_prob = [ h / histo_sum for h in histogram ] entropy = -sum( [p * math.log(p) for p in h_prob if p != 0] )
  • 19. SVM & Classifing Blobs ● blob size ● color histograms ● entropy of blob (texture) Classify!
  • 23. Python and Arduino Arduino Uno pyserial import serial arduino = serial.Serial(device, BAUD_RATE) arduino.write("a") Project Sentry Gun https://sites.google.com/site/projectsentrygun/ Python-On-A-Chip http://code.google.com/p/python-on-a-chip/
  • 24. 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
  • 25.
  • 26. Next Steps ● Better Optics ● Stronger Firepower ○ Laminar water jet ○ Pressurized water pump ● Python-On-A-Chip ● Bird Classifier & Counter
  • 27. Questions? kgrandis@gmail.com @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.