Donde detecta parte del círculo y dado un radio de 0.001 (de color verde).
Ahora cuando incremento el tamaño no me lo detecta, doy un radio de 20 (tomando en cuenta que sí es cierto que tomaría como radio pixeles).
Este es el código relevante:
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 deteccionCirculo(r, g, gx, gy, imagen, prop): | |
height, width = imagen.size | |
imagen = imagen.convert('RGB') | |
im = imagen.load() | |
freq = dict() | |
votos = dict() | |
for y in xrange(height): | |
for x in xrange(width): | |
try: | |
red, green, blue = im[y, x] | |
if red == 255 and green == 255 and blue == 255 : | |
if fabs(g[y, x]) > 0.000001: | |
xc = ( x - r * (gx[y, x] / ( g[y, x] * 1.0 )) ) | |
yc = ( y - r * (gy[y, x] / ( g[y, x] * 1.0 )) ) | |
key = "%.0f %.0f"%(xc, yc) | |
votos[(x, y)] = key | |
if key in freq: | |
freq[key] += 1 | |
else: | |
freq[key] = 1 | |
except: | |
print x, y, width, height | |
freq_f = dict() | |
freq = sorted(freq.iteritems(), key=operator.itemgetter(1), reverse=True) | |
k = int(len(freq) * prop) | |
for f in freq: | |
if len(freq_f) <= k: | |
freq_f[f[0]] = f[1] | |
for c in freq_f.keys(): | |
pos = c.split() | |
x = int(pos[0]) | |
y = int(pos[1]) | |
try: | |
im[y, x] = 0,255,0 | |
except: | |
pass | |
for y in xrange(height): | |
for x in xrange(width): | |
if (x, y) in votos: | |
if votos[(x, y)] in freq_f: | |
print "PINTANDO ALGO" | |
im[y, x] = 255,255,0 | |
print "gx: ",gx.shape | |
print "gx matriz: ",gx | |
print "gy: ",gy.shape | |
print "gy matriz: ",gy | |
print "Frecuencias: ",sorted(freq_f.iteritems(), key=operator.itemgetter(1)) | |
data = np.array(imagen) | |
im = Image.fromarray(data) | |
return im |
Pues, primero habría que llegar binarizar lo de bordes para procesar únicamente los pixeles que se clasifican como borde al momento de votar. Luego seguiría la aglomaración de votos para filtrar los centros populares. 2 pts por el avance parcial.
ResponderEliminar