Пример #1
0
def tracing():   # extract data from the trace array, removing redundant data for a single frame
    global trace
    frames = []
    coords = []
    tempF = None
    temp = None
    for record in trace:
        if not temp == record[0]:
            if not len(frames) == 0:
                sqlTrack(temp, frames, coords)
                del frames[:]
                del coords[:]
            temp = record[0]
        if not tempF == record[1]:
            tempF = record[1]
            frames.append(tempF)
            point = [record[2], record[3]]
            invH = cvutils.invertHomography(homography)
            coord = cvutils.project(invH, point)
            coords.append([coord[0][0], coord[1][0]])
    sqlTrack(temp, frames, coords)
Пример #2
0
def tracing():
    global trace
    print trace[0][1], trace[len(trace)-1][1]
    frames = []
    coords = []
    tempF = None
    temp = None
    for record in trace:
        if not temp == record[0]:
            if not len(frames) == 0:
                sqlEdit(temp, frames, coords)
                del frames[:]
                del coords[:]
            temp = record[0]
        if not tempF == record[1]:
            tempF = record[1]
            frames.append(tempF)
            point = [record[2], record[3]]
            invH = cvutils.invertHomography(homography)
            coord = cvutils.project(invH, point)
            coords.append([coord[0][0], coord[1][0]])
    sqlEdit(temp, frames, coords)
    print('Usage: {0} <video-filename> <n-objects>'.format(sys.argv[0]))
    sys.exit()

if sys.argv[1].endswith('.avi'):
    videoFilenamePrefix = utils.removeExtension(sys.argv[1],'.')
else:
    videoFilenamePrefix = sys.argv[1]

objectNum = int(sys.argv[2])

objects = ubc_utils.loadTrajectories(videoFilenamePrefix+'-objects.txt', objectNum+1)
obj = objects[objectNum]
features = ubc_utils.loadTrajectories(videoFilenamePrefix+'-features.txt', max(obj.featureNumbers)+1)
h = np.loadtxt(videoFilenamePrefix+'-homography.txt')

invh = cvutils.invertHomography(h)

def computeGroundTrajectory(features, homography, timeInterval = None):
    '''Computes a trajectory for the set of features as the closes point to the ground
    using the homography in image space'''
    if not timeInterval:
        raise Exception('not implemented') # compute from the features
    
    yCoordinates = -np.ones((len(features),int(timeInterval.length())))
    for i,f in enumerate(features):
        traj = f.getPositions().asArray()
        imgTraj = cvutils.projectArray(homography, traj)
        yCoordinates[i,f.getFirstInstant()-timeInterval.first:f.getLastInstant()+1-timeInterval.first] = imgTraj[1,:]

    indices = np.argmax(yCoordinates,0)
    newTraj = moving.Trajectory()
if sys.argv[1].endswith('.avi'):
    videoFilenamePrefix = utils.removeExtension(sys.argv[1], '.')
else:
    videoFilenamePrefix = sys.argv[1]

objectNum = int(sys.argv[2])

objects = ubc_utils.loadTrajectories(videoFilenamePrefix + '-objects.txt',
                                     objectNum + 1)
obj = objects[objectNum]
features = ubc_utils.loadTrajectories(videoFilenamePrefix + '-features.txt',
                                      max(obj.featureNumbers) + 1)
h = np.loadtxt(videoFilenamePrefix + '-homography.txt')

invh = cvutils.invertHomography(h)


def computeGroundTrajectory(features, homography, timeInterval=None):
    '''Computes a trajectory for the set of features as the closes point to the ground
    using the homography in image space'''
    if not timeInterval:
        raise Exception('not implemented')  # compute from the features

    yCoordinates = -np.ones((len(features), int(timeInterval.length())))
    for i, f in enumerate(features):
        traj = f.getPositions().asArray()
        imgTraj = cvutils.projectArray(homography, traj)
        yCoordinates[i,
                     f.getFirstInstant() -
                     timeInterval.first:f.getLastInstant() + 1 -