comparison scripts/classify-objects.py @ 807:52aa03260f03 opencv3

reversed all code to OpenCV 2.4.13
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 10 Jun 2016 15:26:19 -0400
parents 8eb8a6bd70e8
children 21f10332c72b
comparison
equal deleted inserted replaced
806:c6f497291fd8 807:52aa03260f03
2 2
3 import cvutils, moving, ml, storage 3 import cvutils, moving, ml, storage
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
9 from scipy.stats import norm, lognorm 9 from scipy.stats import norm, lognorm
10 10
11 # TODO add mode detection live, add choice of kernel and svm type (to be saved in future classifier format) 11 # TODO add mode detection live, add choice of kernel and svm type (to be saved in future classifier format)
12 12
13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene')
14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True)
15 parser.add_argument('--kernel', dest = 'kernelType', help = 'kernel type for the support vector machine (SVM)', default = SVM_RBF, type = long) 15 parser.add_argument('--kernel', dest = 'kernelType', help = 'kernel type for the support vector machine (SVM)', default = cv2.SVM_RBF, type = long)
16 parser.add_argument('--svm', dest = 'svmType', help = 'SVM type', default = SVM_C_SVC, type = long) 16 parser.add_argument('--svm', dest = 'svmType', help = 'SVM type', default = cv2.SVM_C_SVC, type = long)
17 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') 17 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)')
18 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') 18 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)')
19 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) 19 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None)
20 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') 20 parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true')
21 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.) 21 parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.)
77 #obj.setFeatures(features) 77 #obj.setFeatures(features)
78 intervals.append(obj.getTimeInterval()) 78 intervals.append(obj.getTimeInterval())
79 timeInterval = moving.TimeInterval.unionIntervals(intervals) 79 timeInterval = moving.TimeInterval.unionIntervals(intervals)
80 80
81 capture = cv2.VideoCapture(videoFilename) 81 capture = cv2.VideoCapture(videoFilename)
82 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) 82 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
83 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) 83 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
84 84
85 pastObjects = [] 85 pastObjects = []
86 if params.undistort: # setup undistortion 86 if params.undistort: # setup undistortion
87 [map1, map2] = cvutils.computeUndistortMaps(width, height, params.undistortedImageMultiplication, params.intrinsicCameraMatrix, params.distortionCoefficients) 87 [map1, map2] = cvutils.computeUndistortMaps(width, height, params.undistortedImageMultiplication, params.intrinsicCameraMatrix, params.distortionCoefficients)
88 if capture.isOpened(): 88 if capture.isOpened():
89 ret = True 89 ret = True
90 frameNum = timeInterval.first 90 frameNum = timeInterval.first
91 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) 91 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum)
92 lastFrameNum = timeInterval.last 92 lastFrameNum = timeInterval.last
93 93
94 while ret and frameNum <= lastFrameNum: 94 while ret and frameNum <= lastFrameNum:
95 ret, img = capture.read() 95 ret, img = capture.read()
96 if ret: 96 if ret: