view trafficintelligence/processing.py @ 1041:fc7c0f38e8a6

added nObjects to MovingObject, with loading/saving
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 04 Jul 2018 16:06:23 -0400
parents c6cf75a2ed08
children 75a6ad604cc5
line wrap: on
line source

#! /usr/bin/env python
'''Algorithms to process trajectories and moving objects'''

import numpy as np

from trafficintelligence import moving

def extractSpeeds(objects, zone):
    speeds = {}
    objectsNotInZone = []
    import matplotlib.nxutils as nx        
    for o in objects:
        inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T)
        if inPolygon.any():
            objspeeds = [o.getVelocityAt(i).norm2() for i in range(int(o.length()-1)) if inPolygon[i]]
            speeds[o.num] = np.mean(objspeeds) # km/h
        else:
            objectsNotInZone.append(o)
    return speeds, objectsNotInZone