代码之家  ›  专栏  ›  技术社区  ›  user70

opencv python使用一个常量调整大小

  •  1
  • user70  · 技术社区  · 8 年前

    我想使用给定的一条边的新长度调整图像的大小 cv2.resize() 方法。

    例如,我的图像的尺寸为300x400,我想将高度从400增加到500,但我应该只写一个边缘的新尺寸(只有500),另一个边缘应该自动增加。什么是序列?

    2 回复  |  直到 8 年前
        1
  •  1
  •   Benehiko    8 年前

    我知道你只要求cv2.resize,但是你可以使用 imutils 为您做一些比率代码的库。

    import imutils
    resized = imutils.resize(img, width=newwidth)
    

    在imutils内部:

    dim = None
    (h, w) = image.shape[:2]
    
    # check to see if the width is None
    if width is None:
        # calculate the ratio of the height and construct the
        # dimensions
        r = height / float(h)
        dim = (int(w * r), height)
    
    # otherwise, the height is None
    else:
        # calculate the ratio of the width and construct the
        # dimensions
        r = width / float(w)
        dim = (width, int(h * r))
    
    # resize the image
    resized = cv2.resize(image, dim, interpolation=inter)
    
        2
  •  0
  •   Sunreef    8 年前

    您可以使用 fx fy 的参数 resize 功能。

    img = cv2.resize(img, (0,0), fx=500/400, fy=500/400)