其他分享
首页 > 其他分享> > Opencv的Vec类使用说明(图像像素.at方法访问)

Opencv的Vec类使用说明(图像像素.at方法访问)

作者:互联网

Vec的类型

typedef Vec<uchar, 2> Vec2b;
typedef Vec<uchar, 3> Vec3b;
typedef Vec<uchar, 4> Vec4b;

typedef Vec<short, 2> Vec2s;
typedef Vec<short, 3> Vec3s;
typedef Vec<short, 4> Vec4s;

typedef Vec<ushort, 2> Vec2w;
typedef Vec<ushort, 3> Vec3w;
typedef Vec<ushort, 4> Vec4w;

typedef Vec<int, 2> Vec2i;
typedef Vec<int, 3> Vec3i;
typedef Vec<int, 4> Vec4i;
typedef Vec<int, 6> Vec6i;
typedef Vec<int, 8> Vec8i;

typedef Vec<float, 2> Vec2f;
typedef Vec<float, 3> Vec3f;
typedef Vec<float, 4> Vec4f;
typedef Vec<float, 6> Vec6f;

typedef Vec<double, 2> Vec2d;
typedef Vec<double, 3> Vec3d;
typedef Vec<double, 4> Vec4d;
typedef Vec<double, 6> Vec6d;

通过上面可以看到Vec主要有uchar、short、ushort、int、float、double类型,然后维度有2,3,4,5,6。五种不同类型的维度。

下面对几种常用类型的说明:Vec3b、Vec3f、Vec3d

Vec3b主要用来访问三通道的0-255的灰度图,如:

int b = srcImage.at<Vec3b>(row, col)[0];  //获取像素值b 
int g = srcImage.at<Vec3b>(row, col)[1];  //获取像素值g

int r = srcImage.at<Vec3b>(row, col)[2];  //获取像素值r

Vec3f主要用来访问三通道的0-255实数类型的灰度图,如:

tempImg.at<Vec3f>(j, k)[0] = xResolution*j;
tempImg.at<Vec3f>(j, k)[1] = yResolution*i;
tempImg.at<Vec3f>(j, k)[2] = src.at<float>(j, k);

同理0-62235的16位的三通道灰度图像由Vec<ushort, 3> Vec3w类型进行访问。

上述主要对图像访问方式总结。

Vec类型的方法

这一部分主要对matx.hpp文件进行说明,以向量的角度对它的方法进行说明

1.共轭向量

Vec3f v0(1, 0, 1), v1(3, 2, 1), v2, v3;

v2 = v0.conj(v1);

2.点乘

v2 = v0.dot(v1);

3.v1、v2叉乘

Vec3f vn = v0.cross(v1);

4.转为对角矩阵

Mat m=v1.diag();

标签:v0,typedef,v1,int,像素,Vec3f,Opencv,Vec
来源: https://blog.csdn.net/beyond951/article/details/122249543