Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/init-tracking.py @ 998:933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sun, 27 May 2018 23:22:48 -0400 |
| parents | scripts/init_tracking.py@2faabcbde2c4 |
| children | 16932cefabc1 |
comparison
equal
deleted
inserted
replaced
| 997:4f3387a242a1 | 998:933670761a57 |
|---|---|
| 1 #! /usr/bin/env python3 | |
| 2 | |
| 3 import sys, argparse, os.path, storage, utils | |
| 4 from shutil import copy | |
| 5 from cvutils import getImagesFromVideo | |
| 6 from matplotlib.pyplot import imsave | |
| 7 | |
| 8 # could try to guess the video | |
| 9 # check if there is already a tracking.cfg file | |
| 10 | |
| 11 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') | |
| 12 | |
| 13 parser.add_argument('-i', dest = 'videoFilename', help = 'filename of the video sequence', required = True) | |
| 14 | |
| 15 args = parser.parse_args() | |
| 16 | |
| 17 # assumes tracking.cfg is in the parent directory to the directory of the traffic intelligence python modules | |
| 18 matchingPaths = [s for s in sys.path if 'traffic-intelligence' in s] | |
| 19 #if len(matchingPaths) > 1: | |
| 20 # print('Too many matching paths for Traffic Intelligence modules: {}'.format(matchingPaths)) | |
| 21 if len(matchingPaths) == 0: | |
| 22 print('No environment path to Traffic Intelligence modules.\nExiting') | |
| 23 sys.exit() | |
| 24 else: | |
| 25 directoryName = matchingPaths[0] | |
| 26 if directoryName.endswith('/'): | |
| 27 directoryName = directoryName[:-1] | |
| 28 if os.path.exists(directoryName+'/../tracking.cfg') and not os.path.exists('./tracking.cfg'): | |
| 29 f = storage.openCheck(directoryName+'/../tracking.cfg') | |
| 30 out = storage.openCheck('./tracking.cfg', 'w') | |
| 31 for l in f: | |
| 32 if 'video-filename' in l: | |
| 33 tmp = l.split('=') | |
| 34 out.write(tmp[0]+'= '+args.videoFilename+'\n') | |
| 35 elif 'database-filename' in l: | |
| 36 tmp = l.split('=') | |
| 37 out.write(tmp[0]+'= '+utils.removeExtension(args.videoFilename)+'.sqlite\n') | |
| 38 else: | |
| 39 out.write(l) | |
| 40 f.close() | |
| 41 out.close() | |
| 42 print('Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted') | |
| 43 if os.path.exists(directoryName+'/../classifier.cfg') and not os.path.exists('./classifier.cfg'): | |
| 44 copy(directoryName+'/../classifier.cfg', 'classifier.cfg') | |
| 45 print('Configuration file classifier.cfg successfully copied to the current directory') | |
| 46 | |
| 47 # extract image from video | |
| 48 image = getImagesFromVideo(args.videoFilename, saveImage = True, outputPrefix = 'frame') | |
| 49 print('first video frame successfully copied to the current directory') | |
| 50 | |
| 51 # next commands | |
| 52 print('--------------------------------------\nHere are a sample of the next command to compute the homography,\ntrack features, group them in objects and display object trajectories\n--------------------------------------') | |
| 53 print('compute_homography -i [frame.png] -w [world_image] -n [npoints] -u [unit_per_pixel]') | |
| 54 print('feature-based-tracking tracking.cfg --tf') | |
| 55 print('feature-based-tracking tracking.cfg --gf') | |
| 56 print('display-trajectories --cfg tracking.cfg -t object') |
