简体   繁体   中英

How to save an image after resizing it in google colab?

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)

Now I want to download this resized image. How do I do it?

You can simply call the cv2.imwrite() method:

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)

I would recommend unpacking the dimensions of the image rather than indexing though:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM