Image Cropping in OpenCV with Python
To crop images in OpenCV, unlike with PIL, you can use NumPy slicing. Here's how:
import cv2 img = cv2.imread("image.jpg")
crop_img = img[y:y+h, x:x+w]
cv2.imshow("Cropped Image", crop_img) cv2.waitKey(0)
Incorrect Usage of getRectSubPix
In your attempt, getRectSubPix was incorrectly used. This function is meant for drawing rectangles on an image and not cropping it.
The above is the detailed content of How to Crop Images in OpenCV Using NumPy Slicing?. For more information, please follow other related articles on the PHP Chinese website!