Exemplo n.º 1
0
def _copy_to_JPEGImages(parent_dir, src_dir):
    target_dir = os.path.join(parent_dir, 'JPEGImages/')
    io_utils.mkdir(target_dir)
    io_utils.remove_all(target_dir)
    for s in os.listdir(src_dir):
        file = os.path.join(src_dir, s)
        io_utils.copy(file, target_dir)
Exemplo n.º 2
0
def copyfile(src_dir, com_dir, des_dir):
    #find those files in src_dir but not in com_dir,and copy them to des_dir
    for f in os.listdir(src_dir):
        name = f.split("\\", 4)[-1]
        pic = os.path.join(com_dir, name)
        if os.path.exists(pic):
            pass
        else:
            io_utils.copy(os.path.join(src_dir, name), des_dir)
Exemplo n.º 3
0
def get_xml_by_imagename():
    id = 50000
    for image_file in os.listdir(JPEGImages_dir):
        image_name = os.path.splitext(image_file)[0]
        for annot_xml in os.listdir(annotations_dir):
            xml_name = os.path.splitext(annot_xml)[0]
            if image_name == xml_name:

                new_id = '{}{}'.format('fusion_2018-07-11_', id)
                xml = os.path.join(annotations_new_dir, new_id + '.xml')
                image = os.path.join(JPEGImages_new_dir, new_id + '.jpg')
                io_utils.copy(os.path.join(annotations_dir, annot_xml), xml)
                io_utils.copy(os.path.join(JPEGImages_dir, image_file), image)
                id += 1
                break
Exemplo n.º 4
0
def _rename_image(parent_dir, image_dir_name, str_date):
    # image_dir_name = 'JPEGImages'
    data_dir = os.path.join(parent_dir, image_dir_name)
    data_rename_dir = os.path.join(parent_dir,
                                   '{}_rename'.format(image_dir_name))

    io_utils.delete_file_folder(data_rename_dir)
    io_utils.mkdir(data_rename_dir)
    prefix = 'train'
    idx = 1000
    cur_date = datetime.datetime.now()
    # str_date = '{year}{month}{day}'.format(year=cur_date.year, month=cur_date.month, day=cur_date.day)
    for s in os.listdir(data_dir):
        old = os.path.join(data_dir, s)
        new = os.path.join(data_rename_dir,
                           '{}_{}_{}.jpg'.format(prefix, str_date, idx))
        io_utils.copy(old, new)
        idx = idx + 1

    return data_rename_dir
Exemplo n.º 5
0
def copy_marked(data_path):

    if not os.path.isdir(data_path):
        print('input_path is not a dir: {}'.format(data_path))
        return

    # for data_path in input_path:
    annot_path = os.path.join(data_path, 'Annotations')
    imgs_path = os.path.join(data_path, 'JPEGImages')
    imgs_out_path = os.path.join(data_path, 'JPEGImages_marked')
    io_utils.mkdir(imgs_out_path)

    annots = [os.path.join(annot_path, s) for s in os.listdir(annot_path)]
    for annot in annots:
        try:
            et = ET.parse(annot)
            element = et.getroot()
            element_filename = element.find('filename').text
            filepath = os.path.join(imgs_path, element_filename)
            io_utils.copy(filepath, imgs_out_path)
        except Exception as e:
            print('Exception in pascal_voc_parser: {}'.format(e))
            continue
Exemplo n.º 6
0
def many2one(parent_dir):
    for s in os.listdir(parent_dir):
        childdir=os.path.join(parent_dir,s)
        for t in os.listdir(childdir):
            file=os.path.join(childdir,t)
            io_utils.copy(file,parent_dir)
Exemplo n.º 7
0
def _copy_download():
    if C.remote_zip_file and C.local_dir:
        io_utils.copy(C.remote_zip_file, C.local_dir)
    else:
        print('copy error')