So my problem is a relatively simple one, but still quite hard for a Python rookie like me. So I essentially have a number of shapes in an input image like a bunch of small triangles in a square or so. I need to extract the outer square and each triangle from within the image. I've developed a simple template matching code to do this... but it does not seem to work!
while ( len(numpy.where( b <150 )[0])!=xx):
xx=len(numpy.where( b <150 )[0])
for v in range(len(b)-len(a)):
for w in range(len(b[0])-len(a[0])):
c=b[v:v+len(a[0]),w:w+len(a)]
c.flags.writeable=False
#c=b.reshape(len(a),len(a))
vv=sum(sum(c-a))
#print v, w
if(vv<minval):
minval=vv
xcor=v
ycor=w
print xcor, ycor, minval
print len(numpy.where( b <150 )[0])
print b[xcor:xcor+len(a),ycor:ycor+len(a[0])]
for p in range(xcor,xcor+len(a)):
for q in range(ycor,ycor+len(a[0])):
b.setflags(write=True)
b[p][q]=251;
#print b[xcor:xcor+len(a),ycor:ycor+len(a[0])]
xcorr=0
ycorr=0
minval=99999
The problem is that I need to extract only a simple set of figures, but my code goes on and on... Also, I do not know how to handle the TRIANGLES IN A BOX problem. Can someone please help me out?
By extract, I mean only find out just where the object is placed... if it is placed at all!