def _validate_added_image_or_die(img_path): # Make sure we actually received a valid image file, clean it up and bail if not so. try: sly_image.validate_format(img_path) except (sly_image.UnsupportedImageFormat, sly_image.ImageReadException): os.remove(img_path) raise
def _add_img_file(self, item_name, img_path): self._check_add_item_name(item_name) dst_img_path = os.path.join(self.img_dir, item_name) if img_path != dst_img_path: # used only for agent + api during download project copy_file(img_path, dst_img_path) # Make sure we actually received a valid image file, clean it up and bail if not so. try: sly_image.validate_format(dst_img_path) except sly_image.UnsupportedImageFormat: os.remove(dst_img_path) raise self._item_to_ann[item_name] = item_name + ANN_EXT