cv::Mat Syntax for CvMat.data.db

asked 2014-01-19 18:53:43 -0600

MRDaniel gravatar image

Using a CvMat, it is possible to...

double* _x = dTx->data.db;

What is the equivalent syntax with a cv::Mat?

edit retag flag offensive close merge delete

Comments

double * _x = mat.ptr<double>(0); // pointer to row 0

you'll have to do this for every row if your Mat is not continuous ( e.g a ROI or a subrect )

berak gravatar imageberak ( 2014-01-20 04:27:09 -0600 )edit

Ah, thank you. I also found the (double)mat.data can work as you cast the uchar to a double*. I have only gotten this to compile, i have not tested. So i will keep your solution handy at all times. Thank you.

MRDaniel gravatar imageMRDaniel ( 2014-01-20 14:51:39 -0600 )edit

No intellisense errors for my syntax using a cast to a double*, however the data is mangled and useless.

I'm using your approach..... however, I'm not sure about this one.

int * fastp = (int*)(idx->data.ptr + idx->step * i);

Any thoughts?

int * fastp = (int * )(idx.data + idx.step * i);

MRDaniel gravatar imageMRDaniel ( 2014-01-21 05:49:43 -0600 )edit

that's for the old CvMat ( deprecated c-api ) . don't use it.

and ofc, whatever way of casting you use, the type of the Mat has to fit.

no use casting a CV_8UC3 rgb image to double or such. that will only result in garbage..

berak gravatar imageberak ( 2014-01-21 06:32:53 -0600 )edit