Created
May 9, 2013 05:37
-
-
Save alejandroave/5545769 to your computer and use it in GitHub Desktop.
This file contains 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
def union(imagen,cord): | |
ancho,altura,pixels,im = cargar(imagen) | |
ancho1,altura1,pixels1,im1 = cargar("esquina.png") | |
pro = [] | |
draw = ImageDraw.Draw(im1) | |
#pro.append((0,0)) | |
visitados = [] | |
pintar = [] | |
visitados = [] | |
cont = 1 | |
total = 0 | |
#cord = [] | |
print "iniciando bfs" | |
a,b,c = random.randint(1, 255),random.randint(1, 255),random.randint(1, 255) | |
for q in range(altura): | |
visitados.append([]) | |
for w in range(ancho): | |
total += 1 | |
if pixels[w,q] == (255,255,255): | |
visitados[q].append(0) | |
if cont == 1: | |
pro.append((w,q)) | |
cont = 0 | |
print "seleccionando uno :P" | |
else: | |
visitados[q].append(1) | |
#identp = 0 | |
union = [] | |
print "valores de las esquinas",cord | |
while len(pro) > 0: | |
x = pro[len(pro)-1][0] | |
y = pro[len(pro)-1][1] | |
pro.pop(len(pro)-1) | |
###################### | |
try: | |
l = cord.index((x,y)) | |
identp = 1 | |
union.append((x,y)) | |
print "esquina encontrada" | |
except: | |
pass | |
for i in range(-1,2): | |
for j in range(-1,2): | |
if x+j >= 0 and y+i >=0 and x+j <ancho and y+i <altura: | |
if visitados[y+i][x+j] == 0: | |
if i == 0 and j == 0: | |
cosa = 0 | |
else: | |
if pixels[x,y][1] == pixels[x+j,y+i][1]: | |
pro.append((x+j,y+i)) | |
visitados[y+i][x+j] = 1 | |
pixels[x,y] = (a,b,c) | |
visitados[y][x]= 1 | |
cont += 1 | |
if len(pro) == 0: | |
y,x = chekar(visitados,ancho,altura) | |
prom = (cont*100)/(total) | |
print "Porcentaje del objeto: ",prom,"%" | |
cont = 0 | |
#print "union :",union | |
#union.append(union[0]) | |
print "union :",union | |
draw.line(union, fill=500) | |
union = [] | |
if x == 0 and y == 0: | |
cosa = 1 | |
else: | |
pro.append((x,y)) | |
a,b,c = random.randint(1, 255),random.randint(1, 255),random.randint(1, 255) | |
im1.save("union.png") | |
im.save("bfs.png") | |
print "termino" | |
return pygame.image.load("union.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment