CV: information frequently used by mat

Source: Internet
Author: User

// CV: It is troublesome to obtain a certain value in the image in mat.

// Prerequisites
/*
/* \ Typedef
Access individual elements using [] operator etc.
Shorter aliases for the most popular specializations of VEC <t, n>

Typedef VEC <uchar, 2> vec2b;
Typedef VEC <uchar, 3> vec3b;
Typedef VEC <uchar, 4> vec4b;

Typedef VEC <short, 2> vec2s;
Typedef VEC <short, 3> vec3s;
Typedef VEC <short, 4> vec4s;

Typedef VEC <ushort, 2> vec2w;
Typedef VEC <ushort, 3> vec3w;
Typedef VEC <ushort, 4> vec4w;

Typedef VEC <int, 2> vec2i;
Typedef VEC <int, 3> vec3i;
Typedef VEC <int, 4> vec4i;
Typedef VEC <int, 6> vec6i;
Typedef VEC <int, 8> vec8i;

Typedef VEC <float, 2> vec2f;
Typedef VEC <float, 3> vec3f;
Typedef VEC <float, 4> vec4f;
Typedef VEC <float, 6> vec6f;

Typedef VEC <double, 2> vec2d;
Typedef VEC <double, 3> vec3d;
Typedef VEC <double, 4> vec4d;
Typedef VEC <double, 6> vec6d;

-------------------- Imread, second parameter ------------------------
Enum
{
// 8bit, color or not
Imread_unchanged =-1,
// 8bit, gray
Imread_grayscale = 0,
//?, Color
Imread_color = 1, // default
// Any depth ,?
Imread_anydepth = 2,
//?, Any color
Imread_anycolor = 4
};

------------------------ Mat common information ------------------------------
//! Returns element type, similar to cv_mat_type (cvmat-> type)

Int type () const; // 0, 1, 2,..., 6

//! Returns element type, similar to cv_mat_depth (cvmat-> type)

Int depth () const;

Common examples include:

Cv_8u:
Cv_8s:
Cv_16u:
Cv_16s:
Cv_32s:
Cv_32f:
Cv_64f:


//! Returns element type, similar to cv_mat_cn (cvmat-> type)
Int channels () const; // 1, 2, 3

//! The matrix dimensionality,> = 2
Int dims;

//! The number of rows and columns or (-1,-1) when the matrix has more than 2 dimensions
Int rows, cols;

//! Pointer to the data
Uchar * data;

------------------------------------
# Define cv_8u 0
# Define cv_8s 1
# Define cv_16u 2
# Define cv_16s 3
# Define cv_32s 4
# Define cv_32f 5
# Define cv_64f 6
# Define cv_usrtype1 7

CV _ [The number of bits per item] [signed or unsigned] [type prefix] C [the channel number]

string show_Mat_type( Mat mat_input ){string mat_type_name = "";//detect depthswitch ( mat_input.depth() ) {case CV_8U   :mat_type_name = "CV_8U";break;case CV_8S   :mat_type_name = "CV_8S";break;case CV_16U  :mat_type_name = "CV_16U";break;case CV_16S  :mat_type_name = "CV_16S";break;case CV_32S  :mat_type_name = "CV_32S";break;case CV_32F  :mat_type_name = "CV_32F";break;case CV_64F  :mat_type_name = "CV_64F";break;default:cout << "switch ( mat_input.depth() ) error!" << endl ;}//detect channelsswitch( mat_input.channels() ) {case 1 :mat_type_name += "C1";break;case 2 :mat_type_name += "C2";break;case 3 :mat_type_name += "C3";break;default:cout << "switch( mat_input.channels() ) error!" << endl ;}//uchar char short    switch( mat_input.type() % 8 ) {    case 0:      //cout<<  int( ((uchar*)mat.data + Cols*i+Chns*j )[k] )<<" ";      mat_type_name += " uchar";      break;          case 1:      //cout<<  int( (  (char*)mat.data + Cols*i+Chns*j)[k] )<<" ";           mat_type_name += " char";      break;          case 2:      //cout<<  (  (unsigned short*)mat.data + Cols*i+Chns*j)[k] <<" ";        mat_type_name += " ushort";      break;          case 3:      //cout<<  (  (short*)mat.data + Cols*i+Chns*j)[k] <<" ";           mat_type_name += " short";      break;          case 4:      //cout<<  (  (int*)mat.data + Cols*i+Chns*j)[k] <<" ";           mat_type_name += " int";      break;          case 5:      //cout<<  (  (float*)mat.data + Cols*i+Chns*j)[k] <<" ";        mat_type_name += " float";      break;          case 6:      //cout<<  (  (double*)mat.data + Cols*i+Chns*j)[k] <<" ";        mat_type_name += " double";      break;          default:       break;    }cout << "\n" << mat_type_name << endl ;return mat_type_name;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.