comparison scripts/learn-poi.py @ 818:181bcb6dad3a

added option to learn motion patterns and show to display results
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 21 Jun 2016 17:08:07 -0400
parents 180b6b0231c0
children 5a68779d7777
comparison
equal deleted inserted replaced
817:b9ec0cc2677d 818:181bcb6dad3a
14 parser.add_argument('-norigins', dest = 'nOriginClusters', help = 'number of clusters for trajectory origins', required = True, type = int) 14 parser.add_argument('-norigins', dest = 'nOriginClusters', help = 'number of clusters for trajectory origins', required = True, type = int)
15 parser.add_argument('-ndestinations', dest = 'nDestinationClusters', help = 'number of clusters for trajectory destinations (=norigins if not provided)', type = int) 15 parser.add_argument('-ndestinations', dest = 'nDestinationClusters', help = 'number of clusters for trajectory destinations (=norigins if not provided)', type = int)
16 parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full") 16 parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full")
17 parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image') 17 parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image')
18 parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units of distance per pixel', type = float, default = 1.) 18 parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units of distance per pixel', type = float, default = 1.)
19 parser.add_argument('--display', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance
19 20
20 args = parser.parse_args() 21 args = parser.parse_args()
21 22
22 objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType) 23 objects = storage.loadTrajectoriesFromSqlite(args.databaseFilename, args.trajectoryType)
23 24
42 gmm = mixture.GMM(n_components=nClusters, covariance_type = args.covarianceType) 43 gmm = mixture.GMM(n_components=nClusters, covariance_type = args.covarianceType)
43 model=gmm.fit(beginnings) 44 model=gmm.fit(beginnings)
44 if not model.converged_: 45 if not model.converged_:
45 print('Warning: model for '+gmmType+' points did not converge') 46 print('Warning: model for '+gmmType+' points did not converge')
46 # plot 47 # plot
47 fig = plt.figure() 48 if args.display:
48 if args.worldImageFilename is not None and args.unitsPerPixel is not None: 49 fig = plt.figure()
49 img = plt.imread(args.worldImageFilename) 50 if args.worldImageFilename is not None and args.unitsPerPixel is not None:
50 plt.imshow(img) 51 img = plt.imread(args.worldImageFilename)
51 labels = ml.plotGMMClusters(model, points, fig, nUnitsPerPixel = args.unitsPerPixel) 52 plt.imshow(img)
52 plt.axis('image') 53 labels = ml.plotGMMClusters(model, points, fig, nUnitsPerPixel = args.unitsPerPixel)
53 plt.title(gmmType) 54 plt.axis('image')
54 print(gmmType+' Clusters:\n{}'.format(ml.computeClusterSizes(labels, range(model.n_components)))) 55 plt.title(gmmType)
56 print(gmmType+' Clusters:\n{}'.format(ml.computeClusterSizes(labels, range(model.n_components))))
55 # save 57 # save
56 storage.savePOIs(args.databaseFilename, model, gmmType, gmmId) 58 storage.savePOIs(args.databaseFilename, model, gmmType, gmmId)
57 gmmId += 1 59 gmmId += 1
58 60
61 if args.display:
62 plt.show()
63
59 # fig = plt.figure() 64 # fig = plt.figure()
60 # if args.worldImageFilename is not None and args.pixelsPerUnit is not None: 65 # if args.worldImageFilename is not None and args.pixelsPerUnit is not None:
61 # img = plt.imread(args.worldImageFilename) 66 # img = plt.imread(args.worldImageFilename)
62 # plt.imshow(img) 67 # plt.imshow(img)
63 # ml.plotGMMClusters(, , fig, nPixelsPerUnit = args.pixelsPerUnit) 68 # ml.plotGMMClusters(, , fig, nPixelsPerUnit = args.pixelsPerUnit)