diff 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
line wrap: on
line diff
--- a/scripts/learn-poi.py	Fri Mar 11 17:38:48 2016 -0500
+++ b/scripts/learn-poi.py	Thu Mar 17 16:01:19 2016 -0400
@@ -13,6 +13,8 @@
 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'object')
 parser.add_argument('-n', dest = 'nClusters', help = 'number of point clusters', required = True, type = int)
 parser.add_argument('--covariance-type', dest = 'covarianceType', help = 'type of covariance of Gaussian model', default = "full")
+parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image')
+parser.add_argument('-u', dest = 'pixelsPerUnit', help = 'number pixels per unit of distance', type = float, default = 1.)
 
 args = parser.parse_args()
 
@@ -32,12 +34,20 @@
 gmm = mixture.GMM(n_components=args.nClusters, covariance_type = args.covarianceType)
 endModel=gmm.fit(ends)
 
-ml.plotGMMClusters(beginningModel, beginnings)
+fig = plt.figure()
+if args.worldImageFilename is not None and args.pixelsPerUnit is not None:
+    img = plt.imread(args.worldImageFilename)
+    plt.imshow(img)
+ml.plotGMMClusters(beginningModel, beginnings, fig, nPixelsPerUnit = args.pixelsPerUnit)
 plt.axis('equal')
 plt.title('Origins')
 print('Origin Clusters:\n{}'.format(ml.computeClusterSizes(beginningModel.predict(beginnings), range(args.nClusters))))
 
-ml.plotGMMClusters(endModel, ends)
+fig = plt.figure()
+if args.worldImageFilename is not None and args.pixelsPerUnit is not None:
+    img = plt.imread(args.worldImageFilename)
+    plt.imshow(img)
+ml.plotGMMClusters(endModel, ends, fig, nPixelsPerUnit = args.pixelsPerUnit)
 plt.axis('equal')
 plt.title('Destinations')
 print('Destination Clusters:\n{}'.format(ml.computeClusterSizes(endModel.predict(ends), range(args.nClusters))))