Mercurial Hosting > traffic-intelligence
comparison scripts/classify-objects.py @ 791:1158a6e2d28e dev
temporary solution for classification, with corrected svm.cpp and ml.hpp for loading saved classifiers
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 29 Apr 2016 16:07:35 -0400 |
parents | 5b970a5bc233 |
children | b1b624504388 |
comparison
equal
deleted
inserted
replaced
788:5b970a5bc233 | 791:1158a6e2d28e |
---|---|
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 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 |
33 databaseFilename = params.databaseFilename | 33 databaseFilename = params.databaseFilename |
34 | 34 |
35 params.convertToFrames(3.6) | 35 params.convertToFrames(3.6) |
36 if params.homography is not None: | 36 if params.homography is not None: |
37 invHomography = np.linalg.inv(params.homography) | 37 invHomography = np.linalg.inv(params.homography) |
38 else: | |
39 invHomography = None | |
38 | 40 |
39 if params.speedAggregationMethod == 'median': | 41 if params.speedAggregationMethod == 'median': |
40 speedAggregationFunc = np.median | 42 speedAggregationFunc = np.median |
41 elif params.speedAggregationMethod == 'mean': | 43 elif params.speedAggregationMethod == 'mean': |
42 speedAggregationFunc = np.mean | 44 speedAggregationFunc = np.mean |
72 #features = storage.loadTrajectoriesFromSqlite(databaseFilename, 'feature') | 74 #features = storage.loadTrajectoriesFromSqlite(databaseFilename, 'feature') |
73 intervals = [] | 75 intervals = [] |
74 for obj in objects: | 76 for obj in objects: |
75 #obj.setFeatures(features) | 77 #obj.setFeatures(features) |
76 intervals.append(obj.getTimeInterval()) | 78 intervals.append(obj.getTimeInterval()) |
77 timeInterval = moving.unionIntervals(intervals) | 79 timeInterval = moving.TimeInterval.unionIntervals(intervals) |
78 | 80 |
79 capture = cv2.VideoCapture(videoFilename) | 81 capture = cv2.VideoCapture(videoFilename) |
80 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) | 82 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) |
81 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) | 83 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) |
82 | 84 |