Created
November 23, 2013 04:05
-
-
Save pmarkun/7610660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import scipy | |
| import pylab | |
| from scipy import ndimage | |
| import mahotas | |
| import math | |
| from SimpleCV import Camera, Image | |
| def calcula_percento(objeto, valor_referencia): | |
| if objeto['h'] >= valor_referencia*0.5: | |
| return 10 | |
| elif objeto['w'] <= valor_referencia*0.5: | |
| return 0.1 #calcular varios juntos | |
| else: | |
| return 1 | |
| # Initialize the camera | |
| cam = Camera(0) | |
| # Loop to continuously get images | |
| while True: | |
| # Get Image from camera | |
| img = cam.getImage() | |
| #img = img.crop(50,50,img.width-50,img.height-50, smart=True) | |
| # Make image black and white | |
| img = img.blur().invert() | |
| blured = mahotas.thresholding.otsu(img.getNumpy()) | |
| img = img.threshold(blured) | |
| img.show() | |
| labeled,nr_objects = ndimage.label(img.getNumpy() > blured) | |
| print nr_objects | |
| objetos = ndimage.find_objects(labeled) | |
| md = [] | |
| for objeto in objetos: | |
| o = {} | |
| o['h'] = objeto[0].stop - objeto[0].start | |
| o['w'] = objeto[1].stop - objeto[1].start | |
| o['area'] = o['h']*o['w'] | |
| if (o['h'] > o['w']): | |
| w = o['h'] | |
| h = o['w'] | |
| o['h'] = h | |
| o['w'] = w | |
| md.append(o) | |
| print md | |
| total = 0 | |
| for objeto in md: | |
| total += calcula_percento(objeto, 117) | |
| print total-10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment