pad image to 512x512

for line in fp:
     filename = (str(int_counter)+".jpeg")
     line_array = line.split(" ")
     img = Image.open(os.path.join(root_dir, line_array[2], line_array[3]))
     int_x_dims = int(line_array[1])
     int_y_dims = int(line_array[0])
     x_pad_val_added = 512-int_x_dims
     y_pad_val_added = 512-int_y_dims
     bimg = ImageOps.expand(img, border=(0,0,x_pad_val_added,y_pad_val_added))
     bimg.save(os.path.join(img_write_dir, filename))
     int_counter += 1
     print("Image padded succesfully!")

'''
#write annotations for padded images - check if float or not on dims
for line in fp:
    filename = (str(int_counter)+".txt")
    line_array = line.split(" ")
    line_to_write_array = ["bird", 0.00, 0, 0.00, line_array[5], line_array[6], 
    float(line_array[5])+float(line_array[7]), float(line_array[6])+float(line_array[8]), 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00]
    file_to_write = open(os.path.join(label_write_dir, filename), "w")
    print((" ".join(str(x) for x in line_to_write_array)))
    file_to_write.write((" ".join(str(x) for x in line_to_write_array)))
    int_counter += 1
    print("Image label generated succesfully!")
'''

  

posted on 2021-01-25 09:53  cdekelon  阅读(58)  评论(0编辑  收藏  举报

导航