OpenCV (2) OpenCV Data Types

1. Data Types in OpenCV:

There are three kinds of data types in OpenCV:

  1. Basic data types
  2. Helper objects
  3. Large array types

2. Basic data types:

The basic data types are those that are assembled directly from C++ primitives (int, float, etc.). In another word, basic data types are the templates of C++ primitives.

Some examples of basic data types:

(1) cv::Vec{N}{b,w,s,i,f,d}

typedef Vec<int, 2> Vec2i; // a mathematical vector with 2 ints
typedef Vec<double, 4> Vec4d; // a mathematical vector with 4 doubles

The dimension of basic data types are fixed in declaration.

(2) cv::Matx{N}{N}{b,w,s,i,f,d}

typedef Matx<float, 1, 2> Matx12f;
typedef Matx<double, 1, 2> Matx12d;

(3) cv::Point{N}{b,w,s,i,f,d}

typedef Point_ Point2f;
typedef Point_ Point2d;

3. Helper objects:

These objects represent more abstract concepts such as the garbage-collecting pointer class, range objects used for slicing, and abstractions such as termination criteria.

(1) cv::TermCriteria sets the terminal conditions:

cv::TermCriteria::MAX_ITER

(2) cv::Ptr is a smart ptr to objecs:

cv::Ptr p

4. Large array types:

These are objects whose fundamental purpose is to contain arrays or other assemblies of primitives or, more often, the basic data types (e.g. cv::Mat represent arbitrary-dimensional arrays containing arbitrary basic elements).

cv::Mat m;

// set the matrix to 3 rows and 10 columns (3-channel 32-bit floats)
m.create(3, 10, CV_32FC3);

// set the values in the 1st channel to 1.0, the 2nd to 0.0, and the 3rd to 1.0
m.setTo( cv::Scalar(1.0f, 0.0f, 1.0f));


Reference

[1] Adrian Kaehler, Gary Bradski, Learning OpenCV 3 , O'Reilly Media (2017)

留言

熱門文章