如何零元素的3D矩阵与opencv库? [英] How to zero elements of 3D Matrix with opencv Library?
问题描述
我正在努力与opencv的3D矩阵的零元素。
我可以在2D矩阵中的所有元素,如下所示:
I'm struggling with zeroing elements of 3D matrix with opencv. I can zero all elements in 2D matrix like following way:
meta = new Mat(Mat::zeros(cluster,3,CV_32S));
我尝试使用类似的方法在3D矩阵中初始化元素为0,
I try to use the similar way to initialize elements with 0 in 3D matrix, it fails.
block = new Mat(Mat::zeros(3,dim,CV_32F));
错误讯息:
1>MatrixOp.obj : error LNK2019: unresolved external symbol "public: static class cv::MatExpr __cdecl cv::Mat::zeros(int,int const *,int)" (?zeros@Mat@cv@@SA?AVMatExpr@2@HPBHH@Z) referenced in function "public: __thiscall MatrixOp::MatrixOp(char *)" (??0MatrixOp@@QAE@PAD@Z)
我有一个最后一种方式来初始化矩阵。遍历矩阵并设置元素值0.但它似乎劳动一些。
I got one last way to initialize matrix. Traverse the matrix and set element value 0. But it seems labor-some.
for(int i=0;i<value_num;i++)
for(int j=0;j<frame_no;j++)
for(int k=0;k<cluster;k++)
block->at<float>(i,j,k) = 0;
任何人都可以给我一个更好的想法?
谢谢。
Can anyone throw me a better ideas? Thanks.
推荐答案
我提醒您文档,您可以使用此构造函数:
I remind you the documentation, you can use this constructor:
C++: Mat::Mat(int ndims, const int* sizes, int type, const Scalar& s)
传递cv :: Scalar(0)应该适合你的目的。
passing cv::Scalar(0) should be good for your purposes.
int sizes[] = { 100, 100, 100 };
cv::Mat *matrix = new cv::Mat(3, sizes, CV_32FC1, cv::Scalar(0));
这应该是一个3D矩阵,一种边为100的立方体。
This should make a 3D matrix, a sort of cube with edge 100.
这篇关于如何零元素的3D矩阵与opencv库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!