Ask Your Question

Does accumulate() in OpenCV 3.0.0 support the 3d Mat?

asked 2015-11-14 10:50:30 -0500

manfeyn gravatar image

updated 2015-11-14 20:17:03 -0500

Hi, guys.

I migrate opencv 3.0.0 recently. After the migration, the accumulate() in the following line throw an exception.

int sizes[] = {1, 512, 1024};

cv::Mat mat1(3, sizes, CV_32F, cv::Scalar(1);

cv::Mat mat2(mat.dims, mat1.row(0).sizes(), CV_32F, cv::Scalar(0));

for (int y = 0; y < 3; y ++) accumulate(mat1.row(y), mat2);

I changed the mat1's dimensions from 3 to 2 by squeeze() then there was no exception. Before the migration, the OpenCV's version is 2.4.9 and this codes works well.

I read the documentation of accumulate() in opencv 3.0.0. And it gives this function:

dst(x,y) = dst(x,y) + src(x,y) if mask != 0

Does this mean accumulate() in OpenCV 3.0.0 does not support 3d mat any more? What is the best practices if I want to accumulate the 3d Mat?

Thanks :)

Update: The matrix's dimension is 1x512x512. Then I used mat.squeeze() to get a 2d matrix to solve this problem. But I feel it's not efficient because the mat.squeeze() is called in the loop. I wonder if there is another way to solve this problem.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-11-17 08:09:52 -0500

manfeyn gravatar image

updated 2015-11-18 03:04:41 -0500

I build the OpenCV 3.0.0 source codes and found the reason why the accumulate() threw an exception.

Mat::Size() is called in cv::accumulate():

// improc/src/accum.cpp
void cv::accumulate( InputArray _src, InputOutputArray _dst, InputArray _mask )
     Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
      Size size = src.size();

However, the Mat::MatSize::operator() does not support 3d matrix:

// opencv2/core/mat.inl.hpp
Size MatSize::operator()() const
    CV_DbgAssert(p[-1] <= 2);
    return Size(p[1], p[0]);

So I guess the cv::accumulate() in OpenCV 3.0.0 does not support 3d matrix.

Please correct me if I am wrong.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-11-14 10:50:30 -0500

Seen: 526 times

Last updated: Nov 18 '15