Mercurial Hosting > traffic-intelligence
comparison scripts/init_tracking.py @ 747:d45ab817ee11 dev
added script to initialize tracking (copying and setting up basic files)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 02 Oct 2015 11:29:43 -0400 |
parents | |
children | 2faabcbde2c4 |
comparison
equal
deleted
inserted
replaced
745:3d0321abb564 | 747:d45ab817ee11 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 import sys, argparse, os.path, storage, utils | |
4 from cvutils import getImagesFromVideo | |
5 from matplotlib.pyplot import imsave | |
6 | |
7 # could try to guess the video | |
8 # check if there is already a tracking.cfg file | |
9 | |
10 parser = argparse.ArgumentParser(description='The program initilizes the files for tracking: copy tracking.cfg, sets up with the video filename, generates a frame image (frame.png) and prints the next commands') | |
11 | |
12 parser.add_argument('-i', dest = 'videoFilename', help = 'filename of the video sequence', required = True) | |
13 | |
14 args = parser.parse_args() | |
15 | |
16 # assumes tracking.cfg is in the parent directory to the directory of the traffic intelligence python modules | |
17 matchingPaths = [s for s in sys.path if 'traffic-intelligence' in s] | |
18 #if len(matchingPaths) > 1: | |
19 # print('Too many matching paths for Traffic Intelligence modules: {}'.format(matchingPaths)) | |
20 if len(matchingPaths) == 0: | |
21 print('No environment path to Traffic Intelligence modules.\nExiting') | |
22 sys.exit() | |
23 else: | |
24 directoryName = matchingPaths[0] | |
25 if directoryName.endswith('/'): | |
26 directoryName = directoryName[:-1] | |
27 if os.path.exists(directoryName+'/../tracking.cfg') and not os.path.exists('./tracking.cfg'): | |
28 f = storage.openCheck(directoryName+'/../tracking.cfg') | |
29 out = storage.openCheck('./tracking.cfg', 'w') | |
30 for l in f: | |
31 if 'video-filename' in l: | |
32 tmp = l.split('=') | |
33 out.write(tmp[0]+'= '+args.videoFilename+'\n') | |
34 elif 'database-filename' in l: | |
35 tmp = l.split('=') | |
36 out.write(tmp[0]+'= '+utils.removeExtension(args.videoFilename)+'.sqlite\n') | |
37 else: | |
38 out.write(l) | |
39 f.close() | |
40 out.close() | |
41 print('Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted') | |
42 | |
43 # extract image from video | |
44 image = getImagesFromVideo(args.videoFilename, saveImage = True, outputPrefix = 'frame') | |
45 print('first video frame successfully copied to the current directory') | |
46 | |
47 # next commands | |
48 print('--------------------------------------\nHere are a sample of the next command to compute the homography,\ntrack features, group them in objects and display object trajectories\n--------------------------------------') | |
49 print('compute_homography -i [frame.png] -w [world_image] -n [npoints] -u [unit_per_pixel]') | |
50 print('feature-based-tracking tracking.cfg --tf') | |
51 print('feature-based-tracking tracking.cfg --gf') | |
52 print('display-trajectories --cfg tracking.cfg -t object') |