Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Seeing with Python - PyCon SG 2014

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Seeing with Python - PyCon SG 2014

Computer Vision using Python

Avatar for Mark Rees

Mark Rees

June 21, 2014

Other Decks in Technology

Transcript

  1. What is Computer Vision – 1980’s   Then  it  was

     called  Machine  Vision     "the  automa4c  acquisi4on  and  analysis  of  images  to   obtain  desired  data  for  interpre4ng   a  scene  or  controlling  an  ac4vity"  (Schaffer,  1984).                    cnt                  dw            $0000                  src                  dw            $0000                  dst                  dw            $0000                      memcpy            public                                          ldab        cnt+1              ;Set  B  =  cnt.L                                          beq          check              ;If  cnt.L=0,  goto  check                  loop                ldx          src                  ;Set  IX  =  src                                          ldaa        ix                    ;Load  A  from  (src)                                          inx                                  ;Set  src  =  src+1                                          stx          src                                          ldx          dst                  ;Set  IX  =  dst                                          staa        ix                    ;Store  A  to  (dst)                                          inx                                  ;Set  dst  =  dst+1                                          stx          dst                                          decb                                ;Decr  B                                          bne          loop                ;Repeat  the  loop                                          stab        cnt+1              ;Set  cnt.L  =  0                  check              tst          cnt+0              ;If  cnt.H=0,                                          beq          done                ;Then  quit                                          dec          cnt+0              ;Decr  cnt.H                                          decb                                ;Decr  B                                          bra          loop                ;Repeat  the  loop                  done                rts                                  ;Return  
  2. What is Computer Vision - 2014   “Computer  vision  is

     a  field  that  includes  methods  for  acquiring,   processing,  analyzing,  and  understanding  images  and,  in  general,  high-­‐ dimensional  data  from  the  real  world  in  order  to  produce  numerical  or   symbolic  informa4on,  e.g.,  in  the  forms  of  decisions.  A  theme  in  the   development  of  this  field  has  been  to  duplicate  the  abili4es  of  human   vision  by  electronically  perceiving  and  understanding  an  image.  This   image  understanding  can  be  seen  as  the  disentangling  of  symbolic   informa4on  from  image  data  using  models  constructed  with  the  aid  of   geometry,  physics,  sta4s4cs,  and  learning  theory.  Computer  vision  has   also  been  described  as  the  enterprise  of  automa4ng  and  integra4ng  a   wide  range  of  processes  and  representa4ons  for  vision   percep4on.”  (Wikipedia  2014  h^p://en.wikipedia.org/wiki/Computer_Vision)  
  3. CV is a lot more than grabbing an image  

    CV   Object   Illumina4on   Image   Capture   Sensors/ Cameras   Digi4sa4on/ Conversion   Image   Processing   Algorithm   Development   Implementa4on   Display  Control  
  4. Python Imaging Library   Pillow  –  The  friendly  PIL  fork

     python  2.6+,  3.2+   h^p://python-­‐pillow.github.io/   PIL  –  The  “original”  PIL  python  1.52+,  2.0+     last  release  11/2009     h^p://eiot.org/downloads   Demo:  PIL.ipynb  
  5. Scipy ndimage   N  dimensional  array  image  processing    

    h^p://docs.scipy.org/doc/scipy/reference/ndimage.html   Demo:  Mul4-­‐demensional  image  processing.ipynb  
  6. SimpleCV   SimpleCV  is  an  open  source  framework  for  building

      computer  vision  applica4ons.  With  it,  you  get  access  to   several  high-­‐powered  computer  vision  libraries  such  as   OpenCV  –  without  having  to  first  learn  about  bit  depths,   file  formats,  color  spaces,  buffer  management,   eigenvalues,  or  matrix  versus  bitmap  storage.     h^p://simplecv.org/   Demo:  SimpleCV  -­‐  The  Basics.ipynb   Pygame  dependency  caused  me  some  problems   Not  all  image  manipula4on  worked  in  ipython.  Simplecv   shell  is  where  all  func4onality  works.  
  7. PyOpenCV   Official  python  wrapper  for  OpenCV  C/C++  libraries  

    Two  namespaces  cv  &  cv2.  Use  cv2,  cv  deprecated   Basis  of  SimpleCV  and  other  python  CV  libraries   Demo:  OpenCV  -­‐  The  Basics.ipynb   Demo:  OpenCV  Mo4on  Detec4on.ipynb   Demo:  OpenCV  Face  Detec4on.ipynb  
  8. Raspberry Pi CV   OpenCV  available  but  USB  cameras  slow

      Rpi  camera  faster,  uses  GPU,  doesn’t  work  with  OpenCV   apt-­‐get  install  python-­‐picamera  solves  that.   h^p://picamera.readthedocs.org/en/release-­‐1.5/    
  9. Resources   h^p://www.packtpub.com/opencv-­‐computer-­‐ vision-­‐with-­‐python/book   h^p://programmingcomputervision.com/   There  also  is

     a  Python  CV  module  PCV   h^p://szeliski.org/Book/   Computer  Vision:  Algorithms  and  Applica4ons