OpenCV 2.4.X最常用的数据类型
2013-09-07 12:43
141 查看
1、Point_
Point_<> 模版类
或者,旧版:CvPoint CvPoint2D32f
点只可以进行加减和比较,不能进行乘除运算。
2、Size_
用于定义一个长为x,宽为y的图形或者矩形
3、Rect_
(shiftinga rectangle by a certain offset偏移)
(expandingor shrinking a rectangle by a certain amount)
rect = rect1 & rect2 (rectangleintersection)
rect = rect1 | rect2 (minimumarea rectangle contain rect2 and rect3 )
Coordinates of the top-left corner. This isa default interpretation of Rect_::x and Rect_::y inOpenCV.
OpenCV typicallyassumes that the top and left boundary of the rectangle are inclusive, whilethe right and bottom boundaries are not.
4、RotatedRect(旋转矩阵)
RotatedRect rRect =RotatedRect(Point2f(200,200),Size2f(200,100), 60);
Point2f vertices[4];
rRect.points(vertices);
Rect brect = rRect.boundingRect();
可以使用points函数返回它的4个顶点,使用boundingRect求出它的外接矩形(非旋转)
5、Matx
用来记录一些小的矩形,这些矩形在编译前大小就固定了。
6、Vec
元素较少的向量
8、Scalar_
用Vec<tp,4>派生下来的,也就是说,它是一个4元组。
7、Mat
不仅可以把它当做一个储存图像的数据结构,还可以储存二维矩阵,也可以储存高维矩阵。在2.0以上的版本中,使用Mat类来储存一幅图像。数据存在data指针所指向的地址中的。
int main(void)
{
Mat img1 = imread("D:/picture/images/baboon1.jpg",0);//灰度图像
cout<<img1.rows<<endl;
cout<<img1.cols<<endl;
cout<<img1.size[0]<<endl;//与img1.rows相等
cout<<(int)img1.at<uchar>(1,2)<<endl;//(1,2)点的灰度值
cout<<(int)(*(img1.data + img1.step[0] * 1 + img1.step[1] * 2))<<endl;//(1,2)点的灰度值
Mat img2 = imread("D:/picture/images/baboon1.jpg");//彩色图像
cout<<(int)img2.at<Vec3b>(1,2)[1]<<endl;//(1,2)点的G分量
cout<<(int)(*(img2.data + img2.step[0] * 1 + img2.step[1] * 2 + sizeof(uchar)))<<endl;//(1,2)点的G分量
return 0;
}
因为8bit图像对应的像素值为0~255,所以opencv使用了uchar类型,这样非常节省空间;但是如果想看到具体的像素值,那么得把他转化为int。
我们看到,使用at函数和直接求出地址然后对地直接引得到的像素值是相同的。at操作是一个模板函数,所以对于灰度图像,返回的直接就是对应的像素值;而对于彩色图像,返回的是一个3元组Vec3b。这个结构是3个uchar连续的放在一起的。所以对于彩色图像,直接使用公式获得的是B分量,如果想获得其他分量,那么得在原始的地址上加上一个sizeof(uchar)。
二维: typedefPoint_<int>Point2i;
typedefPoint2iPoint;
typedefPoint_<float> Point2f;
typedefPoint_<double> Point2d;
Point_<> 模版类
或者,旧版:CvPoint CvPoint2D32f
三维: typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;
点只可以进行加减和比较,不能进行乘除运算。
2、Size_
typedef Size_<int> Size2i;
typedef Size2i Size;
typedef Size_<float> Size2f;
用于定义一个长为x,宽为y的图形或者矩形
3、Rect_
typedef Rect_<int> Rect;
(shiftinga rectangle by a certain offset偏移)
(expandingor shrinking a rectangle by a certain amount)
rect = rect1 & rect2 (rectangleintersection)
rect = rect1 | rect2 (minimumarea rectangle contain rect2 and rect3 )
Coordinates of the top-left corner. This isa default interpretation of Rect_::x and Rect_::y inOpenCV.
OpenCV typicallyassumes that the top and left boundary of the rectangle are inclusive, whilethe right and bottom boundaries are not.
4、RotatedRect(旋转矩阵)
RotatedRect rRect =RotatedRect(Point2f(200,200),Size2f(200,100), 60);
Point2f vertices[4];
rRect.points(vertices);
Rect brect = rRect.boundingRect();
可以使用points函数返回它的4个顶点,使用boundingRect求出它的外接矩形(非旋转)
5、Matx
用来记录一些小的矩形,这些矩形在编译前大小就固定了。
template<typename _Tp, int m, int n>classMatx {...};
typedef Matx<float,1,2> Matx12f;
typedef Matx<double,1,2> Matx12d;
...
typedef Matx<float,1,6> Matx16f;
typedef Matx<double,1,6> Matx16d;
typedef Matx<float,2,1> Matx21f;
typedef Matx<double,2,1> Matx21d;
...
typedef Matx<float,6,1> Matx61f;
typedef Matx<double,6,1> Matx61d;
typedef Matx<float,2,2> Matx22f;
typedef Matx<double,2,2> Matx22d;
...
typedef Matx<float,6,6> Matx66f;
typedef Matx<double,6,6> Matx66d;
例:Matx33f m(1,2,3,
4,5,6,
7,8,9);
cout<< sum(Mat(m*m.t()))<< endl;
6、Vec
元素较少的向量
template<typename _Tp, int n>classVec:public Matx<_Tp, n, 1> {...};
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<int,2> Vec2i;
typedef Vec<int,3> Vec3i;
typedef Vec<int,4> Vec4i;
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;
8、Scalar_
用Vec<tp,4>派生下来的,也就是说,它是一个4元组。
template<typename _Tp>classScalar_:public Vec<_Tp,4> { ... };
typedef Scalar_<double> Scalar;
7、Mat
不仅可以把它当做一个储存图像的数据结构,还可以储存二维矩阵,也可以储存高维矩阵。在2.0以上的版本中,使用Mat类来储存一幅图像。数据存在data指针所指向的地址中的。
int main(void)
{
Mat img1 = imread("D:/picture/images/baboon1.jpg",0);//灰度图像
cout<<img1.rows<<endl;
cout<<img1.cols<<endl;
cout<<img1.size[0]<<endl;//与img1.rows相等
cout<<(int)img1.at<uchar>(1,2)<<endl;//(1,2)点的灰度值
cout<<(int)(*(img1.data + img1.step[0] * 1 + img1.step[1] * 2))<<endl;//(1,2)点的灰度值
Mat img2 = imread("D:/picture/images/baboon1.jpg");//彩色图像
cout<<(int)img2.at<Vec3b>(1,2)[1]<<endl;//(1,2)点的G分量
cout<<(int)(*(img2.data + img2.step[0] * 1 + img2.step[1] * 2 + sizeof(uchar)))<<endl;//(1,2)点的G分量
return 0;
}
因为8bit图像对应的像素值为0~255,所以opencv使用了uchar类型,这样非常节省空间;但是如果想看到具体的像素值,那么得把他转化为int。
我们看到,使用at函数和直接求出地址然后对地直接引得到的像素值是相同的。at操作是一个模板函数,所以对于灰度图像,返回的直接就是对应的像素值;而对于彩色图像,返回的是一个3元组Vec3b。这个结构是3个uchar连续的放在一起的。所以对于彩色图像,直接使用公式获得的是B分量,如果想获得其他分量,那么得在原始的地址上加上一个sizeof(uchar)。
相关文章推荐
- OpenCV 2.4.X最常用的数据类型
- Opencv中的Mat类型常用函数数据
- OpenCV中数据类型和常用数据类型对应关系
- opencv常用数据类型的转换(个人整理)
- opencv 中常用的数据类型
- 常用的Opencv的数据类型
- Oracle常用的数据类型
- VC++常用数据类型及其操作详解
- 第一课 OC最常用的数据类型
- Redis的介绍和常用数据类型结构命令的总结
- android jni常用数据类型的记录
- 交易系统常用的字段及数据类型
- NSLog 一些常用的数据类型 CGRect NSArray等
- (六)redis常用数据类型 SortedSet
- VC常用数据类型使用转换详解
- 共同学习Java源码--常用数据类型--String(十二)
- 共同学习Java源码--常用数据类型--String(十三)
- 常用数据类型转换CString double char int WCHAR(转)
- PostgreSQL学习手册(四) 常用数据类型
- VC常用数据类型使用转换详解 (转)