Source code for Cells
# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Class managing cells
import logging, cv2, imp
# import Cell module
Cell = imp.load_source("Cell", './bin/Movies/Cells/Cell.py')
[docs]class Cells :
def __init__(self, movie) :
self.movie = movie
self.cells_dict = {}
self.name_id = 0
[docs] def new_cell(self, name, begin=0, end='end') :
if end == end :
end = self.movie.get_frame_nb()
if name not in self.cells_dict.keys() :
c = Cell.Cell(self.movie, name, begin, end) # create cell
self.cells_dict[name] = c # register it
return c # return it
else :
logging.error("This cell name already exists")
[docs] def get_name(self) :
"""Function returns a name id that does not already exist"""
while str(self.name_id) in self.cells_dict.keys() :
self.name_id += 1
return self.name_id
[docs] def get_cells_dict(self) :
return self.cells_dict
[docs] def get_cell(self, name) :
"""Returns a cell given its name"""
if name in self.cells_dict.keys() :
return self.cells_dict[name]
else :
logging.error('The requesting cell %s does not exist', name)
[docs] def delete_cell(self, name) :
cell = self.cells_dict[name]
cell.delete()
[docs] def get_save_dict(self) :
dic = {}
dic['name_id'] = {'descr' : 'id of an unused cell', 'value' : self.name_id}
cells = {}
for c in self.cells_dict.keys() :
cells[c] = self.cells_dict[c].get_save_dict()
dic['cells'] = {'descr' : 'Dict containing all the cells', 'value' : cells}
return {'descr' : 'Cells information', 'value' : dic}
[docs] def load_save_dict(self, dic) :
self.name_id = dic['value']['name_id']['value']
cells_dic = dic['value']['cells']['value']
for name in cells_dic.keys() :
c = self.new_cell(name)
c.load_save_dict(cells_dic[name])