【问题标题】:How to save an image after resizing it in google colab?在google colab中调整大小后如何保存图像?
【发布时间】:2021-08-15 04:12:59
【问题描述】:
image = cv2.imread("/content/obj_measurement.jpg")

scale_percent = 12.5 # percent of original size
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)

resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)

现在我想下载这个调整大小的图像。我该怎么做?

【问题讨论】:

    标签: python opencv computer-vision google-colaboratory


    【解决方案1】:

    您可以简单地调用cv2.imwrite() 方法:

    import cv2
    
    image = cv2.imread("/content/obj_measurement.jpg")
    scale_percent = 12.5
    width = int(image.shape[1] * scale_percent / 100)
    height = int(image.shape[0] * scale_percent / 100)
    
    dim = (width, height)
    
    resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
    cv2.imwrite("/content/obj_measurement_new.jpg", resized)
    

    我建议解压缩图像的尺寸而不是索引:

    import cv2
    
    image = cv2.imread("/content/obj_measurement.jpg")
    scale_percent = 12.5
    
    h, w, _ = image.shape
    dim = h * scale_percent / 100, w * scale_percent / 100
    
    resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
    cv2.imwrite("/content/obj_measurement_new.jpg", resized)
    

    【讨论】:

      猜你喜欢
      • 2021-02-26
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2010-10-12
      • 1970-01-01
      • 2015-11-14
      • 2017-08-10
      相关资源
      最近更新 更多