comparison scripts/classify-objects.py @ 1023:a13f47c8931d

work on processing large datasets (generate speed data)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 06 Jun 2018 16:51:15 -0400
parents b7689372c0ec
children cc5cb04b04b0
comparison
equal deleted inserted replaced
1022:b7689372c0ec 1023:a13f47c8931d
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 import cvutils, moving, ml, storage 3 import cvutils, moving, ml, storage, utils
4 4
5 import numpy as np 5 import numpy as np
6 import sys, argparse 6 import sys, argparse
7 #from cv2.ml import SVM_RBF, SVM_C_SVC 7 #from cv2.ml import SVM_RBF, SVM_C_SVC
8 import cv2 8 import cv2
23 args = parser.parse_args() 23 args = parser.parse_args()
24 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) 24 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args)
25 classifierParams = storage.ClassifierParameters(params.classifierFilename) 25 classifierParams = storage.ClassifierParameters(params.classifierFilename)
26 classifierParams.convertToFrames(params.videoFrameRate, 3.6) # conversion from km/h to m/frame 26 classifierParams.convertToFrames(params.videoFrameRate, 3.6) # conversion from km/h to m/frame
27 27
28 if classifierParams.speedAggregationMethod == 'median': 28 speedAggregationFunc = utils.aggregationFunction(classifierParams.speedAggregationMethod)
29 speedAggregationFunc = np.median 29 if speedAggregationFunc is None:
30 elif classifierParams.speedAggregationMethod == 'mean':
31 speedAggregationFunc = np.mean
32 elif classifierParams.speedAggregationMethod == 'centile':
33 speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationCentile)
34 else:
35 print('Unknown speed aggregation method: {}. Exiting'.format(classifierParams.speedAggregationMethod))
36 sys.exit() 30 sys.exit()
37 31
38 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename) 32 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename)
39 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename) 33 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename)
40 34