First time here? Check out the FAQ!

Ask Your Question
0

Undefined depth matrix [closed]

asked Feb 26 '16

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.

Preview: (hide)

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 (Feb 26 '16)edit

1 answer

Sort by » oldest newest most voted
0

answered Feb 26 '16

kbarni gravatar image

updated Feb 26 '16

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...

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Feb 26 '16

Seen: 222 times

Last updated: Feb 26 '16