diff scripts/classify-objects.py @ 788:5b970a5bc233 dev

updated classifying code to OpenCV 3.x (bug in function to load classification models)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 24 Mar 2016 16:37:37 -0400
parents de278c5e65f6
children 1158a6e2d28e
line wrap: on
line diff
--- a/scripts/classify-objects.py	Thu Mar 17 16:01:19 2016 -0400
+++ b/scripts/classify-objects.py	Thu Mar 24 16:37:37 2016 -0400
@@ -4,14 +4,16 @@
 
 import numpy as np
 import sys, argparse
-#from cv2 import SVM_RBF, SVM_C_SVC
+from cv2 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)
@@ -44,9 +46,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.)
@@ -75,8 +77,8 @@
 timeInterval = moving.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
@@ -84,7 +86,7 @@
 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: