How to crop an image in OpenCV using Python

The Solution to How to crop an image in OpenCV using Python is


It's very simple. Use numpy slicing.

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

~ Answered on 2013-03-23 17:26:58


Most Viewed Questions: