Crop half of an image in OpenCV

shjnlee

How can I crop an image and only keep the bottom half of it?

I tried:

Mat cropped frame = frame(Rect(frame.cols/2, 0, frame.cols, frame.rows/2));

but it gives me an error.

I also tried:

double min, max;
Point min_loc, max_loc;
minMaxLoc(frame, &min, &max, &min_loc, &max_loc);
int x = min_loc.x + (max_loc.x - min_loc.x) / 2;
Mat croppedframe = = frame(Rect(x, min_loc.y, frame.size().width, frame.size().height / 2));

but it doesn't work as well.

Olivier

The Rect function arguments are Rect(x, y, width, height). In OpenCV, the data are organized with the first pixel being in the upper left corner, so your rect should be:

Mat croppedFrame = frame(Rect(0, frame.rows/2, frame.cols, frame.rows/2));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to crop each character on an image using Python OpenCV?

How to crop a region of small pixels in an image using OpenCv in Python

how to crop the detected face image in opencv java

How to crop an image in OpenCV using Python

opencv crop a portion of image within contour

Opencv Python Crop Image Using Numpy Array

Crop image with corrected distortion in OpenCV (Python)

opencv: crop image on the GPU side

How to crop the biggest object in image with python opencv?

Use Python OpenCV to Crop/Rotate/Resize Playing Cards From an Image

How do I crop the black background of the image using OpenCV in Python?

How to crop an image from screenshot with the use of OpenCV?

OpenCV crop image and display the original with crop removed

Python OpenCV: Crop image to contents, and make background transparent

Crop image into pieces and then join, is that possible using OpenCV?

Opencv c++ detect and crop white region on image

Clear (not crop) the non-ROI part of image in OpenCV

Crop image's area with openCV (java)

Opencv C++ Crop Image based on changing corners

How to crop image based on contents (Python & OpenCV)?

How to crop the image from bottom using opencv python

Crop image from four corner points using Opencv and Python

How to crop in half a card image in bootstrap/css?

How to crop OpenCV Image from center

OpenCV Python: retrieve rectangle main area from image then crop image

opencv-python: how to crop image with bounding box coordinates

What is the easy way to crop a part of image using Python OpenCV

How to crop image based on the object radius using OpenCV?

Crop image opencv python