Ask Your Question
1

Access 32F Mat element by pointer

asked 2013-03-26 13:52:00 -0600

Seb gravatar image

updated 2013-03-26 13:55:41 -0600

Usually I do

unsigned char *input = (unsigned char*)(oOut.data);
for (int i = 0; i < oOut.rows; i++)
{
  for (int j = 0; j < oOut.cols; j++)
  {    
    input[oOut.step[0]*i + oOut.step[1]*j] = 255;
  }
}

This is with a typical 8UC1 mat. Now, I want to store values that can range from -1500 to 1500. So I'm using a CV_32F mat. But I can't figure out how to store values inside. I always end up with corruption with incoherent values.

Can someone help me?

Edit, I mean 32F, not 32S, my mistake

Thanks Seb

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
6

answered 2013-03-26 14:02:24 -0600

berak gravatar image

updated 2013-03-26 14:05:41 -0600

/// oOut.type == CV_32F;
for (int i = 0; i < oOut.rows; i++)
{
  // the mat might not be continuous, so restart for each row
  float * row = oOut.ptr<float>(i);    
  for (int j = 0; j < oOut.cols; j++)
  {    
    row[j] = 123456;
  }
}

  // if oOut.type == CV_32S, it might look like this:
  // int * row = oOut.ptr<int>(i);

.. you 'll get the picture ..

edit flag offensive delete link more

Comments

Awesome, that is working!

Seb gravatar imageSeb ( 2013-03-26 14:07:30 -0600 )edit

Question Tools

Stats

Asked: 2013-03-26 13:52:00 -0600

Seen: 1,678 times

Last updated: Mar 26 '13