Вопрос

My question is based on the following code.

Vec4b *rv = mMat.ptr<Vec4b> (50);

I don't understand what Vec4b means. I know about Vec4i which means line segment coordinates. So similarly I tried to find what it contains. The below code

std::cout<<rv[1]<<std::endl;

gave an output:

[8, 7, 10, 10]

I dont know what those parameters mean. Surprisingly it showed outputs for parameters greater than four. Eg., rv[4],rv[5] and so on.

So I really dont't get what Vec4b does. Also the mMat.ptr. I Could not find good online sources about Vec4b and Mat.ptr.

Any clarification about what the first code does would really be helpful in enlightening my mind.

Это было полезно?

Решение

So I really dont't get what Vec4b does.

As can be seen from OpenCV's API, it's defined as follows:

template<typename _Tp, int n> class Vec : public Matx<_Tp, n, 1> {...};
...
typedef Vec<uchar, 4> Vec4b;

In other words, it contains 4 uchar (unsigned char) values. The Vec class is commonly used to describe pixel types of multi-channel arrays, e.g. CV_RGBA.

Also the mMat.ptr.

Mat::ptr() returns a pointer to the specified matrix row.


So, for your code,

Vec4b *rv = mMat.ptr<Vec4b> (50);

After this, rv will be a pointer with type Vec4b that pointers to the 51-th row of Mat mMat.


Edit: As all Mat's data are continuous, after all pixels of current row, e.g. using big index in rv[index] (for index >= mMat.cols), you will get data from other rows.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top