tvaLib
Public Member Functions | Public Attributes | List of all members
lib.scene.Sequence Class Reference

Declare Scene descriptor object. More...

Inheritance diagram for lib.scene.Sequence:

Public Member Functions

def __init__ (self, sequence, config)
 
def getBaseDirectory (self)
 
def getFullDataFilename (self)
 
def getFullSerialisedFilename (self)
 
def getFullClassifiedFilename (self)
 
def getFullGroundTruthFilename (self)
 
def getFullAnnotationFilename (self)
 
def getFullEventsFilename (self)
 
def getFullEventsCSVFilename (self)
 
def getFullVideoFilename (self, forceDistorted=False, allowNonExistant=False)
 
def getImageSpaceFrameFilename (self, forceDistorted=False, allowNonExistant=False)
 
def write (self, sequence)
 
def getYear (self)
 
def getMonth (self)
 
def getDay (self)
 
def getHour (self)
 
def getMinute (self)
 
def getSecond (self)
 
def getWeekday (self)
 
def getStartTime (self)
 
def getEndTime (self)
 
def getDuration (self)
 
def isParallelSequenceTo (self, sequence, maxDiffSec=60)
 
def setCountsFromObjects (self, objects)
 
def setCountObjects (self, value)
 
def setCountUserType (self, value, i)
 
def setCountObjOld (self, value)
 
def setCountExpPairs (self, value)
 
def setCountExpInstances (self, value)
 
def setCountExpPairsWInd (self, value)
 
def setCountExpInstancesWInd (self, value)
 
def setDuration (self, value)
 
def setRotation (self, value)
 
def setTranslation (self, x, y)
 
def exportToCode (self, moduleName='tvaMetaData')
 
def loadObjects (self, filename_override='', max_obj=None, max_obj_features=999, suppress_features=False, load_gt=False, indent=0, verbose=0)
 
def loadAnnotations (self, forceNonGTFilename=False, indent=0, legacy=False, verbose=0)
 

Public Attributes

 config
 Metadata. More...
 
 idx
 
 cameraView
 
 videoFilename
 
 dataFilename
 
 name
 
 startTime
 
 duration
 
 durationUnit
 
 translationX
 
 translationY
 
 rotation
 
 legacy
 Internal data. More...
 
 countObjects
 
 countObjOld
 
 countExpPairs
 
 countExpInstances
 
 countExpPairsWInd
 
 countExpInstancesWInd
 
 countByType
 

Detailed Description

Declare Scene descriptor object.

Definition at line 405 of file scene.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.scene.Sequence.__init__ (   self,
  sequence,
  config 
)

Definition at line 406 of file scene.py.

406  def __init__(self, sequence, config):
407 
408  self.config = config
409  self.idx = sequence.idx
410  self.cameraView = sequence.cameraView
411  self.videoFilename = sequence.videoFilename
412  self.dataFilename = sequence.dataFilename
413  self.name = os.path.splitext(self.dataFilename)[0]
414  self.startTime = sequence.startTime
415  self.duration = sequence.duration
416  self.durationUnit = sequence.durationUnit
417  self.translationX = sequence.translationX
418  self.translationY = sequence.translationY
419  self.rotation = sequence.rotation
420  self.legacy = False
421 
422  if(os.path.splitext(self.dataFilename)[-1] == '.sqlite'): self.legacy = False
423  else: self.legacy = True
424  self.countObjects = 0
425  self.countObjOld = 0
426  self.countExpPairs = 0
427  self.countExpInstances = 0
428  self.countExpPairsWInd = 0
429  self.countExpInstancesWInd = 0
430  self.countByType = dict((x,0) for x in range(7))
431  return
432 
433 

Member Function Documentation

◆ exportToCode()

def lib.scene.Sequence.exportToCode (   self,
  moduleName = 'tvaMetaData' 
)

Definition at line 502 of file scene.py.

502  def exportToCode(self, moduleName='tvaMetaData'):
503  print("sequences.append("+moduleName+".VideoSequence([x for x in cameras if x.name=='"+self.cameraView.name+"' and x.site.name=='"+self.cameraView.site.name+"'][0], '"+self.videoFilename+"', '"+str(self.startTime)+"', "+str(self.duration)+"))")
504 

◆ getBaseDirectory()

def lib.scene.Sequence.getBaseDirectory (   self)

Definition at line 434 of file scene.py.

434  def getBaseDirectory(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name)

◆ getDay()

def lib.scene.Sequence.getDay (   self)

Definition at line 470 of file scene.py.

470  def getDay(self): return self.startTime.day

◆ getDuration()

def lib.scene.Sequence.getDuration (   self)

Definition at line 477 of file scene.py.

477  def getDuration(self): return self.duration
478 

◆ getEndTime()

def lib.scene.Sequence.getEndTime (   self)

Definition at line 476 of file scene.py.

476  def getEndTime(self): return self.startTime+timedelta(0,self.duration)

◆ getFullAnnotationFilename()

def lib.scene.Sequence.getFullAnnotationFilename (   self)

Definition at line 439 of file scene.py.

439  def getFullAnnotationFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'.annotation')

◆ getFullClassifiedFilename()

def lib.scene.Sequence.getFullClassifiedFilename (   self)

Definition at line 437 of file scene.py.

437  def getFullClassifiedFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-cl.sqlite')

◆ getFullDataFilename()

def lib.scene.Sequence.getFullDataFilename (   self)

Definition at line 435 of file scene.py.

435  def getFullDataFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.dataFilename)

◆ getFullEventsCSVFilename()

def lib.scene.Sequence.getFullEventsCSVFilename (   self)

Definition at line 441 of file scene.py.

441  def getFullEventsCSVFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-events.csv')

◆ getFullEventsFilename()

def lib.scene.Sequence.getFullEventsFilename (   self)

Definition at line 440 of file scene.py.

440  def getFullEventsFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'.events')

◆ getFullGroundTruthFilename()

def lib.scene.Sequence.getFullGroundTruthFilename (   self)

Definition at line 438 of file scene.py.

438  def getFullGroundTruthFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-gt.sqlite')

◆ getFullSerialisedFilename()

def lib.scene.Sequence.getFullSerialisedFilename (   self)

Definition at line 436 of file scene.py.

436  def getFullSerialisedFilename(self): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'.traj')

◆ getFullVideoFilename()

def lib.scene.Sequence.getFullVideoFilename (   self,
  forceDistorted = False,
  allowNonExistant = False 
)

Definition at line 442 of file scene.py.

442  def getFullVideoFilename(self, forceDistorted=False, allowNonExistant=False):
443  if(self.cameraView.camera.camera_matrix and forceDistorted): name = self.name+'-undistort.avi'
444  else: name = self.videoFilename
445  if(allowNonExistant): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, name)
446  elif(os.path.exists(os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, name))): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, name)
447  else: return ''

◆ getHour()

def lib.scene.Sequence.getHour (   self)

Definition at line 471 of file scene.py.

471  def getHour(self): return self.startTime.hour

◆ getImageSpaceFrameFilename()

def lib.scene.Sequence.getImageSpaceFrameFilename (   self,
  forceDistorted = False,
  allowNonExistant = False 
)

Definition at line 448 of file scene.py.

448  def getImageSpaceFrameFilename(self, forceDistorted=False, allowNonExistant=False):
449  if(self.cameraView.camera.camera_matrix and forceDistorted): undistort = '-undistort'
450  else: undistort = ''
451  if(os.path.exists(os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+undistort+'.png'))): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+undistort+'.png')
452  elif(allowNonExistant): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-frame'+undistort+'.png')
453  elif(os.path.exists(os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-frame'+undistort+'.png'))): return os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.name+'-frame'+undistort+'.png')
454  else: return tvaLib.crawlDirsForFilePattern(pattern='*frame'+undistort+'.png', path=os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name), returnList=False)
455 

◆ getMinute()

def lib.scene.Sequence.getMinute (   self)

Definition at line 472 of file scene.py.

472  def getMinute(self): return self.startTime.minute

◆ getMonth()

def lib.scene.Sequence.getMonth (   self)

Definition at line 469 of file scene.py.

469  def getMonth(self): return self.startTime.month

◆ getSecond()

def lib.scene.Sequence.getSecond (   self)

Definition at line 473 of file scene.py.

473  def getSecond(self): return self.startTime.second

◆ getStartTime()

def lib.scene.Sequence.getStartTime (   self)

Definition at line 475 of file scene.py.

475  def getStartTime(self): return self.startTime

◆ getWeekday()

def lib.scene.Sequence.getWeekday (   self)

Definition at line 474 of file scene.py.

474  def getWeekday(self): return self.startTime.weekday()+1 # From 1 to 7 where Monday=1 and Sunday = 7

◆ getYear()

def lib.scene.Sequence.getYear (   self)

Definition at line 468 of file scene.py.

468  def getYear(self): return self.startTime.year

◆ isParallelSequenceTo()

def lib.scene.Sequence.isParallelSequenceTo (   self,
  sequence,
  maxDiffSec = 60 
)

Definition at line 479 of file scene.py.

479  def isParallelSequenceTo(self, sequence, maxDiffSec=60):
480  timedelta = self.startTime - sequence.startTime
481  if(timedelta.seconds > maxDiffSec or timedelta.seconds < -maxDiffSec): return False
482  else: return True
483 
484 

◆ loadAnnotations()

def lib.scene.Sequence.loadAnnotations (   self,
  forceNonGTFilename = False,
  indent = 0,
  legacy = False,
  verbose = 0 
)
Manage annotation loading according to sequence settings and commands. 

Definition at line 546 of file scene.py.

546  def loadAnnotations(self, forceNonGTFilename=False, indent=0, legacy=False, verbose=0):
547  ''' Manage annotation loading according to sequence settings and commands. '''
548 
549  from sys import stdout;oldstdout = stdout;stdout = tvaConfig.NullWriter()
550  try: import storage as TrafIntStorage
551  finally: stdout = oldstdout
552 
553 
554  if(legacy):
555  if(forceNonGTFilename): objects = TrafIntStorage.loadGroundTruthFromSqlite(self.getFullDataFilename())
556  else: objects = TrafIntStorage.loadGroundTruthFromSqlite(self.getFullGroundTruthFilename())
557  homography = np.loadtxt(os.path.join(self.config.dir, self.cameraView.site.name, self.cameraView.name, self.cameraView.homographyFilename))
558  for obj in objects:
559  obj.computeCentroidTrajectory(homography)
560 
562  else:
563  if(forceNonGTFilename): objects = TrafIntStorage.loadTrajectoriesFromSqlite(self.getFullDataFilename(), 'object')
564  else: objects = TrafIntStorage.loadTrajectoriesFromSqlite(self.getFullGroundTruthFilename(), 'object')
565 
566 
567  if(verbose): print(''.rjust(indent,' ')+'Finished loading {0} annotations.'.format(len(objects)))
568  return objects
569 

◆ loadObjects()

def lib.scene.Sequence.loadObjects (   self,
  filename_override = '',
  max_obj = None,
  max_obj_features = 999,
  suppress_features = False,
  load_gt = False,
  indent = 0,
  verbose = 0 
)
Manage trajectory loading according to sequence settings and commands. 

Definition at line 505 of file scene.py.

505  def loadObjects(self, filename_override='', max_obj=None, max_obj_features=999, suppress_features=False, load_gt=False, indent=0, verbose=0):
506  ''' Manage trajectory loading according to sequence settings and commands. '''
507 
508  if(self.legacy): from ubc_utils import loadTrajectories
509  else:
510  from sys import stdout;oldstdout = stdout;stdout = tvaConfig.NullWriter()
511  try: import storage as TrafIntStorage
512  finally: stdout = oldstdout
513 
514 
515  if(filename_override): path_to_file = os.path.join(self.getBaseDirectory(), filename_override)
516  else: path_to_file = self.getFullDataFilename()
517  if(not os.path.exists(path_to_file)): raise Exception, [383, 'Unable to locate trajectory file on disk "'+path_to_file+'".']
518 
519 
520  objects = None
521  if(max_obj==-1): max_obj = None
522  if(not load_gt):
523  if(self.legacy): objects = loadTrajectories(path_to_file, max_obj)
524  else: objects = TrafIntStorage.loadTrajectoriesFromSqlite(path_to_file, 'object', max_obj)
525 
526  if(not objects or load_gt): return self.loadAnnotations(indent=indent, verbose=verbose)
527 
528 
529  if(not suppress_features):
530  if(self.legacy): features = loadTrajectories(os.path.join(self.getBaseDirectory(), self.name+'-features.txt'))
531  else: features = TrafIntStorage.loadTrajectoriesFromSqlite(path_to_file, 'feature')
532  for j in range(len(objects)):
533  #try:
534  objects[j].featureNumbers = tvaLib.Math.sample(objects[j].featureNumbers, sampleSize=max_obj_features, method='interpolation')
535  objects[j].setFeatures(features)
536  #except:
537  # from tools import printWarning as tvaLib_printWarning
538  # tvaLib_printWarning('There was a problem with the integrity of the feature database at object '+str(j)+' out of '+str(len(objects))+': some features are missing. This object will be dropped and analysis will continue...', 'Warning')
539  # objects[j] = None
540  objects = filter(None, objects)
541 
542 
543  if(verbose): print(''.rjust(indent,' ')+'Finished loading {0} objects.'.format(len(objects)))
544  return objects
545 
def loadObjects(sequencepath, max_obj=None, max_obj_features=999, suppress_features=False, legacy=False, legacy_features_path='')
The following functions are used for manipulating object data from Traffic-Intelligence.
Definition: tools_obj.py:521

◆ setCountExpInstances()

def lib.scene.Sequence.setCountExpInstances (   self,
  value 
)

Definition at line 492 of file scene.py.

492  def setCountExpInstances(self, value): self.countExpInstances = value

◆ setCountExpInstancesWInd()

def lib.scene.Sequence.setCountExpInstancesWInd (   self,
  value 
)

Definition at line 494 of file scene.py.

494  def setCountExpInstancesWInd(self, value): self.countExpInstancesWInd = value

◆ setCountExpPairs()

def lib.scene.Sequence.setCountExpPairs (   self,
  value 
)

Definition at line 491 of file scene.py.

491  def setCountExpPairs(self, value): self.countExpPairs = value

◆ setCountExpPairsWInd()

def lib.scene.Sequence.setCountExpPairsWInd (   self,
  value 
)

Definition at line 493 of file scene.py.

493  def setCountExpPairsWInd(self, value): self.countExpPairsWInd = value

◆ setCountObjects()

def lib.scene.Sequence.setCountObjects (   self,
  value 
)

Definition at line 488 of file scene.py.

488  def setCountObjects(self, value): self.countObjects = value

◆ setCountObjOld()

def lib.scene.Sequence.setCountObjOld (   self,
  value 
)

Definition at line 490 of file scene.py.

490  def setCountObjOld(self, value): self.countObjOld = value

◆ setCountsFromObjects()

def lib.scene.Sequence.setCountsFromObjects (   self,
  objects 
)

Definition at line 485 of file scene.py.

485  def setCountsFromObjects(self, objects):
486  self.setCountObjects(len(objects))
487  for userType in self.countByType: self.setCountUserType(len([1 for obj in objects if obj.userType==userType]), userType)

◆ setCountUserType()

def lib.scene.Sequence.setCountUserType (   self,
  value,
  i 
)

Definition at line 489 of file scene.py.

489  def setCountUserType(self, value, i): self.countByType[i] = value

◆ setDuration()

def lib.scene.Sequence.setDuration (   self,
  value 
)

Definition at line 495 of file scene.py.

495  def setDuration(self, value): self.duration = value

◆ setRotation()

def lib.scene.Sequence.setRotation (   self,
  value 
)

Definition at line 496 of file scene.py.

496  def setRotation(self, value): self.rotation = value

◆ setTranslation()

def lib.scene.Sequence.setTranslation (   self,
  x,
  y 
)

Definition at line 497 of file scene.py.

497  def setTranslation(self, x, y):
498  self.translationX = x
499  self.translationY = y
500 
501 

◆ write()

def lib.scene.Sequence.write (   self,
  sequence 
)

Definition at line 456 of file scene.py.

456  def write(self, sequence):
457  sequence.idx = self.idx
458  sequence.videoFilename = self.videoFilename
459  sequence.dataFilename = self.dataFilename
460  sequence.startTime = self.startTime
461  sequence.duration = self.duration
462  sequence.durationUnit = self.durationUnit
463  sequence.translationX = self.translationX
464  sequence.translationY = self.translationY
465  sequence.rotation = self.rotation
466  return sequence
467 

Member Data Documentation

◆ cameraView

lib.scene.Sequence.cameraView

Definition at line 410 of file scene.py.

◆ config

lib.scene.Sequence.config

Metadata.

Definition at line 408 of file scene.py.

◆ countByType

lib.scene.Sequence.countByType

Definition at line 430 of file scene.py.

◆ countExpInstances

lib.scene.Sequence.countExpInstances

Definition at line 427 of file scene.py.

◆ countExpInstancesWInd

lib.scene.Sequence.countExpInstancesWInd

Definition at line 429 of file scene.py.

◆ countExpPairs

lib.scene.Sequence.countExpPairs

Definition at line 426 of file scene.py.

◆ countExpPairsWInd

lib.scene.Sequence.countExpPairsWInd

Definition at line 428 of file scene.py.

◆ countObjects

lib.scene.Sequence.countObjects

Definition at line 424 of file scene.py.

◆ countObjOld

lib.scene.Sequence.countObjOld

Definition at line 425 of file scene.py.

◆ dataFilename

lib.scene.Sequence.dataFilename

Definition at line 412 of file scene.py.

◆ duration

lib.scene.Sequence.duration

Definition at line 415 of file scene.py.

◆ durationUnit

lib.scene.Sequence.durationUnit

Definition at line 416 of file scene.py.

◆ idx

lib.scene.Sequence.idx

Definition at line 409 of file scene.py.

◆ legacy

lib.scene.Sequence.legacy

Internal data.

Definition at line 420 of file scene.py.

◆ name

lib.scene.Sequence.name

Definition at line 413 of file scene.py.

◆ rotation

lib.scene.Sequence.rotation

Definition at line 419 of file scene.py.

◆ startTime

lib.scene.Sequence.startTime

Definition at line 414 of file scene.py.

◆ translationX

lib.scene.Sequence.translationX

Definition at line 417 of file scene.py.

◆ translationY

lib.scene.Sequence.translationY

Definition at line 418 of file scene.py.

◆ videoFilename

lib.scene.Sequence.videoFilename

Definition at line 411 of file scene.py.


The documentation for this class was generated from the following file: