Mercurial > hg > nsaunier > traffic-intelligence
diff scripts/classify-objects.py @ 795:a34ec862371f
merged with dev branch
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 09 May 2016 15:33:11 -0400 |
| parents | 8eb8a6bd70e8 |
| children | 52aa03260f03 |
line wrap: on
line diff
--- a/scripts/classify-objects.py Tue Nov 03 13:48:56 2015 -0500 +++ b/scripts/classify-objects.py Mon May 09 15:33:11 2016 -0400 @@ -4,14 +4,16 @@ import numpy as np import sys, argparse -#from cv2 import SVM_RBF, SVM_C_SVC +from cv2.ml import SVM_RBF, SVM_C_SVC import cv2 from scipy.stats import norm, lognorm -# TODO add mode detection live +# TODO add mode detection live, add choice of kernel and svm type (to be saved in future classifier format) parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) +parser.add_argument('--kernel', dest = 'kernelType', help = 'kernel type for the support vector machine (SVM)', default = SVM_RBF, type = long) +parser.add_argument('--svm', dest = 'svmType', help = 'SVM type', default = SVM_C_SVC, type = long) parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) @@ -33,6 +35,8 @@ params.convertToFrames(3.6) if params.homography is not None: invHomography = np.linalg.inv(params.homography) +else: + invHomography = None if params.speedAggregationMethod == 'median': speedAggregationFunc = np.median @@ -44,9 +48,9 @@ print('Unknown speed aggregation method: {}. Exiting'.format(params.speedAggregationMethod)) sys.exit() -pedBikeCarSVM = ml.SVM() +pedBikeCarSVM = ml.SVM(args.svmType, args.kernelType) pedBikeCarSVM.load(params.pedBikeCarSVMFilename) -bikeCarSVM = ml.SVM() +bikeCarSVM = ml.SVM(args.svmType, args.kernelType) bikeCarSVM.load(params.bikeCarSVMFilename) # log logistic for ped and bik otherwise ((pedBeta/pedAlfa)*((sMean/pedAlfa)**(pedBeta-1)))/((1+(sMean/pedAlfa)**pedBeta)**2.) @@ -72,19 +76,19 @@ for obj in objects: #obj.setFeatures(features) intervals.append(obj.getTimeInterval()) -timeInterval = moving.unionIntervals(intervals) +timeInterval = moving.TimeInterval.unionIntervals(intervals) capture = cv2.VideoCapture(videoFilename) -width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) -height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) +width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) +height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) pastObjects = [] if params.undistort: # setup undistortion - [map1, map2] = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) + [map1, map2] = cvutils.computeUndistortMaps(width, height, params.undistortedImageMultiplication, params.intrinsicCameraMatrix, params.distortionCoefficients) if capture.isOpened(): ret = True frameNum = timeInterval.first - capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) + capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) lastFrameNum = timeInterval.last while ret and frameNum <= lastFrameNum:
