//cv::Mat中获取图像中某一点的值是比较麻烦的,一一来探秘
//预备知识
/*
/*\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,第二个参数------------------------
enum
{
// 8bit, color or not
IMREAD_UNCHANGED =-1,
// 8bit, gray
IMREAD_GRAYSCALE =0,
// ?, color
IMREAD_COLOR =1,//默认
// any depth, ?
IMREAD_ANYDEPTH =2,
// ?, any color
IMREAD_ANYCOLOR =4
};
------------------------Mat 常用信息------------------------------
//! returns element type, similar to CV_MAT_TYPE(cvmat->type)
//! 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]
//预备知识
/*
/*\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,第二个参数------------------------
enum
{
// 8bit, color or not
IMREAD_UNCHANGED =-1,
// 8bit, gray
IMREAD_GRAYSCALE =0,
// ?, color
IMREAD_COLOR =1,//默认
// any depth, ?
IMREAD_ANYDEPTH =2,
// ?, any color
IMREAD_ANYCOLOR =4
};
------------------------Mat 常用信息------------------------------
//! 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;
常见的有:
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 depth
switch ( 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 channels
switch( 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;
}