# -*- coding: utf-8 -*-
import cv2
import pickle
import string
import os
import shutil
from os import listdir, getcwd
from os.path import join
import cv2
#目的路径
path='/Users/ll/Desktop/shumei/PyTorch-YOLOv3-master/data/custom/labels/';
#图片所在路径
pathimg='/Users/ll/Desktop/data/dataset/VOCdevkit/VOC2007/Annotations/';
#txt路径
idtxt='/Users/ll/Desktop/data/dataset/tr.txt'; #部分图片路径
def ReadTxtName(rootdir):
lines = []
with open(rootdir, 'r') as file_to_read:
while True:
line = file_to_read.readline()
if not line:
break
line = line.strip('\n')
lines.append(line)
return lines
a=1;
image_ids = ReadTxtName(idtxt)
for image_id in image_ids:
shutil.copy(image_id, path+str(a)+'.txt') #重新从1开始命名
# im=cv2.imread(image_id)
# pathimg1=str(a)+'.jpg' #%命名为 1.jpg 2.jpg ....
# cv2.imwrite(pathimg1,im);
a=a+1;
end