OpenCV 2.4.X最常用的数据类型
2014-01-14 09:33
447 查看
1、Point_
Point_<>模版类
或者,旧版:CvPointCvPoint2D32f
点只可以进行加减和比较,不能进行乘除运算。
2、Size_
用于定义一个长为x,宽为y的图形或者矩形
3、Rect_
(shiftingarectanglebyacertainoffset偏移)
(expandingorshrinkingarectanglebyacertainamount)
rect=rect1&rect2(rectangleintersection)
rect=rect1|rect2(minimumarearectanglecontainrect2andrect3)
Coordinatesofthetop-leftcorner.ThisisadefaultinterpretationofRect_::xandRect_::yinOpenCV.
OpenCVtypicallyassumesthatthetopandleftboundaryoftherectangleareinclusive,whiletherightandbottomboundariesarenot.
4、RotatedRect(旋转矩阵)
RotatedRectrRect=RotatedRect(Point2f(200,200),Size2f(200,100),60);
Point2fvertices[4];
rRect.points(vertices);
Rectbrect=rRect.boundingRect();
可以使用points函数返回它的4个顶点,使用boundingRect求出它的外接矩形(非旋转)
5、Matx
用来记录一些小的矩形,这些矩形在编译前大小就固定了。
6、Vec
元素较少的向量
8、Scalar_
用Vec<tp,4>派生下来的,也就是说,它是一个4元组。
7、Mat
不仅可以把它当做一个储存图像的数据结构,还可以储存二维矩阵,也可以储存高维矩阵。在2.0以上的版本中,使用Mat类来储存一幅图像。数据存在data指针所指向的地址中的。
intmain(void)
{
Matimg1=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)点的灰度值
Matimg2=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分量
return0;
}
因为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_<>模版类
或者,旧版:CvPointCvPoint2D32f
三维:typedefPoint3_<int>Point3i;
typedefPoint3_<float>Point3f;
typedefPoint3_<double>Point3d;
点只可以进行加减和比较,不能进行乘除运算。
2、Size_
typedefSize_<int>Size2i;
typedefSize2iSize;
typedefSize_<float>Size2f;
用于定义一个长为x,宽为y的图形或者矩形
3、Rect_
typedefRect_<int>Rect;
(shiftingarectanglebyacertainoffset偏移)
(expandingorshrinkingarectanglebyacertainamount)
rect=rect1&rect2(rectangleintersection)
rect=rect1|rect2(minimumarearectanglecontainrect2andrect3)
Coordinatesofthetop-leftcorner.ThisisadefaultinterpretationofRect_::xandRect_::yinOpenCV.
OpenCVtypicallyassumesthatthetopandleftboundaryoftherectangleareinclusive,whiletherightandbottomboundariesarenot.
4、RotatedRect(旋转矩阵)
RotatedRectrRect=RotatedRect(Point2f(200,200),Size2f(200,100),60);
Point2fvertices[4];
rRect.points(vertices);
Rectbrect=rRect.boundingRect();
可以使用points函数返回它的4个顶点,使用boundingRect求出它的外接矩形(非旋转)
5、Matx
用来记录一些小的矩形,这些矩形在编译前大小就固定了。
template<typename_Tp,intm,intn>classMatx{...};
typedefMatx<float,1,2>Matx12f;
typedefMatx<double,1,2>Matx12d;
...
typedefMatx<float,1,6>Matx16f;
typedefMatx<double,1,6>Matx16d;
typedefMatx<float,2,1>Matx21f;
typedefMatx<double,2,1>Matx21d;
...
typedefMatx<float,6,1>Matx61f;
typedefMatx<double,6,1>Matx61d;
typedefMatx<float,2,2>Matx22f;
typedefMatx<double,2,2>Matx22d;
...
typedefMatx<float,6,6>Matx66f;
typedefMatx<double,6,6>Matx66d;
例:Matx33fm(1,2,3,
4,5,6,
7,8,9);
cout<<sum(Mat(m*m.t()))<<endl;
6、Vec
元素较少的向量
template<typename_Tp,intn>classVec:publicMatx<_Tp,n,1>{...};
typedefVec<uchar,2>Vec2b;
typedefVec<uchar,3>Vec3b;
typedefVec<uchar,4>Vec4b;
typedefVec<short,2>Vec2s;
typedefVec<short,3>Vec3s;
typedefVec<short,4>Vec4s;
typedefVec<int,2>Vec2i;
typedefVec<int,3>Vec3i;
typedefVec<int,4>Vec4i;
typedefVec<float,2>Vec2f;
typedefVec<float,3>Vec3f;
typedefVec<float,4>Vec4f;
typedefVec<float,6>Vec6f;
typedefVec<double,2>Vec2d;
typedefVec<double,3>Vec3d;
typedefVec<double,4>Vec4d;
typedefVec<double,6>Vec6d;
8、Scalar_
用Vec<tp,4>派生下来的,也就是说,它是一个4元组。
template<typename_Tp>classScalar_:publicVec<_Tp,4>{...};
typedefScalar_<double>Scalar;
7、Mat
不仅可以把它当做一个储存图像的数据结构,还可以储存二维矩阵,也可以储存高维矩阵。在2.0以上的版本中,使用Mat类来储存一幅图像。数据存在data指针所指向的地址中的。
intmain(void)
{
Matimg1=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)点的灰度值
Matimg2=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分量
return0;
}
因为8bit图像对应的像素值为0~255,所以opencv使用了uchar类型,这样非常节省空间;但是如果想看到具体的像素值,那么得把他转化为int。
我们看到,使用at函数和直接求出地址然后对地直接引得到的像素值是相同的。at操作是一个模板函数,所以对于灰度图像,返回的直接就是对应的像素值;而对于彩色图像,返回的是一个3元组Vec3b。这个结构是3个uchar连续的放在一起的。所以对于彩色图像,直接使用公式获得的是B分量,如果想获得其他分量,那么得在原始的地址上加上一个sizeof(uchar)。
相关文章推荐
- OpenCV 2.4.X最常用的数据类型
- 常用的Opencv的数据类型
- Opencv中的Mat类型常用函数数据
- OpenCV中数据类型和常用数据类型对应关系
- opencv常用数据类型的转换(个人整理)
- opencv 中常用的数据类型
- SQL Server 常用的数据类型
- 数据库常用数据类型
- VC常用数据类型的使用
- opencv里常用的访问图像像素数据方法
- VC常用数据类型使用转换详解
- OpenCv中矩阵的数据类型
- Python学习之路【第二篇】-pyc简介、Python常用的数据类型及其用法和常用运算符
- MySQL(六)常用语法和数据类型
- VC常用数据类型使用转换详解
- Oracle常用数据类型和完整性约束
- Java常用数据类型转换(持续更新)
- Redis 学习笔记--数据类型常用命令
- C#常用数据类型汇总
- Mysql常用数据类型详细说明及实例说明(学习笔记一)