comparison python/storage.py @ 1003:75af46516b2b

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 01 Jun 2018 17:19:31 -0400
parents 933670761a57
children 75601be6019f
comparison
equal deleted inserted replaced
1002:6c5ce3ec497e 1003:75af46516b2b
3 '''Various utilities to save and load data''' 3 '''Various utilities to save and load data'''
4 4
5 import utils, moving, events, indicators, shutil 5 import utils, moving, events, indicators, shutil
6 from base import VideoFilenameAddable 6 from base import VideoFilenameAddable
7 7
8 from os import path 8 from pathlib import Path
9 from copy import copy 9 from copy import copy
10 import sqlite3, logging 10 import sqlite3, logging
11 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg 11 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg
12 from pandas import read_csv, merge 12 from pandas import read_csv, merge
13 13
41 except sqlite3.OperationalError as error: 41 except sqlite3.OperationalError as error:
42 printDBError(error) 42 printDBError(error)
43 43
44 def deleteFromSqlite(filename, dataType): 44 def deleteFromSqlite(filename, dataType):
45 'Deletes (drops) some tables in the filename depending on type of data' 45 'Deletes (drops) some tables in the filename depending on type of data'
46 if path.isfile(filename): 46 if Path(filename).is_file():
47 with sqlite3.connect(filename) as connection: 47 with sqlite3.connect(filename) as connection:
48 if dataType == 'object': 48 if dataType == 'object':
49 dropTables(connection, ['objects', 'objects_features']) 49 dropTables(connection, ['objects', 'objects_features'])
50 elif dataType == 'interaction': 50 elif dataType == 'interaction':
51 dropTables(connection, ['interactions', 'indicators']) 51 dropTables(connection, ['interactions', 'indicators'])
1305 self.scaleCyclistSpeed = config.getfloat(self.sectionHeader, 'cyc-speed-scale') 1305 self.scaleCyclistSpeed = config.getfloat(self.sectionHeader, 'cyc-speed-scale')
1306 self.meanVehicleSpeed = config.getfloat(self.sectionHeader, 'mean-veh-speed') 1306 self.meanVehicleSpeed = config.getfloat(self.sectionHeader, 'mean-veh-speed')
1307 self.stdVehicleSpeed = config.getfloat(self.sectionHeader, 'std-veh-speed') 1307 self.stdVehicleSpeed = config.getfloat(self.sectionHeader, 'std-veh-speed')
1308 1308
1309 def __init__(self, filename = None): 1309 def __init__(self, filename = None):
1310 if filename is not None and path.exists(filename): 1310 if filename is not None and Path(filename).exists():
1311 self.loadConfigFile(filename) 1311 self.loadConfigFile(filename)
1312 else: 1312 else:
1313 print('Configuration filename {} could not be loaded.'.format(filename)) 1313 print('Configuration filename {} could not be loaded.'.format(filename))
1314 1314
1315 def convertToFrames(self, frameRate, speedRatio = 3.6): 1315 def convertToFrames(self, frameRate, speedRatio = 3.6):
1348 self.sectionHeader = config.sections()[0] 1348 self.sectionHeader = config.sections()[0]
1349 # Tracking/display parameters 1349 # Tracking/display parameters
1350 self.videoFilename = config.get(self.sectionHeader, 'video-filename') 1350 self.videoFilename = config.get(self.sectionHeader, 'video-filename')
1351 self.databaseFilename = config.get(self.sectionHeader, 'database-filename') 1351 self.databaseFilename = config.get(self.sectionHeader, 'database-filename')
1352 self.homographyFilename = config.get(self.sectionHeader, 'homography-filename') 1352 self.homographyFilename = config.get(self.sectionHeader, 'homography-filename')
1353 if path.exists(self.homographyFilename): 1353 if Path(self.homographyFilename).exists():
1354 self.homography = loadtxt(self.homographyFilename) 1354 self.homography = loadtxt(self.homographyFilename)
1355 else: 1355 else:
1356 self.homography = None 1356 self.homography = None
1357 self.intrinsicCameraFilename = config.get(self.sectionHeader, 'intrinsic-camera-filename') 1357 self.intrinsicCameraFilename = config.get(self.sectionHeader, 'intrinsic-camera-filename')
1358 if path.exists(self.intrinsicCameraFilename): 1358 if Path(self.intrinsicCameraFilename).exists():
1359 self.intrinsicCameraMatrix = loadtxt(self.intrinsicCameraFilename) 1359 self.intrinsicCameraMatrix = loadtxt(self.intrinsicCameraFilename)
1360 else: 1360 else:
1361 self.intrinsicCameraMatrix = None 1361 self.intrinsicCameraMatrix = None
1362 distortionCoefficients = getValuesFromINIFile(filename, 'distortion-coefficients', '=') 1362 distortionCoefficients = getValuesFromINIFile(filename, 'distortion-coefficients', '=')
1363 self.distortionCoefficients = [float(x) for x in distortionCoefficients] 1363 self.distortionCoefficients = [float(x) for x in distortionCoefficients]
1387 self.maxLcssDistance = config.getfloat(self.sectionHeader, 'max-lcss-distance') 1387 self.maxLcssDistance = config.getfloat(self.sectionHeader, 'max-lcss-distance')
1388 self.lcssMetric = config.get(self.sectionHeader, 'lcss-metric') 1388 self.lcssMetric = config.get(self.sectionHeader, 'lcss-metric')
1389 self.minLcssSimilarity = config.getfloat(self.sectionHeader, 'min-lcss-similarity') 1389 self.minLcssSimilarity = config.getfloat(self.sectionHeader, 'min-lcss-similarity')
1390 1390
1391 def __init__(self, filename = None): 1391 def __init__(self, filename = None):
1392 if filename is not None and path.exists(filename): 1392 if filename is not None and Path(filename).exists():
1393 self.loadConfigFile(filename) 1393 self.loadConfigFile(filename)
1394 else: 1394 else:
1395 print('Configuration filename {} could not be loaded.'.format(filename)) 1395 print('Configuration filename {} could not be loaded.'.format(filename))
1396 1396
1397 def processVideoArguments(args): 1397 def processVideoArguments(args):