Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6901625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:41:48+00:00 2026-05-27T07:41:48+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:41:49+00:00Added an answer on May 27, 2026 at 7:41 am

    The type is a variable, NOT a function:

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

    EDIT:

    As for the unusual value of type being printed, according to this answer, this variable stores more than the data type.

    So the appropriate way of checking cvMat data type is using the macro CV_MAT_TYPE():

    CvMat *tmp2 = cvCreateMat(3,1, CV_32FC1);
    std::cout << "tmp2 type = " << tmp2->type << " and CV_32FC1 = " << CV_32FC1 << " and " << (CV_MAT_TYPE(tmp2->type) == CV_32FC1) << std::endl;
    

    The naming convention of the data type is:

    CV_<bit_depth>(S|U|F)C<number_of_channels>
    
    S = Signed integer
    U = Unsigned integer
    F = Float 
    
    E.g.: CV_8UC1 means an 8-bit unsigned single-channel matrix, 
          CV_32FC2 means a 32-bit float matrix with two channels.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a CvMat data structure using cvMat() in OpenCV. The
Using OpenCV, saving a CvMat structure into a YAML file on the disk is
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I'm using the OpenCV framework with XCode and want to convert from cvMat or
I'm making simple webcam program using OpenCV 2.3 and got stuck by the compile
I know how to do the opposite i.e. get GpuMat from CvMat using upload,
I'm using a CvNormalBayesClassifier. I'm training it with some random data, like in the
I have one function to compute convolution (to test whether we are using correct
Using Flash CS4 with Actionscript 3 I type the following: trace(Math.pow(97,83) % 205); Which
Using LINQ on collections, what is the difference between the following lines of code?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.