How can access vector <cv::Mat> data by using ptr or data method?

asked 2018-04-12 03:11:15 -0500

updated 2018-04-12 03:15:41 -0500

berak gravatar image

How can access vector <cv::mat> data by using ptr or data method?

I used at method for access vector <cv::mat> data.

This Method is so slow, so I would like to change ptr or data method.

This is my code. How can I change?

vector<Mat> conc_img;

vector<Mat> loss_img(conc_img);

for (int iter = r_start; iter < r_start + h_size; iter++) {

                for (int nframe = 0; nframe < conc_img.size(); nframe++) {

                    part_x[nframe][cnt][0] = loss_img[nframe].at<float>(iter, ref_p[0]);

                    part_x[nframe][cnt][1] = loss_img[nframe].at<float>(iter, ref_p[1]);

                    part_x[nframe][cnt][2] = loss_img[nframe].at<float>(iter, ref_p[2]);

                    part_x[nframe][cnt][3] = loss_img[nframe].at<float>(iter, ref_p[3]);


edit retag flag offensive close merge delete


there is alot of context missing. what are you trying to achieve here ?

berak gravatar imageberak ( 2018-04-12 03:37:05 -0500 )edit

Hi, thank you for your attetnion from my problem.

I used part_x[nframe][cnt][0] = loss_img[nframe].at<float>(iter, ref_p[0]); I know about <at> for accessing Mat. However, I did not know using about ptr or Data for accessing Mat.

How can I use ptr or Data for accessing Mat? Can you change the sentence?

David Lee gravatar imageDavid Lee ( 2018-04-12 04:56:36 -0500 )edit

as long as you're traversing rows, you don't have consecutive memory.

but why are you doing it that way ? we can't help without further information/context

berak gravatar imageberak ( 2018-04-12 04:58:31 -0500 )edit