import cv2
# 读取图像
image = cv2.imread('path_to_image.jpg')
# 检查图像是否成功加载
if image is None:
print("Error: Could not read image.")
else:
# 打印原始图像的尺寸
print("Original Dimensions : ", image.shape)
# 指定新的宽度和高度
new_width = 300
new_height = 300
new_size = (new_width, new_height)
# 使用cv2.resize函数调整图像大小
resized_image = cv2.resize(image, new_size, interpolation=cv2.INTER_AREA)
# 打印调整后的图像尺寸
print("Resized Dimensions : ", resized_image.shape)
# 显示原始图像和调整后的图像
cv2.imshow("Original Image", image)
cv2.imshow("Resized Image", resized_image)
# 等待按键事件,然后关闭所有窗口
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2 库来处理图像。cv2.imread() 函数读取图像文件。new_size。cv2.resize() 函数调整图像大小。interpolation=cv2.INTER_AREA 参数指定了插值方法,适用于缩小图像。cv2.imshow() 函数显示原始图像和调整后的图像。cv2.waitKey(0) 等待用户按键,然后使用 cv2.destroyAllWindows() 关闭所有窗口。如果你需要调整不同的插值方法或参数,可以根据具体需求进行修改。
上一篇:python中int是什么意思
下一篇:python 自定义函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站