Mercurial Hosting > traffic-intelligence
annotate scripts/classify-objects.py @ 967:373e8ef6ee25
modified function to access video property
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 05 Dec 2017 16:15:44 -0500 |
parents | 64259b9885bf |
children | e8eabef7857c |
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.) |
962
64259b9885bf
verbose option to print classification information (more to add)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
947
diff
changeset
|
21 parser.add_argument('--verbose', dest = 'verbose', help = 'verbose information', action = 'store_true') |
536
95276d310972
renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
529
diff
changeset
|
22 |
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
|
23 args = parser.parse_args() |
901
753a081989e2
factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
899
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 |
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
|
28 if classifierParams.speedAggregationMethod == 'median': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
29 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
|
30 elif classifierParams.speedAggregationMethod == 'mean': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
31 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
|
32 elif classifierParams.speedAggregationMethod == 'quantile': |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
33 speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationQuantile) |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
34 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
|
35 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
|
36 sys.exit() |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
37 |
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
|
38 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
|
39 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
|
40 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
|
41 bikeCarSVM.load(classifierParams.bikeCarSVMFilename) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
42 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
43 # 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
|
44 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
|
45 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
|
46 # 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
|
47 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
|
48 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
|
49 '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
|
50 'bicycle': lambda s: bicLogNorm.pdf(s)} |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
51 |
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
|
52 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
|
53 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
|
54 plt.figure() |
682 | 55 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
|
56 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
|
57 maxProb = -1. |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
58 for k in speedProbabilities: |
33d296984dd8
rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
817
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 sys.exit() |
682 | 68 |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 timeInterval.first = 0 |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
73 |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
74 capture = cv2.VideoCapture(videoFilename) |
807
52aa03260f03
reversed all code to OpenCV 2.4.13
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
794
diff
changeset
|
75 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
|
76 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
|
77 |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
78 #if undistort: # setup undistortion |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
79 # [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) |
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
80 # height, width = map1.shape |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
81 # newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
82 # newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True) |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
83 #else: |
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
84 # newCameraMatrix = None |
904
8f60ecfc2f06
work in progress, almost ready
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
902
diff
changeset
|
85 |
684
6d2ece4aed7c
bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
683
diff
changeset
|
86 pastObjects = [] |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
87 currentObjects = [] |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
88 if capture.isOpened(): |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
89 ret = True |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 lastFrameNum = timeInterval.last |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
94 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
95 while ret and frameNum <= lastFrameNum: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
96 ret, img = capture.read() |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
97 if ret: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
98 if frameNum%50 == 0: |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
99 print('frame number: {}'.format(frameNum)) |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
100 #if undistort: |
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
101 # 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
|
102 for obj in objects[:]: |
912 | 103 if obj.getFirstInstant() <= frameNum: # if images are skipped |
935
0e63a918a1ca
updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
928
diff
changeset
|
104 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
|
105 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
|
106 objects.remove(obj) |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
107 |
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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 currentObjects.remove(obj) |
817
b9ec0cc2677d
corrected bug in classify-objects.py script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
812
diff
changeset
|
113 else: |
928
063d1267585d
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
912
diff
changeset
|
114 obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm) |
962
64259b9885bf
verbose option to print classification information (more to add)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
947
diff
changeset
|
115 if args.verbose: |
64259b9885bf
verbose option to print classification information (more to add)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
947
diff
changeset
|
116 print('obj {}@{}: {}'.format(obj.getNum(), frameNum, moving.userTypeNames[obj.userTypes[frameNum]])) |
680
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
117 frameNum += 1 |
da1352b89d02
classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
118 |
902
c69a8defe5c3
changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
901
diff
changeset
|
119 for obj in currentObjects: |
899
1466a63dd1cf
added a new classification parameter
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
898
diff
changeset
|
120 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
|
121 pastObjects.append(obj) |
6d2ece4aed7c
bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
683
diff
changeset
|
122 print('Saving user types') |
686
cdee6a3a47b4
allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
685
diff
changeset
|
123 storage.setRoadUserTypes(databaseFilename, pastObjects) |