zoukankan      html  css  js  c++  java
  • python opencv图片缩放

    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插值

     

  • 相关阅读:
    如何复用网页
    sap
    学习方法
    spring + ehcache 实例
    200个 jquery插件
    vs 示例代码浏览器 搜索
    struts jquery 整合
    eclipse clean 后clease 为空
    mvc相关
    css 框架
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/14568855.html
Copyright © 2011-2022 走看看