Aayman Khalid
Aayman Khalid

Reputation: 468

determining the data type of an image in OpenCV

I am reading the image in Ipl format and then convert it into Mat form. then I try to dispaly the number of rows,columns,channels and depth of the image. the result of the first three is as expected however the result of the depth is:

Code line: cout<<" "<<"Depth ="<

Result: Depth = 0

could anyone tell me what does this mean???

Upvotes: 0

Views: 2037

Answers (2)

Antoine
Antoine

Reputation: 14064

depth is a flag (#defined int in types_c.h), to print it use for example:

const char* depthToStr(int depth) {
  switch(depth){
    case CV_8U: return "unsigned char";
    case CV_8S: return "char";
    case CV_16U: return "unsigned short";
    case CV_16S: return "short";
    case CV_32S: return "int";
    case CV_32F: return "float";
    case CV_64F: return "double";
  }
  return "invalid type!";
}

and use like this: cout << "depth = " << depthToStr(mat.depth()) << endl;

Upvotes: 4

molbdnilo
molbdnilo

Reputation: 66371

The documentation can tell you what it means:

The method returns the identifier of the matrix element depth (the type of each individual channel). For example, for a 16-bit signed 3-channel array, the method returns CV_16S.

You should check it out, it's quite useful.

Upvotes: 0

Related Questions