简体   繁体   中英

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?

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();

你可以使用Mat :: colRange

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM