def _parse_annotations(self, stim, annotations):
annotations = annotations[0]
data_dict = {}
for field, val in annotations.items():
if field not in ["boundingPoly", "fdBoundingPoly", "landmarks"]:
data_dict[field] = val
elif "oundingPoly" in field:
for i, vertex in enumerate(val["vertices"]):
for dim in ["x", "y"]:
name = "%s_vertex%d_%s" % (field, i+1, dim)
val = vertex[dim] if dim in vertex else np.nan
data_dict[name] = val
elif field == "landmarks":
for lm in val:
name = "landmark_" + lm["type"] + "_%s"
lm_pos = { name % k : v for (k, v) in lm["position"].items()}
data_dict.update(lm_pos)
return Value(stim=stim, extractor=self, data=data_dict)
class GoogleVisionAPITextExtractor(GoogleVisionAPIExtractor):