import cv2
import os
import numpy as np
def get_resize_square(input,output):#,output
for filename in os.listdir(input):
image_path=input+'/'+filename
image=cv2.imread(image_path)
print(image)
x=image.shape[1]##宽度
y=image.shape[0]##高度
print(x,y)###
add_array=np.zeros((x-y, x))#宽度787,高度787-648=139
#add_array_image = cv2.cvtColor(add_array, cv2.COLOR_GRAY2BGR)
print('add',add_array)
add_array = np.expand_dims(add_array, axis=2)
image1 = np.concatenate((add_array, add_array, add_array), axis=-1)
image_last = np.vstack((image, image1))
print('image_last',image_last)
print(image_last.shape)
cv2.imwrite(output+'/'+filename,image_last)
if __name__=='__main__':
input_image_dir=r'G:\shuju_quan\suoyou\3000'
output_dir=r'G:\shuju_quan\suoyou\xiugai'
get_resize_square(input_image_dir,output_dir)
将图片补成正方形,不够用黑色补
最新推荐文章于 2023-08-02 14:06:27 发布