//原文:http://blog.csdn.net/moc062066/article/details/6949894
//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)
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 = "";
-
-
- 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 ;
- }
-
-
- 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 ;
- }
-
-
- switch( mat_input.type() % 8 ) {
- case 0:
-
- mat_type_name += " uchar";
- break;
-
- case 1:
-
- mat_type_name += " char";
- break;
-
- case 2:
-
- mat_type_name += " ushort";
- break;
-
- case 3:
-
- mat_type_name += " short";
- break;
-
- case 4:
-
- mat_type_name += " int";
- break;
-
- case 5:
-
- mat_type_name += " float";
- break;
-
- case 6:
-
- mat_type_name += " double";
- break;
-
- default:
- break;
- }
- cout << "\n" << mat_type_name << endl ;
- return mat_type_name;
- }
/****************************************在另一篇文章里看到的************************************、
说到数据的存储,这一直就是一个值得关注的问题,
Mat_<uchar>对应的是CV_8U
Mat_<char>对应的是CV_8S,
Mat_<int>对应的是CV_32S,
Mat_<float>对应的是CV_32F,
Mat_<double>对应的是CV_64F,
对应的数据深度如下:
CV_8U - 8-bit unsigned integers ( 0..255 )
CV_8S - 8-bit signed integers ( -128..127 )
CV_16U - 16-bit unsigned integers ( 0..65535 )
CV_16S - 16-bit signed integers ( -32768..32767 )
CV_32S - 32-bit signed integers ( -2147483648..2147483647 )
CV_32F - 32-bit ?oating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
CV_64F - 64-bit ?oating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )
这里还需要注意一个问题,很多OpenCV的函数支持的数据深度只有8位和32位的,所以要少使用CV_64F,但是vs的编译器又会把float数据自动变成double型,有些不太爽。