Python simplecv

94
Uma Introdução a Computer Vision Gustavo Pinto @gustavopinto

Transcript of Python simplecv

Page 1: Python simplecv

Uma Introdução a Computer Vision

Gustavo Pinto@gustavopinto

Page 2: Python simplecv

@gustavopinto

Page 3: Python simplecv

voltando alguns meses atrás

Page 4: Python simplecv

ainda em

2012

Page 5: Python simplecv
Page 6: Python simplecv
Page 7: Python simplecv
Page 8: Python simplecv
Page 9: Python simplecv

Computer Vision Made Easy

Gustavo Pintowww.entropie.com.br

Page 10: Python simplecv

Computer Vision Made Easy

Gustavo Pintowww.entropie.com.br

Page 11: Python simplecv

Reconhece essa imagem?

Page 12: Python simplecv

Reconhece essa imagem?

Ela é *a* original?

Page 13: Python simplecv

E essa?

Page 14: Python simplecv

E essa? Como você sabe?

Page 15: Python simplecv

E essa? Como você sabe?

Page 16: Python simplecv

E essa? Como você sabe?

how to code?

Page 17: Python simplecv
Page 18: Python simplecv
Page 19: Python simplecv

Pixel

Page 20: Python simplecv

Pixel

r, g, b = monalisa[10, 0]r = 231g = 0b = 41

Page 21: Python simplecv

Pixel (231, 0, 14)

Page 22: Python simplecv

Pixel (231, 0, 14)

R, G, B

Page 23: Python simplecv

[0..255]

R, G, B

Pixel (231, 0, 14)

Page 24: Python simplecv

[0..255]

R, G, B

Pixel (231, 0, 14)

....

Page 25: Python simplecv

logo...

[[ 8, 0, 0], [10, 0, 0], [ 7, 0, 0], ..., [ 0, 3, 0], [ 0, 2, 0], [ 0, 2, 1]]]

=

Page 26: Python simplecv

E se...

- = x

Page 27: Python simplecv

E se...

[[ 8 0 0] [10 0 0] [ 7 0 0] ..., [ 0 3 0] [ 0 2 0] [ 0 2 1]]]

- [[ 2 0 0] [ 2 0 0] [ 1 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 14]]

= x

Page 28: Python simplecv

logo:

[[ 8 0 0] [10 0 0] [ 7 0 0] ..., [ 0 3 0] [ 0 2 0] [ 0 2 1]]]

- [[ 2 0 0] [ 2 0 0] [ 1 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 14]]

= [[ -6 0 0] [ -8 0 0] [ -6 0 0] ..., [ 0 -3 0] [ 0 -2 0] [ 0 -2 13]]]

Page 29: Python simplecv

logo:

[[ 8 0 0] [10 0 0] [ 7 0 0] ..., [ 0 3 0] [ 0 2 0] [ 0 2 1]]]

- [[ 2 0 0] [ 2 0 0] [ 1 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 14]]

= [[ -6 0 0] [ -8 0 0] [ -6 0 0] ..., [ 0 -3 0] [ 0 -2 0] [ 0 -2 13]]]

Page 30: Python simplecv

logo:

[[ 8 0 0] [10 0 0] [ 7 0 0] ..., [ 0 3 0] [ 0 2 0] [ 0 2 1]]]

- [[ 2 0 0] [ 2 0 0] [ 1 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 14]]

= [[ -6 0 0] [ -8 0 0] [ -6 0 0] ..., [ 0 -3 0] [ 0 -2 0] [ 0 -2 13]]]

Então não existe cor negativa?

Page 31: Python simplecv

logo:

[[ 8 0 0] [10 0 0] [ 7 0 0] ..., [ 0 3 0] [ 0 2 0] [ 0 2 1]]]

- [[ 2 0 0] [ 2 0 0] [ 1 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 14]]

= [[ 0 0 0] [ 0 0 0] [ 0 0 0] ..., [ 0 0 0] [ 0 0 0] [ 0 0 13]]]

Page 32: Python simplecv

x.show()

Page 33: Python simplecv

=-

Page 34: Python simplecv

=-

75.88 61.04 27.57

Page 35: Python simplecv

=-

75.88 61.04 27.57

Page 36: Python simplecv

if x >= threshold :-x =

print "fake"

Page 37: Python simplecv

if x >= threshold :-x =

print "fake"

Page 38: Python simplecv

Como criar esse código?

Page 39: Python simplecv

Enabling Computers to See

Page 40: Python simplecv

● Open source● Escrito em Python● Integrado com iPython● Excelente para

○ manipulação de imagens○ conversão de formatos○ detecção de features

● Captura imagens de streams○ kinect, webcams, IP Cams, ...

Page 41: Python simplecv

What is Computer Vision?

Page 42: Python simplecv

What is Computer Vision?

Page 43: Python simplecv

What is Computer Vision?

acquire

process

analyze

Page 44: Python simplecv

This is computer vision made easy!

Page 45: Python simplecv

Primeiro Problema

2004

Page 46: Python simplecv

Primeiro Problema

2004

Page 47: Python simplecv

Primeiro Problema

2004

Page 48: Python simplecv

Primeiro Problema

2004

Vou criar um script pra

redimensionar..

Page 49: Python simplecv

Primeiro Problema

Page 50: Python simplecv

Primeiro Problema

Page 51: Python simplecv

Primeiro Problema

Page 52: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

Page 53: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

Page 54: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

Page 55: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

Page 56: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

Esse cara sou eu..

Page 57: Python simplecv

Primeiro Problemaimgs = ImageSet(image_dir)

for img in imgs: img = img.resize(w=x, h=y) img.save()

http://simplecv.org/docs/SimpleCV.html

150+ methods

Page 58: Python simplecv

Outras features

original original * 5original / 5

Page 59: Python simplecv

Outras features

img.crop(50,40,100, 100)

rotate(73., point=(img.width/2,img.height/2))

img.binarize() img.binarize().invert()

Page 60: Python simplecv

Segundo Problema

Quem mexeu no meu sorvete?

Page 61: Python simplecv

Quem mexeu no meu sorvete?

Page 62: Python simplecv

Quem mexeu no meu sorvete?

Page 63: Python simplecv

++

Page 64: Python simplecv

++

=Como eu vejo

Page 65: Python simplecv

++

=Como realmente é

Page 66: Python simplecv

cam = Camera()cam.live()

Page 67: Python simplecv

cam = Camera()cam.live()

Page 68: Python simplecv

cam = Camera()cam.live()

cam = Camera()while True:

cam.getImage().show()

Page 69: Python simplecv

cam = Camera()cam.live()

cam = Camera()while True:

cam.getImage().show()

cam = Camera()disp = Display()while disp.isNotDone():

img = cam.getImage()img.save(disp)

Page 70: Python simplecv

cam = Camera()cam.live()

cam = Camera()while True:

cam.getImage().show()

cam = JpegStreamReader(device)disp = Display()while disp.isNotDone():

img = cam.getImage()img.save(disp)

Page 71: Python simplecv

cam = JpegStreamReader(device)disp = Display()previous = cam.getImage()while disp.isNotDone():

current = cam.getImage()diff = current - previous

if diff.getNumpy().mean() > threshold:estaoMexendoNaGeladeira(current)

Page 72: Python simplecv

cam = JpegStreamReader(device)disp = Display()previous = cam.getImage()while disp.isNotDone():

current = cam.getImage()diff = current - previous

if diff.getNumpy().mean() > threshold:postAtFacebook(current)

Page 73: Python simplecv

Terceiro Problema

Identificando Imagens

Page 74: Python simplecv

Template Machingsearch for instances in a image

Page 75: Python simplecv
Page 76: Python simplecv

.findTemplate( )

Page 77: Python simplecv

.findTemplate( )

matches.draw()

Page 78: Python simplecv

.findTemplate( )

Page 79: Python simplecv

.findTemplate( )

matches.draw()

Page 80: Python simplecv

Key Point Template Maching

search for keypoints

Page 81: Python simplecv

.findkeypointMatch( )

Page 82: Python simplecv

.findkeypointMatch( )

.findkeypoints().draw()

Page 83: Python simplecv

.findkeypointMatch( )

matches.draw()

Page 84: Python simplecv

Haar Like Featuresclassify more generic objects

Page 85: Python simplecv

● Face● Perfil● Olhos● Orelhas● Óculos

img.findHaarFeatures('face')[-1].draw()

Page 86: Python simplecv

● Face● Perfil● Olhos● Boca● Nariz

Page 87: Python simplecv

● Face● Perfil● Olhos● Boca● Nariz

Page 88: Python simplecv

● Face● Perfil● Olhos● Boca● Nariz

Page 89: Python simplecv

Haar-like Features

!=Face

Recognition

Page 90: Python simplecv

Sim, e dai?

Page 91: Python simplecv

mustacheinator.py

https://gist.github.com/4685584

Page 92: Python simplecv

Problema Bónus

Page 93: Python simplecv

Problema Bónus

Page 94: Python simplecv

Problema Bónus

barcode = img.findBarcode()if barcode is not None:

print barcode[0].data