Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/classify-objects.py @ 686:cdee6a3a47b4 dev
allowing alternate database and filename for classify-objects
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 09 Jun 2015 17:29:03 +0200 |
| parents | 94b291a5f933 |
| children | de278c5e65f6 |
comparison
equal
deleted
inserted
replaced
| 685:94b291a5f933 | 686:cdee6a3a47b4 |
|---|---|
| 10 | 10 |
| 11 # TODO add mode detection live | 11 # TODO add mode detection live |
| 12 | 12 |
| 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') | 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
| 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) | 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
| 15 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') | |
| 16 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') | |
| 15 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) | 17 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) |
| 16 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') | 18 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') |
| 17 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.) | 19 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.) |
| 18 #parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') | |
| 19 #parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) | |
| 20 #parser.add_argument('--last-frame', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int) | |
| 21 # parser.add_argument('--min-speed-equiprobable', dest = 'minSpeedEquiprobable', help = 'speed value below which all classes are equiprobable (distributions give odd values there) (km/h)', type = float, default = 3.33) | |
| 22 # parser.add_argument('--speed-aggregation', dest = 'speedAggregationMethod', help = 'method to aggregate road user speed', type = str, choices = ['median', 'mean', 'quantile'], default = 'median') | |
| 23 # parser.add_argument('--speed-aggregation-quantile', dest = 'speedAggregationQuantile', help = 'quantile for the speed aggregation, if quantile is chosen', type = int, default = 50) | |
| 24 | 20 |
| 25 args = parser.parse_args() | 21 args = parser.parse_args() |
| 26 params = storage.ProcessParameters(args.configFilename) | 22 params = storage.ProcessParameters(args.configFilename) |
| 23 | |
| 24 if args.videoFilename is not None: | |
| 25 videoFilename = args.videoFilename | |
| 26 else: | |
| 27 videoFilename = params.videoFilename | |
| 28 if args.databaseFilename is not None: | |
| 29 databaseFilename = args.databaseFilename | |
| 30 else: | |
| 31 databaseFilename = params.databaseFilename | |
| 27 | 32 |
| 28 params.convertToFrames(3.6) | 33 params.convertToFrames(3.6) |
| 29 if params.homography is not None: | 34 if params.homography is not None: |
| 30 invHomography = np.linalg.inv(params.homography) | 35 invHomography = np.linalg.inv(params.homography) |
| 31 | 36 |
| 59 plt.legend() | 64 plt.legend() |
| 60 plt.title('Probability Density Function') | 65 plt.title('Probability Density Function') |
| 61 plt.show() | 66 plt.show() |
| 62 sys.exit() | 67 sys.exit() |
| 63 | 68 |
| 64 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object', args.nObjects, withFeatures = True) | 69 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, 'object', args.nObjects, withFeatures = True) |
| 65 #features = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'feature') | 70 #features = storage.loadTrajectoriesFromSqlite(databaseFilename, 'feature') |
| 66 intervals = [] | 71 intervals = [] |
| 67 for obj in objects: | 72 for obj in objects: |
| 68 #obj.setFeatures(features) | 73 #obj.setFeatures(features) |
| 69 intervals.append(obj.getTimeInterval()) | 74 intervals.append(obj.getTimeInterval()) |
| 70 timeInterval = moving.unionIntervals(intervals) | 75 timeInterval = moving.unionIntervals(intervals) |
| 71 | 76 |
| 72 capture = cv2.VideoCapture(params.videoFilename) | 77 capture = cv2.VideoCapture(videoFilename) |
| 73 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) | 78 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) |
| 74 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) | 79 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) |
| 75 | 80 |
| 76 pastObjects = [] | 81 pastObjects = [] |
| 77 if params.undistort: # setup undistortion | 82 if params.undistort: # setup undistortion |
| 106 | 111 |
| 107 for obj in objects: | 112 for obj in objects: |
| 108 obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = params.minSpeedEquiprobable, speedProbabilities = speedProbabilities) | 113 obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = params.minSpeedEquiprobable, speedProbabilities = speedProbabilities) |
| 109 pastObjects.append(obj) | 114 pastObjects.append(obj) |
| 110 print('Saving user types') | 115 print('Saving user types') |
| 111 storage.setRoadUserTypes(params.databaseFilename, pastObjects) | 116 storage.setRoadUserTypes(databaseFilename, pastObjects) |
