在OpenCV中向矩阵添加一行 [英] Add a row to a matrix in OpenCV
本文介绍了在OpenCV中向矩阵添加一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个非常简单的问题,但是我无法在Google或OpenCV文档中找到答案.如何在cv::Mat
的底部插入带有向量或默认数字的行?我试过了:
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?
推荐答案
添加的元素必须是与容器矩阵具有相同列数的Mat
:
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
这篇关于在OpenCV中向矩阵添加一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文