Ask Your Question
0

opencv create mat object with a loop

asked 2014-01-17 17:03:04 -0600

jossyy gravatar image

updated 2014-01-23 07:45:24 -0600

Hello,

I use this code :

Mat sampleMat = (Mat_<float>(1,1) << (trainData[i][0]));

But I want to create mat object with a loop. Maybe it looks like this :

Mat sampleMat = (Mat_<float>(1,size) << for(j < size)(trainData[i][j]));

How can I do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-01-23 07:49:12 -0600

The following steps need to be done to achieve this:

// Allocate memory for your matrix (e.g. 8x8 int matrix)
Mat temp_matrix (15, 15, CV_8UC1);
// Make a double loop over indexes and assign values
for(int rows; rows < 15; rows++){
   for(int cols; cols < 15; cols++){
      temp_matrix.at<uchar>(rows,cols) = selected_value;
   }
}
edit flag offensive delete link more

Comments

1

ok, thank you very much StevenPuttemans...

jossyy gravatar imagejossyy ( 2014-01-23 07:52:52 -0600 )edit

I do know there are more effective ways to fill up matrices, but I haven't been in need since this is performing perfectly real time on my system. Maybe take a look at this page.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-23 08:28:36 -0600 )edit

Question Tools

Stats

Asked: 2014-01-17 17:03:04 -0600

Seen: 1,401 times

Last updated: Jan 23 '14