1)配置文件生成java代码:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class test {
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
String file="F:/train.txt";
String charSet="UTF-8";
//写字符转换成字节流
FileOutputStream fileWriter=new FileOutputStream(file);
OutputStreamWriter ow=new OutputStreamWriter(fileWriter, charSet);
long i = 1;
try {
while(i<=100000)
{
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-1", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-2", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-3", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-4", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-5", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-6", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-7", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-8", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-9", i)+".jpg \n");
ow.write("./data/training_data_example/gt_label/"+String.format("%06d", i)+".jpg ");
ow.write("./data/training_data_example/data/"+String.format("%06d-10", i)+".jpg \n");
i++;
}
}
catch (Exception e) {
// TODO: handle exception
}finally{
ow.close();
}
}
}
2)残缺图像生成
import cv2
import os
import random
import numpyas np
root_path= "./"
dir= root_path+"img_align_celeba"+"/"
for root, dir, filesin os.walk(dir):
for filein files:
img= cv2.imread(root_path+ "img_align_celeba" + "/" + str(file))
count= 1
while count< 11:
#centralpoint = (109,89)
x1= 109 + random.randint(-35, 35)
y1= 89 + random.randint(-40, 40)
x2= 50 + x1
y2= 50 + y1
print("%d,%d,%d,%d" % (x1, x2, y1, y2))
mask= np.zeros([218,178], dtype=np.uint8)
mask[x1:x2, y1:y2]= 255
mask= -(mask- 255)
image= cv2.add(img, np.zeros(np.shape(img), dtype=np.uint8), mask=mask)
image[x1:x2, y1:y2]= 255
#(filepath, tempfilename) = os.path.split(str(file))
(filename, extension)= os.path.splitext(str(file))
cv2.imwrite(root_path+ "test/" + filename+"-%d"%(count)+extension, image)
count+= 1
网友评论