OpenCV:访问 5D Matrix 的元素



我在OpenCV中访问5D矩阵的元素时遇到问题。我使用

int sizes[5] = { height_, width_, range_, range_, range_ };
Mat w_i_ = Mat(2 + channels, sizes, CV_16UC(channels), Scalar(0));

其中通道 = 3。然后我尝试使用 for 循环访问和修改矩阵元素:

for (UINT Y = 0; Y < height; ++Y) {
    for (UINT X = 0; X < width; ++X) {
        // a) Compute the homogeneous vector (wi,w)
        Vec3b wi = image.at<Vec3b>(Y, X);
        // b) Compute the downsampled coordinates
        UINT y = round(Y / sigmaSpatial);
        UINT x = round(X / sigmaSpatial);
        Vec3b zeta = round( (image.at<Vec3b>(Y, X) - min) / sigmaRange);
                       // round() here is overloaded for vectors
        // c) Update the downsampled S×R space
        int idx[5] = { y, x, zeta[0], zeta[1], zeta[2] };
        w_i_.at<Vec3b>(idx) = wi;
    }
}

当我运行代码时,我收到 Mat::at() 生成的断言失败错误。具体来说,我得到的消息是:

OpenCV Error: Assertion failed (elemSize() == (((((DataType<_Tp>::type) & ((512 - 1) << 3)) >> 3) + 1) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> ((DataType<_Tp>::type) & ((1 << 3) - 1))*2) & 3))) in cv::Mat::at, file c:opencvbuildincludeopencv2coremat.inl.hpp, line 1003

我已经在网上搜索过,但我似乎找不到任何关于 5D 矩阵的主题(类似的主题被证明没有帮助)。

提前致谢

初始化zeta变量,但不检查其值。最有可能的是,您获得的zeta[0], zeta[1]zeta[2]指数的值超出范围,因此at()函数中的内部范围检查失败。

为了防止此类崩溃,至少在调用 at() 之前添加一些手动范围检查:

for(int i = 0 ; i < 3 ; i++)
   if(zeta[i] < 0 || zeta[i] >= _range)
      continue;

最新更新