How to crop an image in OpenCV using Python

It is very easy to crop image in open CV

import cv2
img = cv2.imread("crop.png")
crop_img = img[y:y+h, x:x+w]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)

We need to import open CV library. Then read image using imread function.
Pass cropping coordinates x,y,w,h . Print image using imshow function.

Leave a Comment

Your email address will not be published. Required fields are marked *