Skip to main content

Posts

Showing posts with the label Crop an image in Python

OpenCV Crop an image in Python

 Crop operation in OpenCV is very simple. You should first read the image. Then the values x, y, h, w must be determined to specify the region to be cropped. You can do this using the code below. import cv2 image = cv2.imread( 'image.jpg' ) y= 10 x= 20 h= 200 w= 250 crop = image[y:y+h , x:x+w] cv2.imshow( 'Image' , crop) cv2.waitKey( 0 )