Source code for Loader

# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# This package provides an interface to load movies

# ==== Importations
import imp, logging, glob, sys, cv2, numpy

sys.path.append('./bin/Movies/Loader/')
import load_list_files   # Charger tous les modules (mettre ici, faute de mieux).
logging.debug("Modules loaded!")
[docs]class Loader : def __init__(self) : self.loaders_list = {'list_files' : load_list_files} self.img_paths = []
[docs] def load(self, inp, loader_name) : """Function that load the video files inside the Loader""" if self.img_paths != [] : logging.error("Loader already initialized") return self.img_paths if loader_name in self.loaders_list.keys() : self.img_paths = self.loaders_list[loader_name].Load(inp) return self.img_paths else : logging.error("The requested loader '%s' does not exist", loader_name) return self.img_paths
[docs] def get_frame_nb(self) : return len(self.img_paths)
[docs] def get_frame(self, index, rgb=True) : """Returns the image with the given index. Note that for the moment, the image is loaded at maximum depth (i.e. : can be 16bits), and converted to RGB autoatically. If a 8bits image is needed, consider the cv2.convertScaleAbs to change bit depth The rgb parameters indicates if the conversion should be performed.""" if (index < 0) or (index>len(self.img_paths)-1) : logging.error("The requested frame has an invalid index (%s)", str(index)) else : ##m = cv2.imread(self.img_paths[index]) # VERY experimental ##m.dtype=numpy.uint8 m = cv2.imread(self.img_paths[index], -1) # Loads the image as is if len(m.shape) < 3 and rgb: # Convert to RGB m=cv2.cvtColor(m, cv2.COLOR_GRAY2BGR) """m= m/numpy.max(m)*255 m=numpy.int_(m) m=m.astype(numpy.uint8) #m=cv2.convertScaleAbs(m) # Converts to 8 bits print (numpy.min(m), numpy.max(m)), m.shape, m.dtype""" return m
[docs] def get_size(self) : if len(self.img_paths) > 0 : im = cv2.imread(self.img_paths[0]) return im.shape else : logging.error("No movie has been instanciated in the Loader")
[docs] def get_save_dict(self) : dic = {} dic['img_paths'] = {'descr' : 'list of frames of the movie', 'value' : self.img_paths} return dic
[docs] def load_save_dict(self, dic) : ip = dic['value']['img_paths']['value'] self.img_paths = ip # The loader should check if the files still exist...