Skip to content

Instantly share code, notes, and snippets.

@rodgomesc
Created July 16, 2014 18:23
Show Gist options
  • Save rodgomesc/b4df7d5fe8fa388df4e2 to your computer and use it in GitHub Desktop.
Save rodgomesc/b4df7d5fe8fa388df4e2 to your computer and use it in GitHub Desktop.
Detector de Moedas
from SimpleCV import *
# A quarter mede 24.26mm
quarterSize = 24.26
# Isto ira manter o ratio entre o tamanho da imagem ao tamanho real do quartzo
sizeRatio = 0
objectSize = 0
img = Image('coins.jpg', sample=True)
segmented = img.hueDistance(Color.BLACK)
coins = img.invert().findBlobs(minsize=200)
#Aqui vamos calcular o fator de escala
if coins:
c = coins[-1]
diameter = c.radius() * 2
sizeRatio = quarterSize / diameter
#Agora vamos imprimir as medicoes de volta na imagem
for coin in coins:
#obter o tamanho fisico da moeda
size = (coin.radius() * 2) * sizeRatio
#rotular a moeda em conformidade
if size > 18 and size < 20:
text = "Tipo: penny"
elif size > 20 and size < 23:
text = "Tipo: nickel"
elif size > 16 and size < 18:
text = "Tipo: dime"
elif size > 23 and size < 26:
text = "Tipo: quarter"
else:
text = "Desconhecido!"
text = text + ", Tamanho:" + str(size) + "mm"
img.drawText(text, coin.x, coin.y)
img.show()
time.sleep(10) #mostra o resultado por 10 segundos na tela
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment