opencv中mat的push_back。

本文探讨了在OpenCV中使用Mat::push_back方法向矩阵底部添加元素的问题。尽管该方法类似于STL vector的push_back,但在尝试直接使用vector向Mat添加一行时,可能会遇到运行时的sigsegv错误。作者建议通过先创建一个单行Mat并使用at()函数赋值,然后使用push_back将其添加到目标矩阵中,以避免此类错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mat::push_back

Adds elements to the bottom of the matrix.

C++: template<typename T> void Mat::push_back(const T& elem)

C++: void Mat::push_back(const Mat& m)
Parameters:
  • elem – Added element(s).
  • m – Added line(s).

The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of the STL vector class. When elem is Mat , its type and the number of columns must be the same as in the container matrix.

在为mat增加一行的时候,用到push_back。首先用vector存要加的数据,用push_back加入,编译没有问题,运行时抛出sigsegv错误。

我理解按照上述push_back的定义,他是可以接受vector的参数,并且由于编译没有问题,也更加使我相信这一点。可惜!

最后使用方法:先创建一个Mat(1, 16, CV_64F), 利用at()函数为其赋值。最后使用push_back加入。

 Mat temp(1, 16, CV_64F);;
 for (int j = 0; j < 10; j++)
 {
     temp.at<double>(0, j-1) = j;
 }
 origin.push_back(temp);



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值