Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a row of cv::Mat to std::vector

I have a fairly simple question: how to take one row of cv::Mat and get all the data in std::vector? The cv::Mat contains doubles (it can be any simple datatype for the purpose of the question).

Going through OpenCV documentation is just very confusing, unless I bookmark the page I can not find a documentation page twice by Googling, there's just to much of it and not easy to navigate.

I have found the cv::Mat::at(..) to access the Matrix element, but I remember from C OpenCV that there were at least 3 different ways to access elements, all of them used for different purposes... Can't remember what was used for which :/

So, while copying the Matrix element-by-element will surely work, I am looking for a way that is more efficient and, if possible, a bit more elegant than a for loop for each row.

like image 604
penelope Avatar asked Mar 20 '12 15:03

penelope


1 Answers

It should be as simple as:

m.row(row_idx).copyTo(v);

Where m is cv::Mat having CV_64F depth and v is std::vector<double>

like image 112
Andrey Kamaev Avatar answered Oct 31 '22 00:10

Andrey Kamaev