def process(image: ndarray, horizontal_ratio: int, vertical_ratio: int, quality: int = 50): print("Encoding image with JPEG") t = clock() image = JPEG(image, quality) image.encode(horizontal_ratio, vertical_ratio) elapsed_time = clock() - t print("Encoding time: {}".format(round(elapsed_time, 2)) + " seconds") print("Decoding stream") t = clock() image.decode() elapsed_time = clock() - t print("Decoding time: {}".format(round(elapsed_time, 2)) + " seconds") return image
def value(self, new_value: np.ndarray): # Decode the attribute value if it's in byte form if isinstance(new_value, bytes): new_value = new_value.decode("utf-8") self.attr_dtype_combo.setCurrentText( _get_human_readable_type(new_value)) if np.isscalar(new_value): self.type_changed(SCALAR) self.attr_value_lineedit.setText(str(new_value)) else: self.type_changed(ARRAY) self.dialog.model.array = new_value self.dialog.model.update_array_dtype(new_value.dtype) self.dtype_changed(None)
def send_srd(self, state: np.ndarray, reward=None, done=False): state = state.astype(np.float32).tobytes() state = base64.b64encode(state) state = state.decode() self.send("SRD %s%s%s" % (state, "" if reward is None else (" %f" % reward), " DONE" if done else ""))