三维垫返回一个空矩阵

3 dimensional Mat returns a null Matrix

本文关键字:一个 返回 三维      更新时间:2023-10-16

我正在尝试在OpenCV中初始化一个三维垫,如下所示:

3d_matrix = Mat(3, sizes, CV_64FC1, double(0));

其中sizes是大小3intsizes的值为 341441170

但是,在去窃听时,我看到3d_matrix rowscols都设置为-1

当我尝试将此矩阵编写为图像时,它会创建一个空图像(即它没有大小(,正如预期的那样。

正如@Miki所说,对于多维矩阵,行和列设置为 -1。

如果您只有 3 个暗角,则可以使用以下内容:

cv::Mat threed_matrix = cv::Mat(341, 441, CV_64FC(170));
std::cout << "rows: " << threed_matrix.rows << std::endl
          << "cols: " << threed_matrix.cols << std::endl
          << "channels(): " << threed_matrix.channels() << std::endl;

这给了:

rows: 341
cols: 441
channels(): 170

请注意,通道大小不应超过 CV_CN_MAX ,这是当前在 OpenCV 中512定义的