Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Created August 21, 2022 17:20
Show Gist options
  • Save Merwanski/228bc26c10975c3b3dc811c79aae5d26 to your computer and use it in GitHub Desktop.
Save Merwanski/228bc26c10975c3b3dc811c79aae5d26 to your computer and use it in GitHub Desktop.
read and display image in python
# import necessary packages
import numpy as np
import cv2
# path to image
path_to_image = "data/cv_image_000.jpg"
# read the image with cv2
image = cv2.imread(path_to_image)
print('Original Dimensions : ', image.shape)
scale_percent = 60 # percent of original size
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
# resize the image
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
print('Resized Dimensions : ', resized.shape)
# show the image
cv2.imshow("Original image", image)
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment