Mercurial Hosting > traffic-intelligence
comparison scripts/extract-appearance-images.py @ 902:c69a8defe5c3
changed workflow of classify objects
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 22 Jun 2017 16:57:34 -0400 |
parents | 753a081989e2 |
children | 8f60ecfc2f06 |
comparison
equal
deleted
inserted
replaced
901:753a081989e2 | 902:c69a8defe5c3 |
---|---|
7 | 7 |
8 import cvutils, moving, ml, storage | 8 import cvutils, moving, ml, storage |
9 | 9 |
10 parser = argparse.ArgumentParser(description='The program extracts labeled image patches to train the HoG-SVM classifier, and optionnally speed information') | 10 parser = argparse.ArgumentParser(description='The program extracts labeled image patches to train the HoG-SVM classifier, and optionnally speed information') |
11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) | 11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)') | |
13 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)') | |
14 parser.add_argument('--gt', dest = 'classificationAnnotationFilename', help = 'name of the file containing the correct classes (user types)', required = True) | |
15 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each saved patch', default = 50, type = int) | |
16 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to use to extract patches from', type = int, default = None) | |
17 parser.add_argument('--compute-speed-distributions', dest = 'computeSpeedDistribution', help = 'computes the distribution of the road users of each type and fits parameters to each', action = 'store_true') | |
18 | |
12 | 19 |
13 #parser.add_argument('-d', dest = 'directoryName', help = 'parent directory name for the directories containing the samples for the different road users', required = True) | 20 #parser.add_argument('-d', dest = 'directoryName', help = 'parent directory name for the directories containing the samples for the different road users', required = True) |
14 | 21 |
15 args = parser.parse_args() | 22 args = parser.parse_args() |
16 params = storage.ProcessParameters(args.configFilename) | 23 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) |
17 classifierParams = storage.ClassifierParameters(params.classifierFilename) | 24 classifierParams = storage.ClassifierParameters(params.classifierFilename) |
18 | 25 |
19 # need all info as for classification (image info) | 26 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, 'object', args.nObjects, withFeatures = True) |
27 timeInterval = moving.TimeInterval.unionIntervals([obj.getTimeInterval() for obj in objects]) | |
28 | |
29 capture = cv2.VideoCapture(videoFilename) | |
30 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) | |
31 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) | |
32 | |
33 if undistort: # setup undistortion | |
34 [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) | |
35 if capture.isOpened(): | |
36 ret = True | |
37 frameNum = timeInterval.first | |
38 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) | |
39 lastFrameNum = timeInterval.last | |
40 while ret and frameNum <= lastFrameNum: | |
41 ret, img = capture.read() | |
42 if ret: | |
43 if frameNum%50 == 0: | |
44 print('frame number: {}'.format(frameNum)) | |
45 if undistort: | |
46 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) | |
47 | |
48 | |
49 frameNum += 1 | |
50 | |
51 | |
20 | 52 |
21 # todo speed info: distributions AND min speed equiprobable | 53 # todo speed info: distributions AND min speed equiprobable |
22 | 54 |
23 # provide csv delimiter for the classification file as arg | 55 # provide csv delimiter for the classification file as arg |
24 | 56 |