Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get the ROI of an image from the center

Hello good evening I started researching about getting the ROI of an image and from what I understand is using function RECT I've tried but I get an error and honestly do not quite understand its parameters mean, if someone can help me roi get the picture attached below.

image description

My code is the next

Mat image;
image = imread(argv[1]);
int alto = 100; 
Rect roi(0,(image.rows)-alto,image.cols,alto);
Mat imgROI = image(roi);
imwrite("ROI.jpg",imgROI);

and the error is the next

Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in binary_op, file /home/jenny/Downloads/opencv-2.4.9/modules/core/src/arithm.cpp, line 1021 terminate called after throwing an instance of 'cv::Exception'