(annotation_root, extract_num_from_imgid=True)
| 36 | |
| 37 | |
| 38 | def get_image_info(annotation_root, extract_num_from_imgid=True): |
| 39 | path = annotation_root.findtext('path') |
| 40 | if path is None: |
| 41 | filename = annotation_root.findtext('filename') |
| 42 | else: |
| 43 | filename = os.path.basename(path) |
| 44 | img_name = os.path.basename(filename) |
| 45 | img_id = os.path.splitext(img_name)[0] |
| 46 | if extract_num_from_imgid and isinstance(img_id, str): |
| 47 | img_id = int(re.findall(r'\d+', img_id)[0]) |
| 48 | |
| 49 | size = annotation_root.find('size') |
| 50 | width = int(size.findtext('width')) |
| 51 | height = int(size.findtext('height')) |
| 52 | |
| 53 | image_info = { |
| 54 | 'file_name': filename, |
| 55 | 'height': height, |
| 56 | 'width': width, |
| 57 | 'id': img_id |
| 58 | } |
| 59 | return image_info |
| 60 | |
| 61 | |
| 62 | def get_coco_annotation_from_obj(obj, label2id): |
no outgoing calls
no test coverage detected