我收到错误:
“类型错误:字符串索引必须是整数”
当我尝试裁剪图像时
我正在尝试编写一个裁剪矩形图像的函数,以便制作方形图像并居中。
def squared_and_resized(img,resized_dim):
image = cv2.imread(img)
img_height,img_width = image.shape[:2]
if (img_width > img_height):
start_row = 0
end_row = img_height
start_col = math.floor((img_width - img_height) /2)
end_col = math.floor((img_width + img_height) /2)
else:
start_col = 0
end_col = img_width
start_row = math.floor((img_height-img_width)/2)
end_row = start_row + img_width
squared_img = img[start_row:end_row , start_col:end_col]
resized_img = cv2.resize(squared_img,(resized_dim, resized_dim))
return resized_img
MMTTMM
犯罪嫌疑人X
相关分类