Quyền Anh
Quyền Anh

Reputation: 103

Get part of data from cv::Mat

I have a cv::Mat src (type: CV_32F) with size 11000x1085.

Get a row data

cv::Mat dst = src.row();

If I want to get data from column 4 to 1085, I do this way.

for(int i = 0; i < 11000; i++)
   for(int j = 3; j < 1085; j++)
      dst.at<double>(i,j-3) = src.at<double>(i,j);

Is there another way to do that faster?

Upvotes: 1

Views: 2407

Answers (2)

Klathzazt
Klathzazt

Reputation: 2454

It depends if you want to make a deep copy of the data or not. You may want to construct a region of interest (ROI) as described on this helpful tutorial, which describes other methods to work with the cv::Mat to structure your data:

http://docs.opencv.org/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.html

To create a region of interest (ROI) for a rectangle:

Mat Dst (src, Rect(3, 0, 11000, 1085) );

If you want copy the data:

Mat Clone = Dst.clone();

Upvotes: 2

Bull
Bull

Reputation: 11941

You could use Mat::colRange

cv::Mat dst = src.colRange(3, 1085);

Upvotes: 1

Related Questions