How to crop a cv2 image in Python

Cropping a cv2 image reduces the dimensions of a a NumPy array representing pixels. For example, cropping a one-dimensional array returns a new array containing the elements located at indices l to r inclusive.

Solution for How to crop a cv2 image in Python : You can use Numpy array slicing to crop a cv2 image Use the Numpy array slicing syntax [y1:(y2 + 1), x1:(x2 + 1)] with the pair (x1, y1) specifying the coordinates of the top left corner and (x2, y2) specifying the coordinates of the bottom right corner of the pixel array, to return a cropped pixel array.


how-to-crop-a-cv2-image-in-python