Mercurial Hosting > traffic-intelligence
annotate scripts/classify-objects.py @ 956:196a1fd498ba
removing unnecessary complexity of varying number of return elements
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 15 Aug 2017 16:15:55 -0400 |
parents | 053484e08947 |
children | 64259b9885bf |
rev | line source |
---|---|
522
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
3 import cvutils, moving, ml, storage |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
4 |
522
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 import numpy as np |
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 import sys, argparse |
807
52aa03260f03
reversed all code to OpenCV 2.4.13
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
794
diff
changeset
|
7 #from cv2.ml import SVM_RBF, SVM_C_SVC |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
8 import cv2 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
9 from scipy.stats import norm, lognorm |
522
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 |
788
5b970a5bc233
updated classifying code to OpenCV 3.x (bug in function to load classification models)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
687
diff
changeset
|
11 # TODO add mode detection live, add choice of kernel and svm type (to be saved in future classifier format) |
522
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 |
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
536
95276d310972
renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
529
diff
changeset
|
14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
15 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') |
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
16 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') |
685
94b291a5f933
several updates for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
684
diff
changeset
|
17 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) |
911
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
18 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') |
683
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
19 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') |
854
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
20 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.) |
536
95276d310972
renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
529
diff
changeset
|
21 |
522
ce40a89bd6ae
added functions for classification refactored from Sohail s work for TRB/TRC (to be tested)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
22 args = parser.parse_args() |
901
753a081989e2
factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
899
diff
changeset
|
23 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
24 classifierParams = storage.ClassifierParameters(params.classifierFilename) |
854
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
25 classifierParams.convertToFrames(params.videoFrameRate, 3.6) # conversion from km/h to m/frame |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
26 |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
27 if classifierParams.speedAggregationMethod == 'median': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
28 speedAggregationFunc = np.median |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
29 elif classifierParams.speedAggregationMethod == 'mean': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
30 speedAggregationFunc = np.mean |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
31 elif classifierParams.speedAggregationMethod == 'quantile': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
32 speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationQuantile) |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
33 else: |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
34 print('Unknown speed aggregation method: {}. Exiting'.format(classifierParams.speedAggregationMethod)) |
683
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
35 sys.exit() |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
36 |
812
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
37 pedBikeCarSVM = ml.SVM() |
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
38 pedBikeCarSVM.load(classifierParams.pedBikeCarSVMFilename) |
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
39 bikeCarSVM = ml.SVM() |
21f10332c72b
moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
807
diff
changeset
|
40 bikeCarSVM.load(classifierParams.bikeCarSVMFilename) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
41 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
42 # log logistic for ped and bik otherwise ((pedBeta/pedAlfa)*((sMean/pedAlfa)**(pedBeta-1)))/((1+(sMean/pedAlfa)**pedBeta)**2.) |
854
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
43 carNorm = norm(classifierParams.meanVehicleSpeed, classifierParams.stdVehicleSpeed) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
44 pedNorm = norm(classifierParams.meanPedestrianSpeed, classifierParams.stdPedestrianSpeed) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
45 # numpy lognorm shape, loc, scale: shape for numpy is scale (std of the normal) and scale for numpy is exp(location) (loc=mean of the normal) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
46 bicLogNorm = lognorm(classifierParams.scaleCyclistSpeed, loc = 0., scale = np.exp(classifierParams.locationCyclistSpeed)) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
47 speedProbabilities = {'car': lambda s: carNorm.pdf(s), |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
48 'pedestrian': lambda s: pedNorm.pdf(s), |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
49 'bicycle': lambda s: bicLogNorm.pdf(s)} |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
50 |
683
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
51 if args.plotSpeedDistribution: |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
52 import matplotlib.pyplot as plt |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
53 plt.figure() |
682 | 54 for k in speedProbabilities: |
854
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
55 plt.plot(np.arange(0.1, args.maxSpeedDistributionPlot, 0.1), [speedProbabilities[k](s/(3.6*params.videoFrameRate)) for s in np.arange(0.1, args.maxSpeedDistributionPlot, 0.1)], label = k) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
56 maxProb = -1. |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
57 for k in speedProbabilities: |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
58 maxProb = max(maxProb, np.max([speedProbabilities[k](s/(3.6*params.videoFrameRate)) for s in np.arange(0.1, args.maxSpeedDistributionPlot, 0.1)])) |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
59 plt.plot([classifierParams.minSpeedEquiprobable*3.6*params.videoFrameRate]*2, [0., maxProb], 'k-') |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
60 plt.text(classifierParams.minSpeedEquiprobable*3.6*params.videoFrameRate, maxProb, 'threshold for equiprobable class') |
683
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
61 plt.xlabel('Speed (km/h)') |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
62 plt.ylabel('Probability') |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
63 plt.legend() |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
64 plt.title('Probability Density Function') |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
65 plt.show() |
f3a0b652b590
added function to display the speed distributions and optimize a little going through objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
682
diff
changeset
|
66 sys.exit() |
682 | 67 |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
68 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, 'object', args.nObjects, withFeatures = True) |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
69 timeInterval = moving.TimeInterval.unionIntervals([obj.getTimeInterval() for obj in objects]) |
911
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
70 if args.startFrame0: |
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
71 timeInterval.first = 0 |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
72 |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
73 capture = cv2.VideoCapture(videoFilename) |
807
52aa03260f03
reversed all code to OpenCV 2.4.13
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
794
diff
changeset
|
74 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) |
52aa03260f03
reversed all code to OpenCV 2.4.13
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
794
diff
changeset
|
75 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
76 |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
77 #if undistort: # setup undistortion |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
78 # [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) |
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
79 # height, width = map1.shape |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
80 # newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
81 # newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True) |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
82 #else: |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
83 # newCameraMatrix = None |
904
8f60ecfc2f06
work in progress, almost ready
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
902
diff
changeset
|
84 |
684
6d2ece4aed7c
bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
683
diff
changeset
|
85 pastObjects = [] |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
86 currentObjects = [] |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
87 if capture.isOpened(): |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
88 ret = True |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
89 frameNum = timeInterval.first |
911
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
90 if not args.startFrame0: |
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
91 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
92 lastFrameNum = timeInterval.last |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
93 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
94 while ret and frameNum <= lastFrameNum: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
95 ret, img = capture.read() |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
96 if ret: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
97 if frameNum%50 == 0: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
98 print('frame number: {}'.format(frameNum)) |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
99 #if undistort: |
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
100 # img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) |
947
053484e08947
found a more elegant solution, making a copy of the list to iterate
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
946
diff
changeset
|
101 for obj in objects[:]: |
912 | 102 if obj.getFirstInstant() <= frameNum: # if images are skipped |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
103 obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, classifierParams.maxPedestrianSpeed, classifierParams.maxCyclistSpeed, classifierParams.nFramesIgnoreAtEnds, invHomography, intrinsicCameraMatrix, distortionCoefficients) |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
104 currentObjects.append(obj) |
947
053484e08947
found a more elegant solution, making a copy of the list to iterate
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
946
diff
changeset
|
105 objects.remove(obj) |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
106 |
947
053484e08947
found a more elegant solution, making a copy of the list to iterate
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
946
diff
changeset
|
107 for obj in currentObjects[:]: |
911
3dd5acfa1899
corrected potential issues with videos where one cannot reach a give frame from its number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
905
diff
changeset
|
108 if obj.getLastInstant() <= frameNum: # if images are skipped |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
109 obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities, maxPercentUnknown = classifierParams.maxPercentUnknown) |
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
110 pastObjects.append(obj) |
947
053484e08947
found a more elegant solution, making a copy of the list to iterate
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
946
diff
changeset
|
111 currentObjects.remove(obj) |
817
b9ec0cc2677d
corrected bug in classify-objects.py script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
812
diff
changeset
|
112 else: |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
113 obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
114 frameNum += 1 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
115 |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
116 for obj in currentObjects: |
899
1466a63dd1cf
added a new classification parameter
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
898
diff
changeset
|
117 obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities, maxPercentUnknown = classifierParams.maxPercentUnknown) |
684
6d2ece4aed7c
bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
683
diff
changeset
|
118 pastObjects.append(obj) |
6d2ece4aed7c
bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
683
diff
changeset
|
119 print('Saving user types') |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
120 storage.setRoadUserTypes(databaseFilename, pastObjects) |