How to Crop OpenCV Image using Mouse Click and Movement in Python

Click and Crop Image

You can easily crop an image using mouse clicks on OpenCV. For this you need call the OpenCV cv2.setMouseCallback(“window”, image). You then need to detect the left mouse button down using the cv2.EVENT_LBUTTONDOWN event, then continuously locate the position of the mouse using the cv2.EVENT_MOUSEMOVE event and at last you need to detect the left mouse button released or cv2.EVENT_LBUTTONUP event.

By doing this it will create an rectangle to the image and also give the output ROI of the cropped image