Roi to small? [closed]

asked 2018-10-13 11:50:59 -0600

robro gravatar image

Hi,

I am using ROIs to crop my images and I just noticed that the ROIs are always one pixel to small.

Actually I am not sure whether I misunderstood how I select a roi or whether there is something wrong.

For example if I select a Roi from a Mat with 100 rows and the roi shall have the same height I do it with these points: Point(x1,0), Point(x2,Mat.rows-1). I thought from 0 to 99 is 100 and would select the full Mat height, but this is not the case.

See this example:

#include <opencv2/opencv.hpp>
#include <iostream>
cv::Mat test = cv::Mat::zeros(cv::Size(1000, 100), CV_64FC1);
cv::Rect ROI(cv::Point2i{0,0},cv::Point2i{319,test.rows-1});

std::cout << "Cols: " << ROI.width << " Rows: " << ROI.height << std::endl; //Returns 99, 319 instead of 100, 320

Why is that? Thank you very much!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2018-10-13 13:57:14.799794

Comments

2

did you miss, that the idea of a "Range" here excludes the upper value ? it's

lo <= x < hi

(for any dimension) ??

berak gravatar imageberak ( 2018-10-13 11:59:52 -0600 )edit
1

:D Yes, i missed that! Thank you very much, problem solved ;-)

robro gravatar imagerobro ( 2018-10-13 12:08:53 -0600 )edit