简体   繁体   中英

What is Vec4b, MatObj.ptr in opencv ?

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, eg 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, eg using big index in rv[index] (for index >= mMat.cols ), you will get data from other rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM