(image_dir,txt_dir,image_save_dir, xml_save_dir)
:param image_dir: 图片根目录
    :param txt_dir: text文件根目录
    :return:
:param image_dir: 图片根目录
    :param txt_dir: text文件根目录
    :return:
: param image_dir : 图片根目录 : param txt_dir : text文件根目录 : return :
def generateImageAndXml(image_dir,txt_dir,image_save_dir, xml_save_dir):
    """
    :param image_dir: 图片根目录
    :param txt_dir: text文件根目录
    :return:
    """
    files = getFiles(txt_dir)  # 所有txt
    files = [file for file in files if file.endswith('ellipseList.txt')]  # 过滤出annotation文件
    for file in files:
        print(file)
        txt_path = os.path.join(txt_dir,file)
        with open(txt_path, 'r') as f:
            line = 'init'
            while True:
                line = f.readline()
                if line == '':
                    break
                image_dir_tmp = line.strip()
                # print(">>>{} is being processed...".format(image_dir_tmp))
                new_name = '_'.join(image_dir_tmp.split('/'))
                image_path = os.path.join(image_dir, image_dir_tmp+'.jpg')
                img_shape = cv2.imread(image_path).shape
                h = img_shape[0]
                w = img_shape[1]
                d = img_shape[2]
                shutil.copyfile(image_path,os.path.join(image_save_dir,new_name+ '.jpg'))
                line = f.readline().strip()
                num = int(line)
                box_list = []
                for i in range(num):
                    line = f.readline().strip()
                    data = [float(val) for val in line.split(' ') if val != '']
                    coord = convert_coord(data)
                    box_list.append(coord)
                WriterXMLFiles(new_name+'.xml',xml_save_dir,box_list,w,h,d)
def generateImageAndXml ( image_dir , txt_dir , image_save_dir , xml_save_dir ) : files = getFiles ( txt_dir ) # 所有txt files = [ file for file in files if file . endswith ( 'ellipseList.txt' ) ] # 过滤出annotation文件 for file in files : print ( file ) txt_path = os . path . join ( txt_dir , file ) with open ( txt_path , 'r' ) as f : line = 'init' while True : line = f . readline ( ) if line == '' : break image_dir_tmp = line . strip ( ) # print(">>>{} is being processed...".format(image_dir_tmp)) new_name = '_' . join ( image_dir_tmp . split ( '/' ) ) image_path = os . path . join ( image_dir , image_dir_tmp + '.jpg' ) img_shape = cv2 . imread ( image_path ) . shape h = img_shape [ 0 ] w = img_shape [ 1 ] d = img_shape [ 2 ] shutil . copyfile ( image_path , os . path . join ( image_save_dir , new_name + '.jpg' ) ) line = f . readline ( ) . strip ( ) num = int ( line ) box_list = [ ] for i in range ( num ) : line = f . readline ( ) . strip ( ) data = [ float ( val ) for val in line . split ( ' ' ) if val != '' ] coord = convert_coord ( data ) box_list . append ( coord ) WriterXMLFiles ( new_name + '.xml' , xml_save_dir , box_list , w , h , d )