Ricardo
Ricardo

Reputation: 310

Fill a std::vector with cv:Mat's

I've created a struct:

struct clusters_t { 
cv::Mat ids; 
cv::Mat means; 
vector<cv::mat> covs; 
cv::Mat weights; 
} clusters;

And I have a problem filling the "covs". I reserve memory like I show below but... how can I copy a Mat inside the vector of mats??

clusters.covs.clear(); 
clusters.covs.reserve(0);

cv::Mat matrix;

newCovs.copyTo(clusters.covs.at(0)); //<-- DOESN'T WORK... HOW CAN I COPY matrix inside the vector?

Upvotes: 0

Views: 892

Answers (1)

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39380

Use resize instead of reserve (and be sure to create at least one element).

Alternatively,

newCovs.copyTo(std::back_inserter(clusters.covs));

will work too.

Nope, because it can't work on iterators.

Upvotes: 1

Related Questions