Schnigges
Schnigges

Reputation: 1326

Subregion of image matrix in OpenCV

I have a matrix containing the color frame of an RGB camera with dimensions 1920x1080. From that image, I want to get rid of the right and left hand side, to have dimensions 960x1080.

However, I cannot seem to figure out how to get exactly this part of the image. I am able to extract a subimage with dimension 960x1079 with:

cv::Mat A = B(cv::Range(0, dim_y - 1), cv::Range(dim_x / 4, dim_x - dim_x / 4));

This gives me a valid image. However, when I try to use

cv::Mat A = B(cv::Range::all(), cv::Range(dim_x / 4, dim_x - dim_x / 4));

... the image dimensions are 960x1080, but the data is invalid and doesn't contain any values (checked with VS ImageWatch extension)

What could be the issue here?

Upvotes: 1

Views: 1043

Answers (1)

herohuyongtao
herohuyongtao

Reputation: 50657

Both versions are valid actually.

You can verify it by saving it to your computer. It should be a bug of ImageWatch when the right boundary of cv::Range (for the row range only) is the max value.


Also note that, the right boundary of cv::Range is exclusive. So in order to make the images of two versions identical, you should change the first version to:

cv::Mat A = B(cv::Range(0, dim_y), cv::Range(dim_x / 4, dim_x - dim_x / 4));

Upvotes: 1

Related Questions