def run(self): 'Take pictures from selected cameras' while self.__control_data != -1: #Run infinite loop as the main application is running for i, cam in enumerate(self.__cameras): #if there isn't a camera selected it creates a None value, otherwise create a RGB Matrix try: cam(fast = False) self.__results[i] = cam.RGBimage except: self.__results[i] = None if self.__control_data: #Send list of RGB Matrix to main application only on request self.__sending_pipe.send(self.__results) self.__control_data = 0 self.__sending_data = self.__sending_pipe.recv() if self.__sending_pipe.poll() else self.__sending_data for i, cam in enumerate(self.__cameras): #Change or close camera devices as selected on the main application if ((cam == None) and (self.__sending_data[i] != None)): self.__cameras[i] = camera(self.__sending_data[i]) elif ((cam != None) and (self.__sending_data[i] == None)): self.__cameras[i].close() self.__cameras[i] = None elif ((cam != None) and (cam.device != (self.__sending_data[i]))): self.__cameras[i].close() self.__cameras[i] = None self.__cameras[i]= camera(self.__sending_data[i]) self.__control_data = self.__control_pipe.recv() if self.__control_pipe.poll() else self.__control_data for cam in self.__cameras: try: cam.close() except: pass return
def __init__(self, c_pipe, s_pipe, default_file, project_file): Process.__init__(self) self.__c_pipe = c_pipe self.__s_pipe = s_pipe self.__d_file = default_file self.__p_file = project_file cam_names = default_file.read('str', 'cameras', 'names') resolution = project_file.read('list', 'cameras', 'resolution') self.__config = [project_file.read('list', 'cameras', cam) for cam in cam_names] self.__colors = [project_file.read('np_array', 'colors', cam) for cam in cam_names] cam_numbers = [config[0] for config in self.__config] self.__cameras = [camera(num, resolution) for num in cam_numbers] self.__c_data = 1 # -1 stop process, 0 pause process, 1 start-resume process self.__s_data = 0 # 0 don't send images, 1 send images self.__init_time = None self.__time = None #Setting workers self.__results = range(4) self.__flag = 0 self.__c_pipes = [] self.__s_pipes = [] self.__workers = [] for index in xrange(3): c_, c_1 = Pipe() s_, s_1 = Pipe() w_ = worker(self.__config[index], self.__colors[index], c_1, s_1) w_.start() self.__c_pipes.append(c_) self.__s_pipes.append(s_) self.__workers.append(w_) return