How to determine the data type of a CvMat

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2011-11-30T01:07:08Z Indexed on 2011/12/01 1:53 UTC
Read the original article Hit count: 381

Filed under:
|

When using the CvMat type, the type of data is crucial to keeping your program running.

For example, depending on whether your data is type float or unsigned char, you would choose one of these two commands:

cvmGet(mat, row, col);
cvGetReal2D(mat, row, col);

Is there a universal approach to this? If the wrong data type matrix is passed to these calls, they crash at runtime. This is becoming an issue, since a function I have defined is getting passed several different types of matrices.

How do you determine the data type of a matrix so you can always access its data?

I tried using the "type()" function as such.

CvMat* tmp_ptr = cvCreateMat(t_height,t_width,CV_8U);
std::cout << "type = " << tmp_ptr->type() << std::endl;

This does not compile, saying "term does not evaluate to a function taking 0 arguments". If I remove the brackets after the word type, I get a type of 1111638032

EDIT minimal application that reproduces this...

int main( int argc, char** argv )
{
    CvMat *tmp2 = cvCreateMat(10,10, CV_32FC1);
    std::cout << "tmp2 type = " << tmp2->type << " and CV_32FC1 = " << CV_32FC1 << " and " << (tmp2->type == CV_32FC1) << std::endl;
}

Output: tmp2 type = 1111638021 and CV_32FC1 = 5 and 0

© Stack Overflow or respective owner

Related posts about c

    Related posts about opencv