如何正确初始化cv :: Mat指针到带有zeros()的0矩阵 [英] How to correctly initialize a cv::Mat pointer to a 0 matrix with zeros()

查看:2152
本文介绍了如何正确初始化cv :: Mat指针到带有zeros()的0矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在函数顶部初始化了以下内容:

I have the following initialized at the top of a function:

cv::Mat *m;

然后,在一个循环中,我正在使用该名称分配新矩阵并将它们存储在列表中.我希望它们初始化为具有特定大小的零矩阵.

Then, within a loop I am allocating new matrices with this name and storing them in a list. I want them to initialize as zero matrices with a specific size.

这是我尝试过的:

m = new cv::Mat::zeros(height, width, CV_32F);

我根据OpenCV文档中提供的示例进行了尝试.执行此操作的正确方法是什么?

I tried this based on the example given in the OpenCV documentation. What is the correct way to perform this operation?

推荐答案

摘录自 Mat :: zeros 它像这样使用

cv::Mat m = cv::Mat::zeros(height, width, CV_32F);

如果要使用在堆上分配的Mat,请使用

If you want to use a Mat allocated on the heap use

cv::Mat * m = new cv::Mat( cv::Mat::zeros(height, width, CV_32F) );

// use m

delete m; // don't forget to delete m

这篇关于如何正确初始化cv :: Mat指针到带有zeros()的0矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆