opencv基本的数据结构(转)
DataType : 将C++数据类型转换为对应的opencv数据类型
enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, CV_64F=6 };
// allocates a 30x40 floating-point matrix // CV_32F
Mat A(30, 40, DataType<float>::type);
Mat B = Mat_<std::complex<double> >(3, 3);
// the statement below will print 6, 2 /*, that is depth == CV_64F, channels == 2*/ CV_64FC2
cout << B.depth() << ", " << B.channels() << endl;
--------------------------------------------------------------------------------
Point_ 二维点坐标(x,y)
typedef Point_<int> Point2i;
typedef Point2i Point;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
--------------------------------------------------------------------------------
Point3_ 3维点坐标(x,y,z)
typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;
--------------------------------------------------------------------------------
Size_ 尺寸(width, height)
typedef Size_<int> Size2i;
typedef Size2i Size;
typedef Size_<float> Size2f;
--------------------------------------------------------------------------------
Rect_ 矩形区域(x,y,width,height) ,(x,y)左上角坐标, 范围[x, x + width), [y, y + height)
rect = rect ± point //矩形偏移(shifting a rectangle by a certain offset)
rect = rect ± size //改变大小(expanding or shrinking a rectangle by a certain amount)
rect += point, rect -= point, rect += size, rect -= size //(augmenting operations)
rect = rect1 & rect2 //矩形交集(rectangle intersection)
rect = rect1 | rect2 //包含r1r2的最小矩形(minimum area rectangle containing rect2 and rect3 )
rect &= rect1, rect |= rect1 //(and the corresponding augmenting operations)
rect == rect1, rect != rect1 //(rectangle comparison)
--------------------------------------------------------------------------------
RotatedRect 旋转矩形
RotatedRect::RotatedRect(const Point2f& center, const Size2f& size, float angle)// 中心点(不是左上角坐标),尺寸,旋转角度
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);
--------------------------------------------------------------------------------
Matx 小矩阵
template<typename_Tp, int m, int n> class Matx {...};
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;//Matx转化为Mat
--------------------------------------------------------------------------------
Vec 短向量,基于Matx
template<typename_Tp, int n> class Vec : 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;
--------------------------------------------------------------------------------
Scalar_ 四维向量
template<typename_Tp> class Scalar_: public Vec<_Tp, 4> { ... };
typedef Scalar_<double> Scalar;
--------------------------------------------------------------------------------
Range 范围,(start, end)
Mat m(300,300,CV32F);
Mat part = m(Range::all(), Range(20, 200)); // 相当于matlab的m(:, 20 : 199)对于自定义的函数,可以用如下方法来支持Range
void my_function(..., const Range& r, ....)
{
if(r == Range::all()) {
// process all the data, 使用全部数据
}
else {
// process [r.start, r.end),根据r中定义, 处理数据 start : end - 1
}
}
--------------------------------------------------------------------------------
Mat 矩阵结构
•M.data 数据区域的指针
•M.dims 矩阵维度
•M.sizes 维度
•M.elemSize() 每个元素占的字节空间大小,与元素类型相关,如CV_8U
•M.step[] 用来计算元素地址, M.step[i] 表示所有比i大的维度所占空间大小
M.step[i] >= M.step[i+1]*M.sizes[i+1]; //这里大于是因为数据空间可能有空白•2-dimensional matrices are stored row-by-row
•3-dimensional matrices are stored plane-by-plane
addr(M(i(0),...,i(M.dims−1))) = M.data + M.step[0] ∗ i(0)+ M.step[1] ∗ i(1)+ ... + M.step[M.dims − 1] ∗ i(M.dims−1)创建数组:
// make a 7x7 complex matrix filled with 1+3j.
Mat M(7,7,CV_32FC2,Scalar(1,3));
// and now turn M to a 100x60 15-channel 8-bit matrix.
// The old content will be deallocated
M.create(100,60,CV_8UC(15));
// create a 100x100x100 8-bit array
int sz[] = {100, 100, 100};
Mat bigCube(3, sz, CV_8U, Scalar::all(0));创建特殊矩阵:
•diag
•ones
•zeros
•eye
属性相关:
•rows
•cols
•begin
•end
•at
•size
•depth
•type
•elemSize
•total
矩阵操作:
•t
•inv
•mul
•cross
•dot
•reshape
•resize
•reserve
•push_back
•pop_back
赋值相关:
•clone
•copyTo
•convertTo
•assignTo
•setTo
--------------------------------------------------------------------------------
InputArray
OutputArray
//Do not explicitly create InputArray, OutputArray instancesvoid myAffineTransform(InputArray_src, OutputArray_dst, InputArray_m)
{
// get Mat headers for input arrays. This is O(1) operation,
// unless_src and/or_m are matrix expressions.
Mat src =_src.getMat(), m =_m.getMat();
CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) );
// [re]create the output array so that it has the proper size and type.
// In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize.
_dst.create(src.size(), src.type());
Mat dst =_dst.getMat();
for( int i = 0; i < src.rows; i++ )
for( int j = 0; j < src.cols; j++ )
{
Point2f pt = src.at<Point2f>(i, j);
dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x +
m.at<float>(0, 1)*pt.y +
m.at<float>(0, 2),
m.at<float>(1, 0)*pt.x +
m.at<float>(1, 1)*pt.y +
m.at<float>(1, 2));
}
}
opencv基本的数据结构(转)的更多相关文章
- OpenCV(2)-Mat数据结构及访问Mat中像素
Mat数据结构 一开始OpenCV是基于C语言的,在比较早的教材例如<学习OpenCV>中,讲解的存储图像的数据结构还是IplImage,这样需要手动管理内存.现在存储图像的基本数据结构是 ...
- opencv新版本的数据结构
转自 http://blog.csdn.net/yang_xian521/article/details/7108387 记得我在OpenCV学习笔记(四)——新版本的数据结构core里面讲过新版本的 ...
- opencv的基本数据结构(一)(转)
从2001年以来,opencv的函数库一直是基于C接口构建的,因此在opencv1.0版本中,一般使用IplImage的C结构体在内存中存储图像,因此,我们在很多较经典的书籍或者开源项目中依然可见Ip ...
- opencv的基本数据结构(二)(转)
转自:原文链接,以下代码.图片.内容有点改动,只为转载不降低博客内容的可阅性,版权归原作者所有. OpenCV中强大的Mat类型大家已经比较熟悉了.这里梳理一些在工程中其他经常用到的几种基本数据类型. ...
- OpenCV的基本数据结构
参考:http://www.cnblogs.com/guoqiaojin/p/3176692.html
- Opencv 的数据结构
opencv的基本数据结构 结构 成员 意义 CvPoint int x,y 图像中的点 CvPoint2D32f float x,y 二维空间中的点 CvPoint3D32f float x,y,z ...
- OpenCV学习(2)--基本数据结构
OpenCV的基本数据结构 CvPoint:表示图像中的点 CvPoint2D32f:二维空间中的点 CvPoint3D32f:三维空间中的点 这些都是结构体,并不是C++语言中的类,所以他们的构造函 ...
- opencv 人脸识别
背景知识 OpenCV 是一个开源的计算机视觉和机器学习库.它包含成千上万优化过的算法,为各种计算机视觉应用提供了一个通用工具包.根据这个项目的关于页面,OpenCV 已被广泛运用在各种项目上,从 ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
随机推荐
- Web服务端软件的服务品质概要
软件品质概述 提供同样功能.产品和服务的服务者中, 竞争力来自功能的多样化和服务品质的差异化, 无论是个体.企业还是国家. 这里的服务指功能.产品的实现程度和处理能力,以及研发/客服提供的技术支持程度 ...
- 将HTML5 Canvas的内容保存为图片借助toDataURL实现
将HTML5 Canvas的内容保存为图片主要思想是借助Canvas自己的API - toDataURL()来实现,具体实现如下,感兴趣的朋友可以参考下哈,希望对你有所帮助 <html> ...
- Css Study - 纵向Menu - By html and Css
http://www.wikihow.com/Create-a-Dropdown-Menu-in-HTML-and-CSS HTML <div id="leftmenu"&g ...
- nginx简单的rewrite配置
假设当前已存在location /test/,希望配置一个短连接/ts/与之相同,就需要用到rewrite 直接配置到server段 rewrite ^/ts/(.*) /test/$1; 或者放到l ...
- OpenCV 绘制图像直方图
OpenCV绘制图像直方图,版本2.4.11 直方图可展示图像中的像素分布,是用以表示数字图像中亮度分布的直方图,标绘了图像中每个亮度值的像素数.可以借助观察该直方图了解需要如何调整亮度分布.这种直方 ...
- NRF52832学习笔记
一.打印函数 printf("");用于在调试串口时在电脑端的串口调试工具上打印: 宏定义时每行后面的斜杠,在最后一行不加斜杠.
- 微信小程序-视图
数据绑定 <!--wxml--> <view> {{message}} </view> // page.js Page({ data: { message: 'He ...
- 深入浅出设计模式——命令模式(Command Pattern)
模式动机 在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需在程序运行时指定具体的请求接收者即可,此时,可以使用命令模式来进行设计,使得请 ...
- 基于struts2、spring的应用闲置一段时间后报空指针错(转)
在做struts2.spring网站时,在系统闲置一段时间后,访问页面会出错,第二次再访问就正常了.后来查了后台日志,发现是数据库连接关闭了,导致页面访问出错.页面上报空指针错误,错误没有保留,日志中 ...
- sqlite与android交互 (封装)
学android已经有大概一周时间了吧 ,总感觉自己基础不怎么好,只能通过一点一点积累着敲来巩固平常的知识,有的时候就先不封装的敲一遍,再封装上,有些语句真的记不住,虽然知道他是什么意思,于是乎就反复 ...