目录
裁剪为64的倍数
import cv2
def crop_and_resize_image(image_path):
"""
先裁剪后缩放图像,使缩放后的图像尺寸是64的倍数
Args:
image_path (str): 图像文件的路径
Returns:
resized_image (numpy.ndarray): 处理后的图像
"""
image = cv2.imread(image_path)
height, width = image.shape[:2]
# 计算裁剪后的高度和宽度,使得它们是64的倍数
new_height = (height // 64) * 64
new_width = (width // 64) * 64
# 计算裁剪的起始位置(从中心开始裁剪,保持图像中心部分)
start_y = (height - new_height) // 2
start_x = (width - new_width) // 2
# 裁剪图像
cropped_image = image[start_y:start_y + new_height, sta