Ask Your Question
0

from MAT to BIDIMENSIONAL ARRAY

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

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

Comments

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 -0600 )edit

I have to multiply a Mat with a bidimensional array

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

2 answers

Sort by ยป oldest newest most voted
2

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

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
0

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

Jawaher Khemakhem gravatar image

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

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 = im.at<uchar>(i, j);// you can access to each element (row/col) 

    }
}
edit flag offensive delete link more

Comments

                     for (int i = 0; i &lt; rows; i++){
                                for (int j = 0; j &lt; cols; j++){
                                       imfft=imfft*filter[i][j]
                                  }}

I have to multiply an array with a mat

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

Question Tools

Stats

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

Seen: 411 times

Last updated: May 28 '13