Fixed vector template class cv::Vec<> in OpenCV

Fixed vector template class cv::Vec<> in OpenCV

1、vector

Vector (vector) is a sequential container that encapsulates a dynamic size array and can store various types of objects. You can simply think of vector as a dynamic array that can store any type.

usage:

#include <vector>
using namespace std;

vector<int> v;  //声明一个 int 向量 v,未分配大小,可以动态的向里面添加删除

2、thing<>

Vec3b color;  //变量 color 是一个长度为 3 的 uchar 数组,用于描述 RGB 颜色

Fixed vector alias naming rules: cv::Vec{2,3,4,6}{b, s ,w , i, f, d}

{2,3,4,6} represent the length of the vector;
{b, s ,w , i, f, d} represent the data type in the vector;

b:unsigned char ; s:short int
w:unsigned short; i:int
f:float; d:double

3. Access
the member function of pixel cv::mat: .at(int y, int x), which can be used to access the element coordinates corresponding to (x, y) in the image.
When in use, the data type of the image must be known during compilation, because cv::mat can store elements of any data type, so the implementation of the at method is implemented with a template function.

Img.at<uchar>(14,25) = 30;			//img的数据类型为 unsigned char型灰度图(单通道),要对坐标为(14,25)的像素重新赋值为30

// 若为彩色图,将坐标(14,25)的像素赋值为30,需要对这个像素三个通道的每个对应元素赋值
Opencv中图像三原色在内存中的排列顺序为BGR

img.at<Vec3b>(14,25) [0]= 25;//B  
img.at< Vec3b >(14,25) [1]= 25;//G  
img.at< Vec3b >(14,25 [2]= 25;//R  

Guess you like

Origin blog.csdn.net/qq_43508270/article/details/126083121