zoukankan      html  css  js  c++  java
  • 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!")
    '''
    

      

  • 相关阅读:
    Linux基础命令mv
    Linux基础命令cp
    闭包函数
    函数的嵌套
    函数对象
    global与nonlocal
    名称空间与作用域
    函数的参数(总结)
    函数的基本使用
    文件的操作之指针移动
  • 原文地址:https://www.cnblogs.com/morganh/p/14323704.html
Copyright © 2011-2022 走看看