简体   繁体   English

什么是opencv中的Vec4b,MatObj.ptr?

[英]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. 我不明白Vec4b是什么意思。 I know about Vec4i which means line segment coordinates. 我知道Vec4i的意思是线段坐标。 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] [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. 例如rv [4],rv [5]等。

So I really dont't get what Vec4b does. 所以我真的不明白Vec4b的作用。 Also the mMat.ptr. 也是mMat.ptr。 I Could not find good online sources about Vec4b and Mat.ptr. 我找不到有关Vec4b和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. 所以我真的不明白Vec4b的作用。

As can be seen from OpenCV's API , it's defined as follows: OpenCV的API可以看出,其定义如下:

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. 换句话说,它包含4个ucharunsigned char )值。 The Vec class is commonly used to describe pixel types of multi-channel arrays, eg CV_RGBA . Vec类通常用于描述多通道阵列的像素类型,例如CV_RGBA

Also the mMat.ptr. 也是mMat.ptr。

Mat::ptr() returns a pointer to the specified matrix row. Mat::ptr()返回一个指向指定矩阵行的指针。


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 . 之后, rv将是类型为Vec4b指针,该指针指向Mat mMat51行。


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. 编辑:由于所有Mat的数据都是连续的,因此在当前行的所有像素之后,例如在rv[index]使用大索引(对于index >= mMat.cols ),您将从其他行中获取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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