annotate scripts/classify-objects.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents e8eabef7857c
children b7689372c0ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 993
diff changeset
1 #! /usr/bin/env python3
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
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
993
e8eabef7857c update to OpenCV3 for python
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 962
diff changeset
38 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename)
e8eabef7857c update to OpenCV3 for python
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 962
diff changeset
39 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename)
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
40
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
41 # 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
42 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
43 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
44 # 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
45 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
46 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
47 '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
48 'bicycle': lambda s: bicLogNorm.pdf(s)}
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
49
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
50 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
51 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
52 plt.figure()
682
fbe29be25501 corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 680
diff changeset
53 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
54 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
55 maxProb = -1.
33d296984dd8 rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 817
diff changeset
56 for k in speedProbabilities:
33d296984dd8 rework and more info on speed probabilities for classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 817
diff changeset
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 sys.exit()
682
fbe29be25501 corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 680
diff changeset
66
686
cdee6a3a47b4 allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 685
diff changeset
67 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
68 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
69 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
70 timeInterval.first = 0
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
71
686
cdee6a3a47b4 allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 685
diff changeset
72 capture = cv2.VideoCapture(videoFilename)
993
e8eabef7857c update to OpenCV3 for python
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 962
diff changeset
73 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
e8eabef7857c update to OpenCV3 for python
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 962
diff changeset
74 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
75
935
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
76 #if undistort: # setup undistortion
928
063d1267585d work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 912
diff changeset
77 # [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients)
063d1267585d work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 912
diff changeset
78 # height, width = map1.shape
935
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
79 # newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication)))
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
80 # newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True)
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
81 #else:
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
82 # newCameraMatrix = None
904
8f60ecfc2f06 work in progress, almost ready
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 902
diff changeset
83
684
6d2ece4aed7c bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 683
diff changeset
84 pastObjects = []
902
c69a8defe5c3 changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 901
diff changeset
85 currentObjects = []
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
86 if capture.isOpened():
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
87 ret = True
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
88 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
89 if not args.startFrame0:
993
e8eabef7857c update to OpenCV3 for python
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 962
diff changeset
90 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum)
680
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
91 lastFrameNum = timeInterval.last
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
92
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
93 while ret and frameNum <= lastFrameNum:
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
94 ret, img = capture.read()
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
95 if ret:
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
96 if frameNum%50 == 0:
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
97 print('frame number: {}'.format(frameNum))
928
063d1267585d work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 912
diff changeset
98 #if undistort:
063d1267585d work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 912
diff changeset
99 # 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
100 for obj in objects[:]:
912
fd057a6b04db corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 911
diff changeset
101 if obj.getFirstInstant() <= frameNum: # if images are skipped
935
0e63a918a1ca updated classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 928
diff changeset
102 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
103 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
104 objects.remove(obj)
902
c69a8defe5c3 changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 901
diff changeset
105
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 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
107 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
108 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
109 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
110 currentObjects.remove(obj)
817
b9ec0cc2677d corrected bug in classify-objects.py script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 812
diff changeset
111 else:
928
063d1267585d work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 912
diff changeset
112 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
113 if args.verbose:
64259b9885bf verbose option to print classification information (more to add)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 947
diff changeset
114 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
115 frameNum += 1
da1352b89d02 classification is working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
116
902
c69a8defe5c3 changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 901
diff changeset
117 for obj in currentObjects:
899
1466a63dd1cf added a new classification parameter
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 898
diff changeset
118 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
119 pastObjects.append(obj)
6d2ece4aed7c bug forgot to svae objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 683
diff changeset
120 print('Saving user types')
686
cdee6a3a47b4 allowing alternate database and filename for classify-objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 685
diff changeset
121 storage.setRoadUserTypes(databaseFilename, pastObjects)