Esempio n. 1
0
 def projectKeyframes(self, keyframes):
     E0, E1 = self.E
     for kf in progressinfo(keyframes.values()):
         Pc = kf['pos']
         # get 2 projected points on wall from this keyframe
         projections = []
         for pt in kf['points']:
             if int(pt['level']) > 0:
                 continue
             Pm = pt['pos']
             Pp, props = self.projectPointToWall(Pc, Pm)
             if not (props['forward_proj'] and props['on_wall']):
                 continue
             # get indices on wallimg and kfimg
             wallind = self.indicesFromLambdaZ(props['lambda_wall'], Pp[2])
             kfind = pt['imgpos']
             # get extra parameters that can serve as cost
             projcost = abs(1 - props['lambda_line'])
             angle = self.angleWithNormal(Pc, Pp)
             if abs(angle) > np.pi / 2:
                 #print "warning: keyframe behind wall"
                 continue
             projections.append([wallind, kfind, projcost, angle])
         # get keyframe data
         kfimg = Image.open(kf['img'])
         kfimg = array(kfimg)  # from Image to 2D array
         # project keyframe on wall
         self.projectKeyframe(kfimg, projections)
Esempio n. 2
0
 def createFillableArea(self):
     M, N = self.MN
     self.fillableArea = []
     for i in progressinfo(range(M)):
         for j in range(N):
             self.fillableArea.append(array([i, j]))
     self.fillableArea = array(self.fillableArea, dtype=np.int32)
Esempio n. 3
0
 def projectKeyframes(self, keyframes):
     for kf in progressinfo(keyframes.values()):
         Pc = kf['pos']
         # get 2 projected points on floor from this keyframe
         projections = []
         for pt in kf['points']:
             if int(pt['level']) > 0:
                 continue
             Pm = pt['pos']
             Pp, props = self.projectPointToFloor(Pc, Pm)
             if not (props['forward_proj'] and props['between_walls']):
                 continue
             floorind = self.indicesFromP(Pp)
             kfind = pt['imgpos']
             angle = self.angleWithNormal(Pc, Pp)
             #assert abs(angle) < np.pi/2, "keyframe under floor"
             projections.append(
                 [floorind, kfind,
                  abs(1 - props['lambda_line']), angle])
         # get keyframe data
         kfimg = Image.open(kf['img'])
         kfimg = array(kfimg)  # from Image to 2D array
         # project keyframe on floor
         self.projectKeyframe(kfimg, projections)
Esempio n. 4
0
E = vstack((E1, E2))
margin = 4 * L.sigma
vals = E[:, 0]
xmin = vals.min() - margin
xmax = vals.max() + margin
vals = E[:, 1]
ymin = vals.min() - margin
ymax = vals.max() + margin
# XY vals
N = 30
X = arange(xmin, xmax, (xmax - xmin) / N)
Y = arange(ymin, ymax, (ymax - ymin) / N)
X, Y = meshgrid(X, Y)
Z = zeros(X.shape)
print "calculating probabilities..."
for row, (xrow, yrow) in enumerate(progressinfo(zip(X, Y))):
    for col, (x, y) in enumerate(zip(xrow, yrow)):
        Z[row, col] = L.Prob([x, y])
#cmap = cm.gray_r # black&white
cmap = cm.jet  # color
surf = ax.plot_surface(X,
                       Y,
                       Z,
                       rstride=1,
                       cstride=1,
                       cmap=cmap,
                       linewidth=0,
                       antialiased=False)
# unknown
ax.w_zaxis.set_major_locator(LinearLocator(6))
# colorbar
Esempio n. 5
0
def gridfill(X, Y, f):
    Z = zeros(X.shape)
    for row, (xrow, yrow) in enumerate(progressinfo(zip(X, Y))):
        for col, (x,y) in enumerate(zip(xrow, yrow)):
            Z[row, col] = f([x,y])
    return Z*(xmax-xmin)
Esempio n. 6
0
# 3D plot init
fig = plt.figure()
ax = fig.gca(projection='3d')
# lims
E = vstack((E1, E2))
margin = 4*L.sigma
vals = E[:,0]; xmin=vals.min()-margin; xmax=vals.max()+margin
vals = E[:,1]; ymin=vals.min()-margin; ymax=vals.max()+margin
# XY vals
N = 30
X = arange(xmin, xmax, (xmax-xmin)/N)
Y = arange(ymin, ymax, (ymax-ymin)/N)
X, Y = meshgrid(X, Y)
Z = zeros(X.shape)
print "calculating probabilities..."
for row, (xrow, yrow) in enumerate(progressinfo(zip(X, Y))):
    for col, (x,y) in enumerate(zip(xrow, yrow)):
        Z[row, col] = L.Prob([x,y])
#cmap = cm.gray_r # black&white
cmap = cm.jet # color
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cmap, linewidth=0, antialiased=False)
# unknown
ax.w_zaxis.set_major_locator(LinearLocator(6))
# colorbar
#fig.colorbar(surf, shrink=0.5, aspect=5)
# set view
ax.view_init(elev=47, azim=-69)
xlabel('x (m)', fontsize=20)
ylabel('y (m)', fontsize=20)
fig.suptitle('Prob[(x,y)]', fontsize=30)
plt.show()
Esempio n. 7
0

def create_fillable_area(walls, (M,N)):
    ### plot walls
    #import pylab as pl
    #for w in walls:
    #    x,y = pl.array(w).T
    #    pl.plot(x,y, '.-')
    #pl.show()

    ### define polygon ###
    poly = Poly(name='room', edges=[Edge(a=Pt(x=x1, y=y1), b=Pt(x=x2, y=y2)) for ((x1,y1),(x2,y2)) in walls])
    
    ### check if inside ###
    fillableArea = []
    for i in progressinfo(range(M)):
        for j in range(N):
            if ispointinside(Pt(i,j), poly):
                fillableArea.append([i,j])
    return np.array(fillableArea)

def point_inside_area(walls, (i,j)):
    poly = Poly(name='room', edges=[Edge(a=Pt(x=x1, y=y1), b=Pt(x=x2, y=y2)) for ((x1,y1),(x2,y2)) in walls])
    return ispointinside(Pt(i,j), poly)

def rayintersectseg(p, edge):
    ''' takes a point p=Pt() and an edge of two endpoints a,b=Pt() of a line segment returns boolean
    '''
    a,b = edge
    if a.y > b.y:
        a,b = b,a