1

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));

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));

Error message:

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)

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.

4

1 回答 1

6

我提醒你文档,你可以使用这个构造函数:

C++: Mat::Mat(int ndims, const int* sizes, int type, const Scalar& s)

传递 cv::Scalar(0) 应该有利于您的目的。

int sizes[] = { 100, 100, 100 };
cv::Mat *matrix = new cv::Mat(3, sizes, CV_32FC1, cv::Scalar(0));

这应该生成一个 3D 矩阵,一种边为 100 的立方体。

于 2013-10-03T20:36:50.020 回答