Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/storage.py @ 1052:1748c02f9ac3
Modifying storage.py [configloaders]
author | Wendlasida |
---|---|
date | Thu, 05 Jul 2018 13:48:12 -0400 |
parents | fc7c0f38e8a6 |
children | 60cc87e824c4 |
comparison
equal
deleted
inserted
replaced
1042:b1ba6d44fcb9 | 1052:1748c02f9ac3 |
---|---|
412 for obj in objects: | 412 for obj in objects: |
413 if obj.hasFeatures(): | 413 if obj.hasFeatures(): |
414 for feature in obj.getFeatures(): | 414 for feature in obj.getFeatures(): |
415 featureNum = feature.getNum() | 415 featureNum = feature.getNum() |
416 cursor.execute(objectFeatureQuery, (obj.getNum(), featureNum)) | 416 cursor.execute(objectFeatureQuery, (obj.getNum(), featureNum)) |
417 cursor.execute(objectQuery, (obj.getNum(), obj.getUserType(), 1)) | 417 cursor.execute(objectQuery, (obj.getNum(), obj.getUserType(), obj.nObjects if hasattr(obj, 'nObjects') and obj.nObjects is not None else 1)) |
418 # Parse curvilinear position structure | 418 # Parse curvilinear position structure |
419 elif(trajectoryType == 'curvilinear'): | 419 elif(trajectoryType == 'curvilinear'): |
420 createCurvilinearTrajectoryTable(cursor) | 420 createCurvilinearTrajectoryTable(cursor) |
421 curvilinearQuery = "INSERT INTO curvilinear_positions VALUES (?,?,?,?,?)" | 421 curvilinearQuery = "INSERT INTO curvilinear_positions VALUES (?,?,?,?,?)" |
422 for obj in objects: | 422 for obj in objects: |
1361 class ProcessParameters(VideoFilenameAddable): | 1361 class ProcessParameters(VideoFilenameAddable): |
1362 '''Class for all parameters controlling data processing: input, | 1362 '''Class for all parameters controlling data processing: input, |
1363 method parameters, etc. for tracking and safety | 1363 method parameters, etc. for tracking and safety |
1364 | 1364 |
1365 Note: framerate is already taken into account''' | 1365 Note: framerate is already taken into account''' |
1366 | |
1367 def loadTrackerConfig(self, filename = None): | |
1368 from configparser import ConfigParser | |
1369 | |
1370 config = ConfigParser(strict=False) | |
1371 config['DEFAULT']['acceleration-bound'] = '3' | |
1372 config['DEFAULT']['min-velocity-cosine'] = '0.8' | |
1373 config['DEFAULT']['ndisplacements'] = '3' | |
1374 config['DEFAULT']['max-nfeatures'] = '1000' | |
1375 config['DEFAULT']['feature-quality'] = '0.0812219538558' | |
1376 config['DEFAULT']['min-feature-distanceklt'] = '3.54964337411' | |
1377 config['DEFAULT']['block-size'] = '7' | |
1378 config['DEFAULT']['use-harris-detector'] = 'false' | |
1379 config['DEFAULT']['k'] = '0.04' | |
1380 config['DEFAULT']['window-size'] = '6' | |
1381 config['DEFAULT']['pyramid-level'] = '5' | |
1382 config['DEFAULT']['min-tracking-error'] = '0.183328975142' | |
1383 config['DEFAULT']['max-number-iterations'] = '20' | |
1384 config['DEFAULT']['feature-flag'] = '0' | |
1385 config['DEFAULT']['min-feature-eig-threshold'] = '1e-4' | |
1386 config['DEFAULT']['min-feature-time'] = '15' | |
1387 config['DEFAULT']['min-feature-displacement'] = '0.05' | |
1388 config['DEFAULT']['tracker-reload-time'] = '10' | |
1389 | |
1390 self.sectionHeader = config.sections()[0] | |
1391 | |
1392 if filename is not None: | |
1393 config.read_file(addSectionHeader(utils.openCheck(filename))) | |
1394 | |
1395 #Tracker parameters | |
1396 self.accelerationBound = config.getint(self.sectionHeader, 'acceleration-bound') | |
1397 self.minVelocityCosine = config.getfloat(self.sectionHeader, 'min-velocity-cosine') | |
1398 self.ndisplacements = config.getfloat(self.sectionHeader, 'ndisplacements') | |
1399 self.maxNFeatures = config.getint(self.sectionHeader, 'max-nfeatures') | |
1400 self.minFeatureDistanceKLT = config.getfloat(self.sectionHeader, 'min-feature-distanceklt') | |
1401 self.featureQuality = config.getfloat(self.sectionHeader, 'feature-quality') | |
1402 self.blockSize = config.getint(self.sectionHeader, 'block-size') | |
1403 self.useHarrisDetector = config.getboolean(self.sectionHeader, 'use-harris-detector') | |
1404 self.k = config.getfloat(self.sectionHeader, 'k') | |
1405 self.winSize = config.getint(self.sectionHeader, 'window-size') | |
1406 self.pyramidLevel = config.getint(self.sectionHeader, 'pyramid-level') | |
1407 self.maxNumberTrackingIterations = config.getint(self.sectionHeader, 'max-number-iterations') | |
1408 self.minTrackingError = config.getfloat(self.sectionHeader, 'min-tracking-error') | |
1409 self.featureFlags = config.getboolean(self.sectionHeader, 'feature-flag') | |
1410 self.minFeatureEigThreshold = config.getfloat(self.sectionHeader, 'min-feature-eig-threshold') | |
1411 self.minFeatureTime = config.getint(self.sectionHeader, 'min-feature-time') | |
1412 self.minFeatureDisplacement = config.getfloat(self.sectionHeader, 'min-feature-displacement') | |
1413 self.updateTimer = config.getint(self.sectionHeader, 'tracker-reload-time') | |
1414 | |
1415 def loadHomographyConfig(self, filename = None): | |
1416 | |
1417 if filename is None: | |
1418 self.homographyFilename = None | |
1419 self.homography = None | |
1420 else : | |
1421 from configparser import ConfigParser | |
1422 config = ConfigParser(strict=False) | |
1423 config.read_file(addSectionHeader(utils.openCheck(filename))) | |
1424 parentPath = Path(filename).parent | |
1425 self.sectionHeader = config.sections()[0] | |
1426 self.homographyFilename = utils.getRelativeFilename(parentPath, config.get(self.sectionHeader, 'homography-filename')) | |
1427 if Path(self.homographyFilename).exists(): | |
1428 self.homography = loadtxt(self.homographyFilename) | |
1429 else: | |
1430 self.homography = None | |
1431 | |
1432 def loadDistortionConfig(self, filename = None): | |
1433 if filename is None: | |
1434 self.intrinsicCameraFilename = None | |
1435 self.intrinsicCameraMatrix = None | |
1436 self.distortionCoefficients = None | |
1437 self.undistort = False | |
1438 self.undistortedImageMultiplication = 1. | |
1439 else: | |
1440 from configparser import ConfigParser | |
1441 config = ConfigParser(strict=False) | |
1442 config.read_file(addSectionHeader(utils.openCheck(filename))) | |
1443 parentPath = Path(filename).parent | |
1444 self.sectionHeader = config.sections()[0] | |
1445 self.intrinsicCameraFilename = utils.getRelativeFilename(parentPath, config.get(self.sectionHeader, 'intrinsic-camera-filename')) | |
1446 if Path(self.intrinsicCameraFilename).exists(): | |
1447 self.intrinsicCameraMatrix = loadtxt(self.intrinsicCameraFilename) | |
1448 else: | |
1449 self.intrinsicCameraMatrix = None | |
1450 distortionCoefficients = getValuesFromINIFile(filename, 'distortion-coefficients', '=') | |
1451 self.distortionCoefficients = [float(x) for x in distortionCoefficients] | |
1452 self.undistortedImageMultiplication = config.getfloat(self.sectionHeader, 'undistorted-size-multiplication') | |
1453 self.undistort = config.getboolean(self.sectionHeader, 'undistort') | |
1454 | |
1366 | 1455 |
1367 def loadConfigFile(self, filename): | 1456 def loadConfigFile(self, filename): |
1368 from configparser import ConfigParser | 1457 from configparser import ConfigParser |
1369 | 1458 |
1370 config = ConfigParser(strict=False) | 1459 config = ConfigParser(strict=False) |
1390 self.undistortedImageMultiplication = config.getfloat(self.sectionHeader, 'undistorted-size-multiplication') | 1479 self.undistortedImageMultiplication = config.getfloat(self.sectionHeader, 'undistorted-size-multiplication') |
1391 self.undistort = config.getboolean(self.sectionHeader, 'undistort') | 1480 self.undistort = config.getboolean(self.sectionHeader, 'undistort') |
1392 self.firstFrameNum = config.getint(self.sectionHeader, 'frame1') | 1481 self.firstFrameNum = config.getint(self.sectionHeader, 'frame1') |
1393 self.videoFrameRate = config.getfloat(self.sectionHeader, 'video-fps') | 1482 self.videoFrameRate = config.getfloat(self.sectionHeader, 'video-fps') |
1394 | 1483 |
1395 self.minFeatureTime = config.getfloat(self.sectionHeader, 'min-feature-time') | 1484 self.minFeatureTime = config.getint(self.sectionHeader, 'min-feature-time') |
1396 | 1485 |
1397 self.classifierFilename = utils.getRelativeFilename(parentPath, config.get(self.sectionHeader, 'classifier-filename')) | 1486 self.classifierFilename = utils.getRelativeFilename(parentPath, config.get(self.sectionHeader, 'classifier-filename')) |
1398 | 1487 |
1399 # Safety parameters | 1488 # Safety parameters |
1400 self.maxPredictedSpeed = config.getfloat(self.sectionHeader, 'max-predicted-speed')/3.6/self.videoFrameRate | 1489 self.maxPredictedSpeed = config.getfloat(self.sectionHeader, 'max-predicted-speed')/3.6/self.videoFrameRate |
1411 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') | 1500 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') |
1412 self.constantSpeedPrototypePrediction = config.getboolean(self.sectionHeader, 'constant-speed') | 1501 self.constantSpeedPrototypePrediction = config.getboolean(self.sectionHeader, 'constant-speed') |
1413 self.maxLcssDistance = config.getfloat(self.sectionHeader, 'max-lcss-distance') | 1502 self.maxLcssDistance = config.getfloat(self.sectionHeader, 'max-lcss-distance') |
1414 self.lcssMetric = config.get(self.sectionHeader, 'lcss-metric') | 1503 self.lcssMetric = config.get(self.sectionHeader, 'lcss-metric') |
1415 self.minLcssSimilarity = config.getfloat(self.sectionHeader, 'min-lcss-similarity') | 1504 self.minLcssSimilarity = config.getfloat(self.sectionHeader, 'min-lcss-similarity') |
1505 | |
1506 self.configFilename = filename | |
1416 | 1507 |
1417 def __init__(self, filename = None): | 1508 def __init__(self, filename = None): |
1418 if filename is not None and Path(filename).exists(): | 1509 if filename is not None and Path(filename).exists(): |
1419 self.loadConfigFile(filename) | 1510 self.loadConfigFile(filename) |
1420 else: | 1511 else: |
1421 print('Configuration filename {} could not be loaded.'.format(filename)) | 1512 print('Configuration filename {} could not be loaded.'.format(filename)) |
1513 self.configFilename = filename | |
1422 | 1514 |
1423 def processVideoArguments(args): | 1515 def processVideoArguments(args): |
1424 '''Loads information from configuration file | 1516 '''Loads information from configuration file |
1425 then checks what was passed on the command line | 1517 then checks what was passed on the command line |
1426 for override (eg video filename and database filename''' | 1518 for override (eg video filename and database filename''' |