Crop Image Using OpenCV in Python
Manav Narula
Nov 25, 2021

The opencv
module provides different tools and functionalities for Computer Vision. We have different functions available to read and process images.
This tutorial will demonstrate how to crop an image using the opencv
module in Python.
Images are stored as NumPy
arrays. To crop images, we can use NumPy
slicing to slice the arrays.
For example,
import cv2
img = cv2.imread("sample.png")
cropped = img[y:y+h, x:x+w]
cv2.imshow("cropped", cropped)
In the above example, the imread()
function reads the image. We crop the image using NumPy
slicing. Finally, we display the cropped image using the imshow()
function.
Author: Manav Narula
Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
LinkedInRelated Article - Python OpenCV
- No Module Named CV2 in Mac in Python
- Image Masking in OpenCV
- Utilize Bitwise_AND on an Image Using OpenCV
- OpenCV Package Configuration
- OpenCV ArUco Markers
- SIFT Using OpenCV in Python