MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / __getitem__

Method __getitem__

anyword_data.py:111–135  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

109 return self._length
110
111 def __getitem__(self, index):
112 gt = self.raw_data[index]
113 img_path = gt['img_name']
114 full_image = np.array(Image.open(img_path).convert('RGB'))
115 height, width = full_image.shape[:2]
116 im_shape = (width, height)
117 polygon = gt['polygon']
118 location = calculate_square(full_image, polygon)
119 crop_image = full_image[location[1]:location[3], location[0]:location[2]]
120 trans_image = self.transform(crop_image)
121 mask, masked_image, mask_rect = generate_mask(trans_image, im_shape, self.resolution, polygon, location)
122 text = gt['text']
123 draw_ttf = self.draw_text(text[:self.max_len])
124 glyph = self.draw_glyph(text, mask_rect)
125 info = {
126 # "full_image": torch.tensor(full_image),
127 # "location": torch.tensor(location),
128 "image": trans_image,
129 'mask': mask,
130 'masked_image': masked_image,
131 'ttf_img': draw_ttf,
132 'glyph': glyph,
133 "text": text
134 }
135 return info
136
137 def load_data(self, json_path):
138 content = load_json(json_path)

Callers

nothing calls this directly

Calls 5

draw_textMethod · 0.95
draw_glyphMethod · 0.95
calculate_squareFunction · 0.70
generate_maskFunction · 0.70
transformMethod · 0.45

Tested by

no test coverage detected