comparison scripts/init-tracking.py @ 1102:cdf1773ba89e

corrected bug
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 27 Feb 2019 16:28:08 -0500
parents cc5cb04b04b0
children
comparison
equal deleted inserted replaced
1101:e23828659a66 1102:cdf1773ba89e
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 import sys, argparse, os.path 3 import sys, argparse, os.path
4 from shutil import copy 4 from shutil import copy
5 5
6 from cvutils import getImagesFromVideo 6 from trafficintelligence.cvutils import getImagesFromVideo
7 from matplotlib.pyplot import imsave 7 from matplotlib.pyplot import imsave
8 8
9 from trafficintelligence import storage, utils 9 from trafficintelligence import storage, utils
10 10
11 # could try to guess the video 11 # could try to guess the video
27 sys.exit() 27 sys.exit()
28 else: 28 else:
29 directoryName = matchingPaths[0] 29 directoryName = matchingPaths[0]
30 if directoryName.endswith('/'): 30 if directoryName.endswith('/'):
31 directoryName = directoryName[:-1] 31 directoryName = directoryName[:-1]
32 if os.path.exists(directoryName+'/../tracking.cfg') and not os.path.exists('./tracking.cfg'): 32 if os.path.exists(directoryName+'/tracking.cfg') and not os.path.exists('./tracking.cfg'):
33 f = storage.openCheck(directoryName+'/../tracking.cfg') 33 f = utils.openCheck(directoryName+'/tracking.cfg')
34 out = storage.openCheck('./tracking.cfg', 'w') 34 out = utils.openCheck('./tracking.cfg', 'w')
35 for l in f: 35 for l in f:
36 if 'video-filename' in l: 36 if 'video-filename' in l:
37 tmp = l.split('=') 37 tmp = l.split('=')
38 out.write(tmp[0]+'= '+args.videoFilename+'\n') 38 out.write(tmp[0]+'= '+args.videoFilename+'\n')
39 elif 'database-filename' in l: 39 elif 'database-filename' in l:
42 else: 42 else:
43 out.write(l) 43 out.write(l)
44 f.close() 44 f.close()
45 out.close() 45 out.close()
46 print('Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted') 46 print('Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted')
47 if os.path.exists(directoryName+'/../classifier.cfg') and not os.path.exists('./classifier.cfg'): 47 if os.path.exists(directoryName+'/classifier.cfg') and not os.path.exists('./classifier.cfg'):
48 copy(directoryName+'/../classifier.cfg', 'classifier.cfg') 48 copy(directoryName+'/classifier.cfg', 'classifier.cfg')
49 print('Configuration file classifier.cfg successfully copied to the current directory') 49 print('Configuration file classifier.cfg successfully copied to the current directory')
50 50
51 # extract image from video 51 # extract image from video
52 if args.nFrames is not None: 52 if args.nFrames is not None:
53 image = getImagesFromVideo(args.videoFilename, 0, args.nFrames, saveImage = True, outputPrefix = 'frame') 53 image = getImagesFromVideo(args.videoFilename, 0, args.nFrames, saveImage = True, outputPrefix = 'frame')