python opencv resize
import cv2 # 读取图像 image = cv2.imread('input.jpg') # 获取原始图像的宽度和高度 height, width = image.shape[:2] # 定义新的大小 new_width = 640 # 新宽度 new_height = int(new_width * height / width) # 根据比例计算新高度,以保持纵横比 # 使用resize函数调整图像大小 resized_image = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LINEAR) # 显示原始图像和调整大小后的图像 cv2.imshow('Original Image', image) cv2.imshow('Resized Image', resized_image) # 等待按键并关闭窗口 cv2.waitKey(0) cv2.destroyAllWindows() # 如果需要,保存调整大小后的图像 # cv2.imwrite('resized_image.jpg', resized_image)
####################
QQ 3087438119