Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a row to a matrix in OpenCV

Tags:

opencv

matrix

row

This is a very simple question but I couldn't find the answer in Google or in OpenCV documentation. How do you insert a row with either a vector or a default number at the bottom of a cv::Mat? I tried:

std::vector<double> v = {0, 0, 1};
m.push_back(v);

which compiles, but it always gets me an assertion error. What is the right way to do it?

like image 463
Neptilo Avatar asked Aug 13 '13 15:08

Neptilo


1 Answers

The added element must be a Mat with the same number of columns as the container matrix:

cv::Mat m = cv::Mat::ones(4, 3, CV_64F);    // 3 cols, 4 rows
cv::Mat row = cv::Mat::ones(1, 3, CV_64F);  // 3 cols, 1 row
m.push_back(row);                           // 3 cols, 5 rows
like image 63
ChronoTrigger Avatar answered Oct 18 '22 19:10

ChronoTrigger