Mercurial Hosting > traffic-intelligence
comparison scripts/learn-poi.py @ 787:0a428b449b80 dev
improved script to display over world image
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 17 Mar 2016 16:01:19 -0400 |
parents | 1f2b2d1f4fbf |
children | 180b6b0231c0 |
comparison
equal
deleted
inserted
replaced
786:1f2b2d1f4fbf | 787:0a428b449b80 |
---|---|
11 parser = argparse.ArgumentParser(description='The program learns and displays Gaussians fit to beginnings and ends of object trajectories (based on Mohamed Gomaa Mohamed 2015 PhD). TODO: save the data') | 11 parser = argparse.ArgumentParser(description='The program learns and displays Gaussians fit to beginnings and ends of object trajectories (based on Mohamed Gomaa Mohamed 2015 PhD). TODO: save the data') |
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', required = True) | 12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file', required = True) |
13 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'object') | 13 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'object') |
14 parser.add_argument('-n', dest = 'nClusters', help = 'number of point clusters', required = True, type = int) | 14 parser.add_argument('-n', dest = 'nClusters', help = 'number of point clusters', required = True, type = int) |
15 parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full") | 15 parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full") |
16 parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image') | |
17 parser.add_argument('-u', dest = 'pixelsPerUnit', help = 'number pixels per unit of distance', type = float, default = 1.) | |
16 | 18 |
17 args = parser.parse_args() | 19 args = parser.parse_args() |
18 | 20 |
19 objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType) | 21 objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType) |
20 | 22 |
30 gmm = mixture.GMM(n_components=args.nClusters, covariance_type = args.covarianceType) | 32 gmm = mixture.GMM(n_components=args.nClusters, covariance_type = args.covarianceType) |
31 beginningModel=gmm.fit(beginnings) | 33 beginningModel=gmm.fit(beginnings) |
32 gmm = mixture.GMM(n_components=args.nClusters, covariance_type = args.covarianceType) | 34 gmm = mixture.GMM(n_components=args.nClusters, covariance_type = args.covarianceType) |
33 endModel=gmm.fit(ends) | 35 endModel=gmm.fit(ends) |
34 | 36 |
35 ml.plotGMMClusters(beginningModel, beginnings) | 37 fig = plt.figure() |
38 if args.worldImageFilename is not None and args.pixelsPerUnit is not None: | |
39 img = plt.imread(args.worldImageFilename) | |
40 plt.imshow(img) | |
41 ml.plotGMMClusters(beginningModel, beginnings, fig, nPixelsPerUnit = args.pixelsPerUnit) | |
36 plt.axis('equal') | 42 plt.axis('equal') |
37 plt.title('Origins') | 43 plt.title('Origins') |
38 print('Origin Clusters:\n{}'.format(ml.computeClusterSizes(beginningModel.predict(beginnings), range(args.nClusters)))) | 44 print('Origin Clusters:\n{}'.format(ml.computeClusterSizes(beginningModel.predict(beginnings), range(args.nClusters)))) |
39 | 45 |
40 ml.plotGMMClusters(endModel, ends) | 46 fig = plt.figure() |
47 if args.worldImageFilename is not None and args.pixelsPerUnit is not None: | |
48 img = plt.imread(args.worldImageFilename) | |
49 plt.imshow(img) | |
50 ml.plotGMMClusters(endModel, ends, fig, nPixelsPerUnit = args.pixelsPerUnit) | |
41 plt.axis('equal') | 51 plt.axis('equal') |
42 plt.title('Destinations') | 52 plt.title('Destinations') |
43 print('Destination Clusters:\n{}'.format(ml.computeClusterSizes(endModel.predict(ends), range(args.nClusters)))) | 53 print('Destination Clusters:\n{}'.format(ml.computeClusterSizes(endModel.predict(ends), range(args.nClusters)))) |