neuro_dataset.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:event-Python 作者: gorchard 项目源码 文件源码
def apply_tracking1(td, alpha=0.98, threshold=-1):
    """Alternative to stabilization. Compensate for motion of a single "object" by tracking its movement
    The concept is fairly simple:
    0: The tracker starts at the center of the event recording
    1: For each incoming event, calculate its distance to the tracker.
    2: If the distance is less than a threshold then update the tracker location using
    3: tracker_location = tracker_location*alpha + event_location*(1-alpha)

    You may find the tracker is quite erratic because it moves with every incoming event. It may be a good idea to smooth the motion somewhat which would be another step.%

    td: eventvision.Events
    alpha: alpha is a number between 0 and 1. Typically quite high. Default 0.9
    threshold: distance in pixels for the tracker to be updated. Default = 0.5 * height of td
    """
    assert(alpha >= 0)
    assert(alpha <= 1)
    mix = 1 - alpha

    #with timer.Timer() as my_timer:
    track_x = center_x = td.width / 2
    track_y = center_y = td.height / 2
    threshold_sq = math.floor(center_y**2)

    if (threshold > 0):
        threshold_sq = math.floor(threshold**2)

    copy = np.copy(td.data).view(np.recarray)
    for i in range(copy.size):
        datum = copy[i]
        y_val = datum.y
        x_val = datum.x
        distance = (track_x - x_val)**2 + (track_y - y_val)**2

        if (distance <= threshold_sq):
            track_x = track_x * alpha + x_val * mix
            track_y = track_y * alpha + y_val * mix

        datum.y = round(y_val - track_y + center_y)
        datum.x = round(x_val - track_x + center_x)
    #print 'Applying tracker took %s seconds' % my_timer.secs
    # remove the events that are out of bounds
    return copy[(copy.x >= 0) & (copy.y >= 0) & (copy.x < td.width) & (copy.y < td.height)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号