Mercurial Hosting > traffic-intelligence
changeset 685:94b291a5f933 dev
several updates for display
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 05 Jun 2015 17:13:28 +0200 |
parents | 6d2ece4aed7c |
children | cdee6a3a47b4 |
files | python/cvutils.py python/moving.py python/storage.py scripts/classify-objects.py tracking.cfg |
diffstat | 5 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Fri Jun 05 13:26:51 2015 +0200 +++ b/python/cvutils.py Fri Jun 05 17:13:28 2015 +0200 @@ -126,7 +126,8 @@ def playVideo(filename, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1): '''Plays the video''' windowName = 'frame' - cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) + if rescale == 1.: + cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) wait = 5 if frameRate > 0: wait = int(round(1000./frameRate)) @@ -259,7 +260,7 @@ if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels: croppedImg = img[yCropMin : yCropMax, xCropMin : xCropMax] else: - croppedImg = [] + croppedImg = None return croppedImg, yCropMin, yCropMax, xCropMin, xCropMax @@ -273,7 +274,8 @@ height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) windowName = 'frame' - #cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) + if rescale == 1.: + cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) if undistort: # setup undistortion [map1, map2] = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients)
--- a/python/moving.py Fri Jun 05 13:26:51 2015 +0200 +++ b/python/moving.py Fri Jun 05 17:13:28 2015 +0200 @@ -1404,7 +1404,7 @@ '''Extract the image box around the object and applies the SVM model on it''' croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = cvutils.imageBox(img, self, instant, homography, width, height, px, py, minNPixels) - if len(croppedImg) > 0: + if croppedImg is not None and len(croppedImg) > 0: hog = cvutils.HOG(croppedImg)#HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False) self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) else:
--- a/python/storage.py Fri Jun 05 13:26:51 2015 +0200 +++ b/python/storage.py Fri Jun 05 17:13:28 2015 +0200 @@ -372,7 +372,7 @@ userTypes[row[0]] = row[1] return userTypes -def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None): +def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None, withFeatures = False): '''Loads the first objectNumbers objects or the indices in objectNumbers from the database''' connection = sqlite3.connect(filename) @@ -411,6 +411,14 @@ userTypes = loadUserTypesFromTable(cursor, trajectoryType, objectNumbers) for obj in objects: obj.userType = userTypes[obj.getNum()] + + if withFeatures: + nFeatures = 0 + for obj in objects: + nFeatures = max(nFeatures, max(obj.featureNumbers)) + features = loadTrajectoriesFromSqlite(filename, 'feature', nFeatures) + for obj in objects: + obj.setFeatures(features) except sqlite3.OperationalError as error: printDBError(error) @@ -906,6 +914,7 @@ self.nFramesIgnoreAtEnds = config.getint(self.sectionHeader, 'nframes-ignore-at-ends') self.speedAggregationQuantile = config.getint(self.sectionHeader, 'speed-aggregation-quantile') self.minSpeedEquiprobable = config.getfloat(self.sectionHeader, 'min-speed-equiprobable') + self.minNPixels = config.getint(self.sectionHeader, 'min-npixels-crop') self.pedBikeCarSVMFilename = config.get(self.sectionHeader, 'pbv-svm-filename') self.bikeCarSVMFilename = config.get(self.sectionHeader, 'bv-svm-filename') self.maxPedestrianSpeed = config.getfloat(self.sectionHeader, 'max-ped-speed')
--- a/scripts/classify-objects.py Fri Jun 05 13:26:51 2015 +0200 +++ b/scripts/classify-objects.py Fri Jun 05 17:13:28 2015 +0200 @@ -12,6 +12,7 @@ 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('-n', dest = 'nObjects', help = 'number of objects to classify', type = int, default = None) parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true') parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.) #parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') @@ -60,11 +61,11 @@ plt.show() sys.exit() -objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object') -features = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'feature') +objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object', args.nObjects, withFeatures = True) +#features = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'feature') intervals = [] for obj in objects: - obj.setFeatures(features) + #obj.setFeatures(features) intervals.append(obj.getTimeInterval()) timeInterval = moving.unionIntervals(intervals)
--- a/tracking.cfg Fri Jun 05 13:26:51 2015 +0200 +++ b/tracking.cfg Fri Jun 05 17:13:28 2015 +0200 @@ -81,18 +81,20 @@ # minimum average number of features per frame to create a vehicle hypothesis min-nfeatures-group = 3 # Road user classification -# filename of the general ped/cyc/veh SVM classifier -pbv-svm-filename = modelPBV.xml -# filename of the cyc/veh SVM classifier -bv-svm-filename = modelBV.xml +# min number of pixels in cropped image to classify by SVM +min-npixels-crop = 400 # method to aggregate road user speed -speed-aggregation-method = 'median' +speed-aggregation-method = median # number of frames to ignore at both ends of a series (noisy) nframes-ignore-at-ends = 2 # quantile for the speed aggregation, if quantile is chosen speed-aggregation-quantile = 50 # speed value below which all classes are equiprobable (distributions give odd values there) (km/h) min-speed-equiprobable = 3.33 +# filename of the general ped/cyc/veh SVM classifier +pbv-svm-filename = modelPBV.xml +# filename of the cyc/veh SVM classifier +bv-svm-filename = modelBV.xml # maximum pedestrian speed (agregate: mean, median, 85th centile, etc.) 10 km/h max-ped-speed = 10.0 # maximum cyclist speed (agregate: mean, median, 85th centile, etc.) 30 km/h (3xped)