Пример #1
0
    visibility_threshold_dict={'bolt-roi': 0.01},
    allow_unfound_seg=False,
    class_merge_map={
        'seg_mark-middle_0': 'seg_mark-inner_0',
        #'seg_mark_2': 'seg_mark_0'
    }
)
# mark_dataset.save_to_path('uncropped_mark.json', overwrite=True)
mark_dataset.display_preview(show_details=True, window_name='Mark')

# Mark (Cropped) Dataset Creation
logger.info('Creating Mark Dataset (Cropped Version)')
marker_dst_dir = f'{target_dst_dir}/marker'
make_dir_if_not_exists(marker_dst_dir)

cropped_mark_dataset = COCO_Dataset.new()
cropped_mark_dataset.categories = mark_categories.copy()
cropped_mark_dataset.licenses = mark_dataset.licenses.copy()

crop_pbar = tqdm(total=len(bolt_roi_dataset.images), unit='image(s)')
crop_pbar.set_description('Cropping')
for roi_image in bolt_roi_dataset.images:
    orig_img = cv2.imread(roi_image.coco_url)
    roi_anns = bolt_roi_dataset.annotations.get_annotations_from_imgIds([roi_image.id])
    mark_images = mark_dataset.images.get_images_from_file_name(roi_image.file_name)
    assert len(mark_images) == 1
    mark_image = mark_images[0]
    mark_anns = mark_dataset.annotations.get_annotations_from_imgIds(mark_image.id)
    #assert len(roi_anns) == len(mark_anns)

    for i, roi_ann in enumerate(roi_anns):
from annotation_utils.coco.structs import COCO_Dataset, \
    COCO_License, COCO_Image, COCO_Annotation, COCO_Category
from common_utils.common_types.bbox import BBox
from logger import logger

dataset = COCO_Dataset.new(description='Test')
dataset.categories.append(
    COCO_Category(id=len(dataset.categories),
                  supercategory='test_category',
                  name='category_a'))
dataset.categories.append(
    COCO_Category(id=len(dataset.categories),
                  supercategory='test_category',
                  name='category_b'))
dataset.categories.append(
    COCO_Category(id=len(dataset.categories),
                  supercategory='test_category',
                  name='category_c'))

for i in range(10):
    dataset.licenses.append(
        COCO_License(url=f'test_license_{i}',
                     name=f'Test License {i}',
                     id=len(dataset.licenses)))
for i in range(20):
    dataset.images.append(
        COCO_Image(license_id=i % len(dataset.licenses),
                   file_name=f'{i}.jpg',
                   coco_url=f'/path/to/{i}.jpg',
                   height=500,
                   width=500,