Ask Your Question
0

Undefined depth matrix [closed]

asked 2016-02-26 07:38:11 -0500

thierrypin gravatar image

Hi there,

I'm trying to create an undefined number of layers, like this:

Mat img(rows, cols, CV_32SC(N));

It works fine until I need to access the values. I know I can't do anything like:

Vec<int, n> p = tmp.at<Vec<int, n> >

I must have a predetermined number for the compiler, so the only alternative I see right now is to have a few predetermined values to choose, like below.

static void method(params..., int n)
{
    switch (n)
    {
        case 8:   method_<Vec<int, 8> >(params..., int n); break;
        case 16:   method_<Vec<int, 8> >(params..., int n); break;
        ...
        default:
            string error_msg = format("Unsupported value of N. Choices: 8, 16 ...");
            CV_Error(CV_StsNotImplemented, error_msg);
            break;
    }
}

Is there a way to make it more flexible? Thank you.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by thierrypin
close date 2016-03-14 15:38:28.647746

Comments

for sure, you cannot determine n at runtime, it has to be a compile-time constant

maybe make method a template function , too ? like:

template<int N> void method(...) { Vec<int,N> p = tmp.at<Vec<int,N>>(3); }
berak gravatar imageberak ( 2016-02-26 08:46:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-26 08:45:19 -0500

kbarni gravatar image

updated 2016-02-26 08:46:07 -0500

You can build directly N-dimensional matrices. For a 3D matrix:

int sizes[]={W,H,D};  //width, height, depth: known integers
Mat block(3,sizes,CV_32U);

More information here: http://docs.opencv.org/3.1.0/d3/d63/c...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-26 07:38:11 -0500

Seen: 72 times

Last updated: Feb 26 '16