def load_idx(self, idx, **kwargs): if self.rgb_f is None: raise ValueError("Please call open_file() first!") self.rgb_f.seek(0) self.rgb_f.seek(idx) image = self.rgb_f kwds = {} try: self._get_header(image, kwds) except Exception as e: self.logger.warning("Failed to get image metadata: %s" % (str(e))) metadata = dict(header=kwds) # convert to working color profile, if can if self.clr_mgr.can_profile(): image = self.clr_mgr.profile_to_working_pil(image, kwds) # convert from PIL to numpy data_np = np.array(image) from ginga.RGBImage import RGBImage data_obj = RGBImage(data_np=data_np, logger=self.logger) data_obj.io = self name = self.fileinfo.name + '[{}]'.format(idx) data_obj.set(name=name, path=self.fileinfo.filepath, idx=idx, header=kwds) return data_obj
def load_idx(self, idx, **kwargs): if self.rgb_f is None: raise ValueError("Please call open_file() first!") if idx is None: idx = 0 self.rgb_f.set(cv2.CAP_PROP_POS_FRAMES, idx) okay, data_np = self.rgb_f.read() if not okay: raise ValueError("Error reading index {}".format(idx)) metadata = {} data_np = self._process_opencv_array(data_np, metadata, self.fileinfo.filepath) from ginga.RGBImage import RGBImage data_obj = RGBImage(data_np=data_np, logger=self.logger, order=metadata['order'], metadata=metadata) data_obj.io = self name = self.fileinfo.name + '[{}]'.format(idx) data_obj.set(name=name, path=self.fileinfo.filepath, idx=idx) return data_obj
def load_idx(self, idx, **kwargs): if self.rgb_f is None: raise ValueError("Please call open_file() first!") # TODO: idx ignored for now for RGB images! #self.rgb_f.seek(0) #print(dir(self.rgb_f)) okay, data_np = self.rgb_f.read() if not okay: raise ValueError("Error reading index {}".format(idx)) # funky indexing because opencv returns BGR images, # whereas PIL and others return RGB if len(data_np.shape) >= 3 and data_np.shape[2] >= 3: data_np = data_np[..., ::-1] # OpenCv doesn't "do" image metadata, so we punt to piexif # library (if installed) kwds = {} self.piexif_getexif(self._path, kwds) # OpenCv added a feature to do auto-orientation when loading # (see https://github.com/opencv/opencv/issues/4344) # So reset these values to prevent auto-orientation from # happening later kwds['Orientation'] = 1 kwds['Image Orientation'] = 1 # convert to working color profile, if can if self.clr_mgr.can_profile(): data_np = self.clr_mgr.profile_to_working_numpy(data_np, kwds) from ginga.RGBImage import RGBImage data_obj = RGBImage(data_np=data_np, logger=self.logger) data_obj.io = self name = self.fileinfo.name + '[{}]'.format(idx) data_obj.set(name=name, path=self.fileinfo.filepath, idx=idx, header=kwds) return data_obj