Ask Your Question


asked 2013-05-28 10:30:26 -0500

residentelvio gravatar image

Does a function doing this work exists? I need to change a Mat objecto into a bidimensional array to work with every element.

Thanks to help

edit retag flag offensive close merge delete


if I pass to a function a Mat object ass a Mat **name , after can i transfer every element to a bidimensional array?

residentelvio gravatar imageresidentelvio ( 2013-05-28 10:34:01 -0500 )edit

I have to multiply a Mat with a bidimensional array

residentelvio gravatar imageresidentelvio ( 2013-05-28 10:42:03 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-05-28 12:56:18 -0500

berak gravatar image

if it's actually a bidimensional Array, you could even try to make a Mat from that:

Mat m1 = Mat::ones(3,3,CV32F); // placeholder for your mat there

float bd_arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
Mat m2(3,3,CV_32F,bd_arr); 
Mat m3 = m1 * m2;

note, that this won't work with an array of pointers, a dynamically allocated 2d array like this:

float **bad = new float*[3];
bad[0] = new float[3];
bad[1] = new float[3];
bad[2] = new float[3];

(totally different memory layout)

edit flag offensive delete link more

answered 2013-05-28 12:40:51 -0500

Jawaher Khemakhem gravatar image

updated 2013-05-28 13:20:42 -0500

A mat object is 2 D or 3 D array , if we consider that your mat object is 2 D so it is obligatory an array with dimension 2 , you can access to each element in your object mat "im" using for example :

for (int i = 0; i < im.rows; i++)
    for (int j = 0; j < im.cols; j++)
        uchar p1 =<uchar>(i, j);// you can access to each element (row/col) 

edit flag offensive delete link more


                     for (int i = 0; i &lt; rows; i++){
                                for (int j = 0; j &lt; cols; j++){

I have to multiply an array with a mat

residentelvio gravatar imageresidentelvio ( 2013-05-28 20:09:37 -0500 )edit

Question Tools


Asked: 2013-05-28 10:30:26 -0500

Seen: 278 times

Last updated: May 28 '13