Add a row to a matrix in OpenCV

时光毁灭记忆、已成空白 提交于 2019-12-18 02:42:22

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/18212597/add-a-row-to-a-matrix-in-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!