opencv Basic Structures Vec


Vec (Vector) is a template class for numerical values. Unlike c++ vectors, it generally stores short vectors (only a few elements).

The way a Vec is defined is as follows:

 typedef Vec<type, channels> Vec< channels>< one char for the type>;

where type is one of uchar, short, int, float, double and the characters for each type are b, s, i, f, d, respectively.

For example, Vec3b indicates an unsigned char vector of 3 channels. Each index in an RGB image is in this format.

Mat rgb = imread('path/to/file', CV_LOAD_IMAGE_COLOR);  
cout <<<Vec3b>(0,0); //The output is [r g b] values as ASCII character.
// To print integer values of RED value
cout << (int)<Vec3b>(0,0)[0]; //The output will be an integer in [0, 255].

In Vec class the following operators are defined

v1 = v2 + v3
v1 = v2 - v3
v1 = v2 * scale
v1 = scale * v2
v1 = -v2
v1 += v2 and other augmenting operations
v1 == v2, v1 != v2

For more information, see the link