Ask Your Question
0

Not able to create Mat object with float data

asked 2014-05-30 05:03:50 -0600

raja gravatar image

updated 2014-05-30 05:04:15 -0600

I am trying to create a Mat object with a float type data. Mat kernelxx = Mat( HEIGHT, WIDTH, CV_32FC1 );

But what I receive is unsigned char data of type *uchar::Mat::data. Can any one please help me. I also tried using create constructor as well as convertTo() method to make a float data. But all of them create only *uchar data.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2014-05-30 05:19:09 -0600

berak gravatar image

updated 2014-05-30 05:28:00 -0600

no worries, your Mat creation is correct.

float *fp = kernelxx.ptr<float>(0); //will give you the pointer to the 1st row.

(the underlying data buffer is still uchar*)

edit flag offensive delete link more

Comments

Thanks for the answer. But it still didn't solve my purpose. My underlying Mat object still has uchar data. I need a mat object with float data.

Mat kernelxx = Mat::ones( HEIGHT, WIDTH, CV_32FC1 )/HEIGHT*WIDTH; //this creates data with zeros This is weird, as Mat consturctor supports creation of float data.

Mat src=imread("variance8inv.png"); Mat dst(imageHeight, imageWidth, CV_32FC1); filter2D(src, dst, -1 , kernelxx, Point( -1, -1 ), 0, BORDER_DEFAULT );

raja gravatar imageraja ( 2014-05-30 06:13:45 -0600 )edit
  • "I need a mat object with float data." - ALL Mat's have uchar* data, no matter what type.
  • "this creates data with zeros" - i don't think so.

    Mat kernelxx = Mat::ones( 5,6, CV_32FC1 ); cerr << kernelxx << endl;

    [1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1]

  • Mat src=imread("variance8inv.png"); // this will load a 3 channel image, you want:

    Mat src=imread("variance8inv.png", 0); // load as single gray channel

  • also: filter2D(src, dst, CV_32FC1 , kernelxx, Point( -1, -1 ), 0, BORDER_DEFAULT );

    it will overwrite/realloc dst anyway. maybe you even want to src.convertTo(src, CV_32F); before.

berak gravatar imageberak ( 2014-05-30 07:05:53 -0600 )edit

Question Tools

Stats

Asked: 2014-05-30 05:03:50 -0600

Seen: 275 times

Last updated: May 30 '14