Mercurial Hosting > traffic-intelligence
comparison scripts/classify-objects.py @ 1244:00b71da2baac
corrected bug
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 08 Feb 2024 15:04:56 -0500 |
parents | 88eedf79f16a |
children | 2397de73770d |
comparison
equal
deleted
inserted
replaced
1243:88eedf79f16a | 1244:00b71da2baac |
---|---|
9 | 9 |
10 try: | 10 try: |
11 from ultralytics import YOLO | 11 from ultralytics import YOLO |
12 ultralyticsAvailable = True | 12 ultralyticsAvailable = True |
13 except ImportError: | 13 except ImportError: |
14 #print('OpenCV library could not be loaded (video replay functions will not be available)') # TODO change to logging module | 14 print('Ultralytics library could not be loaded') # TODO change to logging module |
15 ultralyticsAvailable = False | 15 ultralyticsAvailable = False |
16 | 16 |
17 | 17 |
18 from trafficintelligence import cvutils, moving, ml, storage, utils | 18 from trafficintelligence import cvutils, moving, ml, storage, utils |
19 | 19 |
22 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene', epilog='The integer ids for the categories are stored in the moving module:\n{}'.format(moving.userType2Num)) | 22 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene', epilog='The integer ids for the categories are stored in the moving module:\n{}'.format(moving.userType2Num)) |
23 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) | 23 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
24 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') | 24 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') |
25 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') | 25 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') |
26 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) | 26 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) |
27 parser.add_argument('--start-frame0', dest = 'startFrame0', help = 'starts with first frame for videos with index problem where frames cannot be reached', action = 'store_true') | |
28 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') | 27 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') |
29 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display (km/h)', type = float, default = 50.) | 28 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display (km/h)', type = float, default = 50.) |
30 parser.add_argument('--verbose', dest = 'verbose', help = 'verbose information', action = 'store_true') | 29 parser.add_argument('--verbose', dest = 'verbose', help = 'verbose information', action = 'store_true') |
31 | 30 |
32 args = parser.parse_args() | 31 args = parser.parse_args() |
41 if ultralyticsAvailable and Path(classifierParams.dlFilename).is_file(): # use Yolo | 40 if ultralyticsAvailable and Path(classifierParams.dlFilename).is_file(): # use Yolo |
42 pedBikeCarSVM = None | 41 pedBikeCarSVM = None |
43 bikeCarSVM = None | 42 bikeCarSVM = None |
44 yolo = YOLO(classifierParams.dlFilename, task='detect') | 43 yolo = YOLO(classifierParams.dlFilename, task='detect') |
45 useYolo = True | 44 useYolo = True |
46 print('Using Yolov8 model +'classifierParams.dlFilename) | 45 print('Using Yolov8 model '+classifierParams.dlFilename) |
47 else: | 46 else: |
48 useYolo = False | 47 useYolo = False |
49 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename) | 48 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename) |
50 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename) | 49 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename) |
51 | 50 |