DataType

A primitive OpenCV data type is one of unsigned char, bool,signed char, unsigned short, signed short, int, float, double, or a tuple of values of one of these types, where all the values in the tuple have the same type.

类型的命名格式:

CV_<bit-depth>{U|S|F}C(<number_of_channels>)

A universal OpenCV structure that is able to store a single instance of such a primitive data type is Vec. Multiple instances of such a type can be stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to store Vec instances.

The DataType class is basically used to provide a description of such primitive data types without adding any fields or methods to the corresponding classes 。 The main purpose of this class is to convert compilation-time type information to an OpenCV-compatible data type identifier

// allocates a 30x40 floating-point matrix
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 */
cout << B.depth() << ", " << B.channels() << endl;

 

Point_

An instance of the class is interchangeable with C structures, CvPoint and CvPoint2D32f . There is also a cast operator to convert point coordinates to the specified type. The conversion from floating-point coordinates to integer coordinates is done by rounding.

For your convenience, the following type aliases are defined:

typedef Point_<int> Point2i;
typedef Point2i Point;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;

Point2f a(0.3f, 0.f), b(0.f, 0.4f);
Point pt = (a + b)*10.f;
cout << pt.x << ", " << pt.y << endl;

Point3_

Template class for 3D points specified by its coordinates , and . An instance of the class is interchangeable with the C structure CvPoint2D32f

typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;

Size_

Template class for specifying the size of an image or rectangle. The class includes two members called width andheight. The structure can be converted to and from the old OpenCV structures CvSize and CvSize2D32f .

typedef Size_<int> Size2i;
typedef Size2i Size;
typedef Size_<float> Size2f;

 

Rect_

Template class for 2D rectangles, described by the following parameters:

  • Coordinates of the top-left corner. This is a default interpretation of Rect_::x and Rect_::y in OpenCV. Though, in your algorithms you may count x and y from the bottom-left corner.
  • Rectangle width and height.

In addition to the class members, the following operations on rectangles are implemented:

  • (shifting a rectangle by a certain offset)
  • (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 (minimum area rectangle containing rect2 and rect3 )
  • rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
  • rect == rect1, rect != rect1 (rectangle comparison)

 

RotatedRect

Each rectangle is specified by the center point (mass center), length of each side (represented by cv::Size2f structure) and the rotation angle in degrees.

Mat image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30); Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
line(image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0)); Rect brect = rRect.boundingRect();
rectangle(image, brect, Scalar(255,0,0)); imshow("rectangles", image);
waitKey(0);

 

TermCriteria

The class defining termination criteria for iterative algorithms. You can initialize it by default constructor and then override any parameters, or the structure may be fully initialized using the advanced variant of the constructor.

终止条件  ——  迭代次数,阈值

TermCriteria::TermCriteria(int type, int maxCount, double epsilon)

Parameters:

  • type – The type of termination criteria: TermCriteria::COUNT, TermCriteria::EPS orTermCriteria::COUNT + TermCriteria::EPS.
  • maxCount – The maximum number of iterations or elements to compute.
  • epsilon – The desired accuracy or change in parameters at which the iterative algorithm stops.
  • criteria – Termination criteria in the deprecated CvTermCriteria format.

 

Matx

If you need a more flexible type, use Mat . The elements of the matrix M are accessible using the M(i,j) notation. Most of the common matrix operations (see also Matrix Expressions ) are available. To do an operation on Matx that is not implemented, you can easily convert the matrix to Mat and backwards.

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;

 

Vec

Template class for short numerical vectors, a partial case of 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;

It is possible to convert Vec<T,2> to/from Point_, Vec<T,3> to/from Point3_ , and Vec<T,4> to CvScalar or Scalar_. Useoperator[] to access the elements of Vec.

All the expected vector operations are also implemented:

  • v1 = v2 + v3
  • v1 = v2 - v3
  • v1 = v2 * scale
  • v1 = scale * v2
  • v1 = -v2
  • v1 += v2 and other augmenting operations
  • v1 == v2, v1 != v2
  • norm(v1) (euclidean norm)

 

Scalar_

Template class for a 4-element vector derived from Vec.

Being derived from Vec<_Tp, 4> , Scalar_ and Scalar can be used just as typical 4-element vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in OpenCV to pass pixel values.

四元组

Range

Template class specifying a continuous subsequence (slice) of a sequence.

序列片段

The class is used to specify a row or a column span in a matrix ( Mat ) and for many other purposes. Range(a,b) is basically the same as a:b in Matlab 。Such a half-opened interval is usually denoted as 区间左闭右开

The static method Range::all() returns a special variable that means “the whole sequence” or “the whole range”, just like ” :

Ptr

The Ptr<_Tp> class is a template class that wraps pointers of the corresponding type.

This class provides the following options:

The Ptr class treats the wrapped object as a black box. The reference counter is allocated and managed separately. The only thing the pointer class needs to know about the object is how to deallocate it. This knowledge is encapsulated in the Ptr::delete_obj() method that is called when the reference counter becomes 0. If the object is a C++ class instance, no additional coding is needed, because the default implementation of this method calls delete obj;. However, if the object is deallocated in a different way, the specialized method should be created. For example, if you want to wrap FILE, the delete_obj may be implemented as follows:

template<> inline void Ptr<FILE>::delete_obj()
{
fclose(obj); // no need to clear the pointer afterwards,
// it is done externally.
}
... // now use it:
Ptr<FILE> f(fopen("myfile.txt", "r"));
if(f.empty())
throw ...;
fprintf(f, ....);
...
// the file will be closed automatically by the Ptr<FILE> destructor.

OPENCV(2) —— Basic Structures(一)的更多相关文章

  1. OPENCV(2) —— Basic Structures(二)

    Mat OpenCV C++ n-dimensional dense array class The class Mat represents an n-dimensional dense numer ...

  2. OpenCV中的结构体、类与Emgu.CV的对应表

    OpenCv中的 C 结构 OpenCV中的 C++ 封装 Emgu.CV中的 C# 封装 OpenCV 和 Emgu.CV 中的结构罗列 谢谢阅读,有误希望指正 原文地址 Basic Structu ...

  3. 【转】Installing OpenCV on Debian Linux

    In this post I will describe the process of installing OpenCV(both versions 2.4.2 and 2.4.3) on Debi ...

  4. 剑指offer:大恒图像

    大恒图像:成立于1991年,专注于视觉部件.视觉系统及互联网医疗相关产品研发.生产和营销的高科技企业. 旗下产品信息: 1.图像采集卡 摄像机等输入的模拟图像信号经过A/D转换,或将数字摄像机的输出信 ...

  5. C/C++ 开源库及示例代码

    C/C++ 开源库及示例代码 Table of Contents 说明 1 综合性的库 2 数据结构 & 算法 2.1 容器 2.1.1 标准容器 2.1.2 Lockfree 的容器 2.1 ...

  6. Inside of Jemalloc

    INSIDE OF JEMALLOCThe Algorithm and Implementation of Jemalloc author: vector03mail:   mmzsmm@163.co ...

  7. net programming guid

    Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...

  8. 通过一篇YAML来学习YAML

    yaml 兼容 json,至今已发展至 1.2版.支持N多种编程语言.官网:http://www.yaml.org/ 格式在线校验:http://nodeca.github.io/js-yaml/ 下 ...

  9. ARTIFICIAL INTELLIGENCE FOR GAMES (Ian Millington / John Funge 著)

    相关网站:http://www.ai4g.com PART I AI AND GAMESCHAPTER1 INTRODUCTIONCHAPTER2 GAME AIPART II TECHNIQUESC ...

随机推荐

  1. bytes、str与unicode

    1.Python3字符序列的类型 bytes -> 原始的8位值(既字节) str -> Unicode字符 2.Python2字符序列的类型 str -> 原始的8位值(既字节) ...

  2. 紫书 习题11-11 UVa 1644 (并查集)

    这道题感觉思路非常巧妙, 我是看了别人的博客才想明白的. 这里用到了并查集, 以根节点为中心城市, 然后把边从大到小排序, 每次的当前的边即为容量, 因为是目前的最小值, 然后去算总的容量, 每次选容 ...

  3. 题解 UVA12206 【Stammering Aliens】

    终于A了这道题啊(坑啊) 教练说:这道题不能用map吧,复杂度不一个O(nlogn)吗 于是我就一直想不出来,然后看题解代码,一看就是map... 所以我就在想,那复杂度是不是也不是O(nlogn)呢 ...

  4. jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法

    jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法 工作中用到一个具有多选功能的easyui-datagrid在处理cell的点击事件时,不同 ...

  5. Android4.2.2下Stagefright下OMX编解码器组件的控制流

    本文均属自己阅读源代码的点滴总结.转账请注明出处谢谢. 欢迎和大家交流. qq:1037701636 email:gzzaigcn2012@gmail.com Android源代码版本号Version ...

  6. Introduction to MongoDB

    https://docs.mongodb.com/getting-started/csharp/introduction/ MongoDB is an open-source document dat ...

  7. m_Orchestrate learning system---二十三、如何搜索概念图插件

    m_Orchestrate learning system---二十三.如何搜索概念图插件 一.总结 一句话总结:要在百度你们搜索前端组件,前端组件  概念图工具,js概念图工具等等这些 用的话用go ...

  8. rest_framework 分页三种

    .分页 a. 分页 看第n页 每页显示n条数据: b. 分页 在某个位置 向后查看多少条数据 c. 加密分页 上一页和下一页 本质:查看 记住页码id的最大值和最小值 通过其来准确扫描 过去的话 会从 ...

  9. k-meas非监督聚类分析

    实验名称: k-meas非监督聚类分析   一.实验目的和要求 目的: 加深对非监督学习的理解和认识 掌握聚类方法K-Means算法的设计方法   要求:     根据聚类数据,采用k-Means聚类 ...

  10. Android中的Junit测试

    在开发中Junit测试可以很方便的帮助开者尽可能早的发现并处理问题,而且使用也非常简单,只需要导入Junit测试相关的jar包并创建测试类,就可以对业务功能进行测试,而不用为了测试在代码中添加输出语句 ...