示例#1
0
def compute_feature( reference, frame, radius = 3 ):
  density = 0.0
  feature = np.array( [0.] * FEATURE_LENGTH, dtype = np.float32 )
  sum_ang = 0.0
  sum_mag = 0.0

  for i in xrange( len( frame ) ):
    dist  = momo.distance( frame[i][:2], reference[:2] )
    if dist < radius:
      density += 1
      rel_v = frame[i][2:] - reference[2:]
      rel_x = frame[i][:2] - reference[:2]
      l_v = np.linalg.norm( rel_v )
      l_x = np.linalg.norm( rel_x )
      a = np.dot( rel_v / l_v, rel_x / l_x )
      sum_ang += a
      sum_mag += l_v

  if density > 0:
    feature[dns_i + max_idx( density, DENSITIES )] = 1

    speed = sum_mag / density
    feature[spd_i + max_idx( speed, SPEEDS )] = 1

    angle = sum_ang / density
    feature[dir_i + max_idx( angle, ANGLES )] = 1
  feature[FEATURE_LENGTH - 1] = 1
    
  return feature
示例#2
0
def compute_feature(reference, frame, radius=3):
    density = 0
    feature = np.array([0.0] * FEATURE_LENGTH, dtype=np.float32)
    bin_count = np.zeros((3,), dtype=np.float32)
    bin_sum = np.zeros((3,), dtype=np.float32)

    for i in xrange(len(frame)):
        dist = momo.distance(frame[i][:2], reference[:2])
        if dist < radius:
            density += 1
            rel_v = frame[i][2:] - reference[2:]
            rel_x = frame[i][:2] - reference[:2]
            l_v = np.linalg.norm(rel_v)
            l_x = np.linalg.norm(rel_x)
            a = np.dot(rel_v / l_v, rel_x / l_x)
            i = max_idx(a, ANGLES)
            bin_count[i] += 1
            bin_sum[i] += l_v

    if density > 0:
        feature[max_idx(density, DENSITIES)] = 1
        for angle in xrange(3):
            if bin_count[angle] > 0:
                l = bin_sum[angle] / bin_count[angle]
                feature[3 + angle * 3 + max_idx(l, SPEEDS)] = 1
    feature[FEATURE_LENGTH - 1] = 1
    return feature
示例#3
0
def compute_feature( reference, frame, radius = 3 ):
  density = 0
  avg_velocity = np.array( [0.] * 2 )
  feature = np.array( [0.] * FEATURE_LENGTH, dtype = np.float32 )
  
  for i in xrange( len( frame ) ):
    dist  = momo.distance( frame[i][:2], reference[:2] )
    if dist < radius:
      density += 1
      avg_velocity += frame[i][2:]

  if ( density >= 3 ):
    feature[3] = 1
  else:
    feature[density] = 1

  if density == 0:
    feature[16] = 1
  else:
    avg_velocity /= density
    avg_velocity = reference[2:] - avg_velocity
    avg_velocity[1] = abs( avg_velocity[1] )
    angle = avg_velocity / np.linalg.norm( avg_velocity )
    angle_index = 0
    max_dot = -1
    for i in xrange( 4 ):
      a = np.dot( ANGLES[i], angle )
      if a > max_dot:
        max_dot = a
        angle_index = i
    speed = np.linalg.norm( avg_velocity )
    speed_index = 0;
    for i in xrange( 3 ):
      if speed >= SPEEDS[i]:
       speed_index = i
    feature[4 + angle_index * 3 + speed_index] = 1
  feature[17] = 1
  return feature