Skip to content

Instantly share code, notes, and snippets.

@yokeshrana
Created March 8, 2021 09:17
Show Gist options
  • Save yokeshrana/b2a7fea55a8b16371a988b7c224ae98c to your computer and use it in GitHub Desktop.
Save yokeshrana/b2a7fea55a8b16371a988b7c224ae98c to your computer and use it in GitHub Desktop.
Resizing the images Cropping the images
import cv2
import numpy as np
img = cv2.imread("Resources/lambo.PNG")
cv2.imshow("Image ", img)
print(img.shape)
'''
Resizing the image
'''
imgResizeinc = cv2.resize(img,(600,600))
print(imgResizeinc.shape)
cv2.imshow("Resize Image Inc",imgResizeinc)
imgResizedec = cv2.resize(img,(300,300))
print(imgResizedec.shape)
cv2.imshow("Resize Image Dec",imgResizedec)
'''
Cropping the image :
Since image is a matrix we can use the normal matrix operations to crop the image
'''
imgCrop = img[0:200,200:500] # start_height: end_height , start_width: end_width
cv2.imshow("Cropped Image",imgCrop)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment