Python 通过opencv实现图片缩放

注意:

1.输出尺寸格式为(宽,高)

2.默认的插值方法为:双线性插值

代码演示:

import cv2 as cv
 
# 读入原图片
img = cv.imread('test.jpg')
# 打印出图片尺寸
print(img.shape)
# 将图片高和宽分别赋值给x,y
x, y = img.shape[0:2]
 
# 显示原图
cv.imshow('OriginalPicture', img)
 
# 缩放到原来的二分之一,输出尺寸格式为(宽,高)
img_test1 = cv.resize(img, (int(y / 2), int(x / 2)))
cv.imshow('resize0', img_test1)
cv.waitKey()
 
# 最近邻插值法缩放
# 缩放到原来的四分之一
img_test2 = cv.resize(img, (0, 0), fx=0.25, fy=0.25, interpolation=cv.INTER_NEAREST)
cv.imshow('resize1', img_test2)
cv.waitKey()
cv.destroyAllWindows()

 

interpolation 选项所用的插值方法:

 

INTER_NEAREST

最近邻插值

INTER_LINEAR

双线性插值(默认设置)

INTER_AREA

使用像素区域关系进行重采样。

INTER_CUBIC

4x4像素邻域的双三次插值

INTER_LANCZOS4

8x8像素邻域的Lanczos插值

 

 

 

 python opencv图片缩放

 

相关文章:

  • 2022-12-23
  • 2021-06-08
  • 2022-02-20
  • 2021-05-20
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-12-08
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2022-01-23
相关资源
相似解决方案