Ask Your Question

How to pass 3D array to Mat ?

asked 2016-12-20 03:18:42 -0500

Nbb gravatar image

updated 2016-12-20 03:24:41 -0500

I have a 3d array

float*** gradientStrengths = new float**[cells_in_y_dir];

After filling it up, how do I pass it to an opencv mat ?

cv::Mat gradientStrengths_mat = gradientStrengths;

Also, how do I extract the 3rd dimension ? there is gradientStrengths_mat.row(0) or col(0) but no depth(0) ?

edit retag flag offensive close merge delete


what are the dimensions of your 3d array ?

berak gravatar imageberak ( 2016-12-20 05:12:22 -0500 )edit

its 60 rows x80 cols x9. I used a vector of mat as a temporary solution but would still like to know how this can be done. Especially accessing the depth like .depth(0).

Nbb gravatar imageNbb ( 2016-12-20 06:01:37 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-12-20 06:11:05 -0500

berak gravatar image

updated 2016-12-20 06:11:47 -0500

you could try with a

Mat(80, 90, CV_32FC(9)); // a Mat with 9 channels ! (you can have up to 512 here)
typedef Vec<9,float> Vec9f; // an element of this

Vec9f &p =<Vec9f>(4,4); 
p[7] = 1.2f;

and rather try to abandon your float*** gradientStrengths in favor of this.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-20 03:18:42 -0500

Seen: 584 times

Last updated: Dec 20 '16