Mercurial Hosting > traffic-intelligence
diff 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 |
line wrap: on
line diff
--- a/scripts/extract-appearance-images.py Thu Jun 22 12:02:34 2017 -0400 +++ b/scripts/extract-appearance-images.py Thu Jun 22 16:57:34 2017 -0400 @@ -9,14 +9,46 @@ parser = argparse.ArgumentParser(description='The program extracts labeled image patches to train the HoG-SVM classifier, and optionnally speed information') parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) +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('--gt', dest = 'classificationAnnotationFilename', help = 'name of the file containing the correct classes (user types)', required = True) +parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each saved patch', default = 50, type = int) +parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to use to extract patches from', type = int, default = None) +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') + #parser.add_argument('-d', dest = 'directoryName', help = 'parent directory name for the directories containing the samples for the different road users', required = True) args = parser.parse_args() -params = storage.ProcessParameters(args.configFilename) +params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) classifierParams = storage.ClassifierParameters(params.classifierFilename) -# need all info as for classification (image info) +objects = storage.loadTrajectoriesFromSqlite(databaseFilename, 'object', args.nObjects, withFeatures = True) +timeInterval = moving.TimeInterval.unionIntervals([obj.getTimeInterval() for obj in objects]) + +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)) + +if undistort: # setup undistortion + [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) +if capture.isOpened(): + ret = True + frameNum = timeInterval.first + capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) + lastFrameNum = timeInterval.last + while ret and frameNum <= lastFrameNum: + ret, img = capture.read() + if ret: + if frameNum%50 == 0: + print('frame number: {}'.format(frameNum)) + if undistort: + img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) + + + frameNum += 1 + + # todo speed info: distributions AND min speed equiprobable