Image Cropping
Cropping is the removal of unwanted outer areas from an image.
cropped_img = img[100:300, 100:300]
OpenCV loads the image as a NumPy array, we can crop the image simply by indexing the array, in our case, we choose to get 200 pixels from 100 to 300 on both axes.
Python3
import numpy as np import cv2 as cv img = cv.imread( 'girlImage.jpg' , 0 ) cropped_img = img[ 100 : 300 , 100 : 300 ] cv.imwrite( 'cropped_out.jpg' , cropped_img) cv.waitKey( 0 ) cv.destroyAllWindows() |
Output:
Image Transformations using OpenCV in Python
In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python.
Contact Us