MCPcopy
hub / github.com/cvg/Hierarchical-Localization / __getitem__

Method __getitem__

hloc/extract_features.py:201–223  ·  view source on GitHub ↗
(self, idx)

Source from the content-addressed store, hash-verified

199 f'Image {name} does not exists in root: {root}.')
200
201 def __getitem__(self, idx):
202 name = self.names[idx]
203 image = read_image(self.root / name, self.conf.grayscale)
204 image = image.astype(np.float32)
205 size = image.shape[:2][::-1]
206
207 if self.conf.resize_max and (self.conf.resize_force
208 or max(size) > self.conf.resize_max):
209 scale = self.conf.resize_max / max(size)
210 size_new = tuple(int(round(x*scale)) for x in size)
211 image = resize_image(image, size_new, self.conf.interpolation)
212
213 if self.conf.grayscale:
214 image = image[None]
215 else:
216 image = image.transpose((2, 0, 1)) # HxWxC to CxHxW
217 image = image / 255.
218
219 data = {
220 'image': image,
221 'original_size': np.array(size),
222 }
223 return data
224
225 def __len__(self):
226 return len(self.names)

Callers

nothing calls this directly

Calls 2

read_imageFunction · 0.85
resize_imageFunction · 0.85

Tested by

no test coverage detected