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/