python - 如何在谷歌colab中调整图像大小后保存图像?

标签 python opencv computer-vision google-colaboratory

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)

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

最佳答案

您只需调用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)

关于python - 如何在谷歌colab中调整图像大小后保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67713014/

相关文章:

带有 ± 字符的 Python subprocess.check_output

c++ - 静态链接 OpenCV

image - 适用于小图像 (80x80) 的最佳 CNN 架构?

python - expectedFailure 被计为错误而不是已通过

python - 在Python的DEAP中,我怎样才能拥有一个具有多个基因的个体,例如 "Genotype"?

java - 使用 contrib 模块和 Java 包装器构建 OpenCV

android - 使用 FFMpeg 的复制在 Android 上修剪/剪切视频

machine-learning - 默认情况下,TensorFlow 是否使用机器中所有可用的 GPU?

python - 使用 OpenCV 检测手

python - 如何解决 selenium webdriver 中的斜线问题?