def open(self, config): self.path_config = config.get_string("path") if not os.path.isdir(self.path_config): return modelbox.Status(modelbox.Status.StatusCode.STATUS_FAULT) batch = config.get_int("batch_size", 1) if batch != 10: return modelbox.Status(modelbox.Status.StatusCode.STATUS_FAULT, "invalid batch") self.__thread1 = SendExternThread(self) self.__thread1.start() return modelbox.Status()
def process(self, data_ctx): in_bl = data_ctx.input("buffer_in") out_bl = data_ctx.output("buffer_out") empty_np = np.array([]) empty_buffer = self.create_buffer(empty_np) for buffer in in_bl: np_image = np.array(buffer, copy= False) image = Image.fromarray(np_image) brightness_array = np.array(image) add_buffer = modelbox.Buffer(self.get_bind_device(), brightness_array) add_buffer.copy_meta(buffer) add_buffer.set("float_test", 0.5) add_buffer.set("string_test", "TEST") add_buffer.set("int_test", 100) add_buffer.set("bool_test", False) add_buffer.set("list_int_test", [1, 1, 1]) add_buffer.set("list_float_test", [0.1, 0.2, 0.3]) add_buffer.set("list_bool_test", [False, False, True]) add_buffer.set("list_string_test", ["TEST1", "TEST2", "TEST3"]) try: add_buffer.set("map_test", {"test" : 1}) except ValueError as err: modelbox.info(str(err)) else: return modelbox.Status.StatusCode.STATUS_SHUTDOWN out_bl.push_back(add_buffer) return modelbox.Status()
def process(self, data_ctx): extern_bl = data_ctx.external() out_bl = data_ctx.output("image_out/out_1") for buffer in extern_bl: out_bl.push_back(buffer) return modelbox.Status()
def open(self, config): self.__out_path_config = config.get_string("out_path") if not os.path.exists(self.__out_path_config): os.mkdir(self.__out_path_config) self.__is_save_config = config.get_bool("is_save") if self.__is_save_config == True: self.__out_path_config = config.get_string("out_path", "./") if not os.path.exists(self.__out_path_config): os.mkdir(self.__out_path_config) self.__out_file = self.__out_path_config + '/python_test_show_out.png' if os.path.exists(self.__out_file): os.remove(self.__out_file) self.__check_path = config.get_string("check_path") if not os.path.exists(self.__check_path): return modelbox.Status(modelbox.Status.StatusCode.STATUS_FAULT, "invalid check file path, it is not exist") return modelbox.Status()
def process(self, data_ctx): in_bl = data_ctx.input("brightness_in") out_bl = data_ctx.output("brightness_out") for buffer in in_bl: np_image = np.array(buffer, copy=False) image = Image.fromarray(np_image) brightness_image = ImageEnhance.Brightness(image).enhance( self.__brightness) brightness_array = np.array(brightness_image) add_buffer = self.create_buffer(brightness_array) add_buffer.copy_meta(buffer) add_buffer.set("brightness", self.__brightness) out_bl.push_back(add_buffer) return modelbox.Status()
def process(self, data_ctx): in_bl = data_ctx.input("show_in") for buffer in in_bl: np_image = np.array(buffer, copy= False) if np_image.shape[0] != 360: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid height") if np_image.shape[1] != 480: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid width") if np_image.shape[2] != 3: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid channels") brightness = buffer.get("brightness") if brightness != 0.1: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid brightness") image = Image.fromarray(np_image) if self.__is_save_config == True: image.save(self.__out_file) with Image.open(self.__check_path) as check_image: try: diff = ImageChops.difference(image, check_image) if diff.getbbox() is not None: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid check image") except ValueError as e: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid check image size") check_image.close() modelbox.info("ShowFlowunit process") return modelbox.Status(modelbox.Status.StatusCode.STATUS_STOP)
def close(self): # Close the flowunit return modelbox.Status()
def data_group_post(self, data_ctx): return modelbox.Status()
def data_pre(self, data_ctx): return modelbox.Status()
def close(self): return modelbox.Status()
def open(self, config): self.__brightness = config.get_float("brightness", 0.0) if self.__brightness == 0.0: return modelbox.Status.StatusCode.STATUS_FAULT return modelbox.Status()
def close(self): self.__thread1.join() return modelbox.Status()
def data_group_pre(self, data_context): return modelbox.Status()
def data_group_pre(self, data_context): # Before all streaming data starts return modelbox.Status()
def data_post(self, data_context): return modelbox.Status()
def data_group_post(self, data_context): # After all streaming data ends return modelbox.Status()
def open(self, config): self.__brightness = config.get_float("buffer_config", 0.0) if self.__brightness != 0.2: return modelbox.Status(modelbox.Status.StatusCode.STATUS_FAULT) return modelbox.Status()