What is the most elegant and efficient way to convert a nested std::vector of std::vectors to cv::Mat? The nested structure is holding an array, i.e. all the inner std::vectors have the same size and represent matrix rows. I don’t mind the data being copied from one to another.
I know that a single, non-nested std::vector is very easy, there is a constructor:
std::vector <double> myvec;
cv::Mat mymat;
// fill myvec
bool copy = true;
myMat = cv::Mat(myvec, copy);
What about the nested vector?
This is a way to do it:
Outputs:
I tried another approach using the constructor of
Matand thepush_back()method but without success, maybe you can figure it out. Good luck!