En esta actividad teniamos que encontrar los convex hull de cada una de las figuras en una imagen para esto yo utilice el algoritmo de jarvis:
Codigo
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 boton_convex(self): | |
img=self.c_convexhull() | |
img = self.cargar_imagen(img) | |
return | |
def turn(self,p1,p2,p3): | |
d= cmp,(0,(p2[0] - p1[0])*(p3[1] - p1[1]) - (p3[0] - p1[0])*(p2[1] - p1[1])) | |
if d==-1: | |
return 'left' | |
else: | |
return 'y' | |
def jarvis(self,c): | |
point = [min(c)] | |
i=0 | |
while True: | |
endpoint= c[0] | |
for j in range(len(c)-1): | |
if endpoint == point[i] or self.turn(c[j],point[i],endpoint)=='left': | |
endpoint=c[j] | |
i +=1 | |
point.append(endpoint) | |
if (endpoint==point[0]): | |
break | |
return point | |
def c_convexhull(self): | |
im=self.boton_convolucion() | |
pixels=im.load() | |
ancho,alto = im.size | |
# canvas.config(width = ancho, height = alto) | |
fondo=(41,170,157) | |
point=[] | |
for i in range(ancho): | |
for j in range(alto): | |
coordenadas=[] | |
origen=(i,j) | |
if pixels[i,j]== (255,255,255): | |
num_pixels,abscisa,ordenada=self.bfs(origen,im,fondo) | |
#print coordenadas | |
for z in range(len(abscisa)): | |
coordenadas.append((abscisa[z],ordenada[z])) | |
print coordenadas | |
point.append(self.jarvis(coordenadas)) | |
print 'salio',point | |
for p in point: | |
for y in p: | |
pixels[y] = (58,196,102) | |
im.save('akkkkki.png') | |
return im |
Como vemos en la imagen en la ezquina de arriba solo colorea uno de los pixeles que tiene el convex hull y no pude encontrar el error :(
NP lab 3 visión.
ResponderEliminarTarea 3 de clase de visión NP.
ResponderEliminarNP lab de líneas.
ResponderEliminar