Python simplecv

Post on 25-May-2015

3.659 views 0 download

Transcript of Python simplecv

Uma Introdução a Computer Vision

Gustavo Pinto@gustavopinto

@gustavopinto

voltando alguns meses atrás

ainda em

2012

Computer Vision Made Easy

Gustavo Pintowww.entropie.com.br

Computer Vision Made Easy

Gustavo Pintowww.entropie.com.br

Reconhece essa imagem?

Reconhece essa imagem?

Ela é *a* original?

E essa?

E essa? Como você sabe?

E essa? Como você sabe?

E essa? Como você sabe?

how to code?

Pixel

Pixel

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

Pixel (231, 0, 14)

Pixel (231, 0, 14)

R, G, B

[0..255]

R, G, B

Pixel (231, 0, 14)

[0..255]

R, G, B

Pixel (231, 0, 14)

....

logo...

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

=

E se...

- = x

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

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]]]

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]]]

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?

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]]]

x.show()

=-

=-

75.88 61.04 27.57

=-

75.88 61.04 27.57

if x >= threshold :-x =

print "fake"

if x >= threshold :-x =

print "fake"

Como criar esse código?

Enabling Computers to See

● 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, ...

What is Computer Vision?

What is Computer Vision?

What is Computer Vision?

acquire

process

analyze

This is computer vision made easy!

Primeiro Problema

2004

Primeiro Problema

2004

Primeiro Problema

2004

Primeiro Problema

2004

Vou criar um script pra

redimensionar..

Primeiro Problema

Primeiro Problema

Primeiro Problema

Primeiro Problemaimgs = ImageSet(image_dir)

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

Primeiro Problemaimgs = ImageSet(image_dir)

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

Primeiro Problemaimgs = ImageSet(image_dir)

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

Primeiro Problemaimgs = ImageSet(image_dir)

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

Primeiro Problemaimgs = ImageSet(image_dir)

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

Esse cara sou eu..

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

Outras features

original original * 5original / 5

Outras features

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

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

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

Segundo Problema

Quem mexeu no meu sorvete?

Quem mexeu no meu sorvete?

Quem mexeu no meu sorvete?

++

++

=Como eu vejo

++

=Como realmente é

cam = Camera()cam.live()

cam = Camera()cam.live()

cam = Camera()cam.live()

cam = Camera()while True:

cam.getImage().show()

cam = Camera()cam.live()

cam = Camera()while True:

cam.getImage().show()

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

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

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)

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

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

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

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

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

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

Terceiro Problema

Identificando Imagens

Template Machingsearch for instances in a image

.findTemplate( )

.findTemplate( )

matches.draw()

.findTemplate( )

.findTemplate( )

matches.draw()

Key Point Template Maching

search for keypoints

.findkeypointMatch( )

.findkeypointMatch( )

.findkeypoints().draw()

.findkeypointMatch( )

matches.draw()

Haar Like Featuresclassify more generic objects

● Face● Perfil● Olhos● Orelhas● Óculos

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

● Face● Perfil● Olhos● Boca● Nariz

● Face● Perfil● Olhos● Boca● Nariz

● Face● Perfil● Olhos● Boca● Nariz

Haar-like Features

!=Face

Recognition

Sim, e dai?

mustacheinator.py

https://gist.github.com/4685584

Problema Bónus

Problema Bónus

Problema Bónus

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

print barcode[0].data