opencv基本数据结构

opencv基本数据结构,第1张

  一、opencv简介

  OpenC++V是一个基于BSD许可(开源)发行的跨平台计算机视觉库,可以运行在Linux、Windows、Android和Mac OS *** 作系统上。它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python、Ruby、MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算法。

  二、opencv优势

  1.研究代码(慢,不稳定,独立并与其他库不兼容)

  2.耗费很高的商业化工具(比如Halcon, MATLAB+Simulink)

  3.依赖硬件的一些特别的解决方案(比如视频监控,制造控制系统,医疗设备)这是如今的现状。而标准的API将简化计算机视觉程序和解决方案的开发。

  OpenCV致力于成为这样的标准API。OpenCV致力于真实世界的实时应用,通过优化的C代码的编写对其OpenCV与其它视觉函数库性能对比执行速度带来了可观的提升,并且可以通过购买Intel的IPP高性能多媒体函数库(Integrated Performance PrimiTIves)得到更快的处理速度。

  三、opencv应用

  1、人机互动

  2、物体识别

  3、图像分割

  4、人脸识别

  5、动作识别

  6、运动跟踪

  7、机器人

  8、运动分析

  9、机器视觉

  10、结构分析

  11、汽车安全驾驶

  四、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));

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/dianzi/2717622.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-08-17
下一篇 2022-08-17

发表评论

登录后才能评论

评论列表(0条)

保存