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)
More Related Contents:
- Video Streaming from IP Camera in Python Using OpenCV cv2.VideoCapture
- How to remove convexity defects in a Sudoku square?
- Detect text region in image using Opencv
- imread returns None, violating assertion !_src.empty() in function ‘cvtColor’ error
- How do I install Python OpenCV through Conda?
- ImportError: numpy.core.multiarray failed to import
- OpenCV VideoCapture and error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’
- OpenCV real time streaming video capture is slow. How to drop frames or get synced with real time?
- OpenCV Python rotate image by X degrees around specific point
- OpenCV – Apply mask to a color image
- Error “ImportError: DLL load failed: %1 is not a valid Win32 application”
- too many values to unpack calling cv2.findContours
- Access IP Camera in Python OpenCV
- NumPy/OpenCV 2: how do I crop non-rectangular region?
- How to fast change image brightness with python + OpenCV?
- How to parse mjpeg http stream from ip camera?
- OpenCV 3.0 LineIterator
- Screen Capture with OpenCV and Python-2.7
- Convert Python Opencv Image (numpy array) to PyQt QPixmap image
- Opencv – Grayscale mode Vs gray color conversion
- Python: how to capture image from webcam on click using OpenCV
- How do I use OpenCV’s remap function?
- Pipe raw OpenCV images to FFmpeg
- How to read raw png from an array in python opencv?
- AttributeError: partially initialized module ‘cv2’ has no attribute ‘gapi_wip_gst_GStreamerPipeline’ (most likely due to a circular import)
- Write OpenCV image in memory to BytesIO or Tempfile
- OpenCV Python not opening images with imread()
- Determine if an image exists within a larger image, and if so, find it, using Python
- Find a 3×3 sliding window over an image
- cv2.imread: checking if image is being read