c++ - 如何在 opencv 中访问 Mat 的第 n 个 channel ?

标签 c++ opencv channel

我知道如何访问三个 channel cv::Mat使用 Vec3b .但现在我有一个 n channel cv::Matn不是常数(使用 cv::Vec<uchar, n> )。我如何访问 cv::Mat现在 channel ?

最佳答案

假设 n = 10,我们想要访问像素 (i, j)4th channel 。这是一个简单的例子:

typedef cv::Vec<uchar, 10> Vec10b;

// ....

// Create the mat
cv::Mat_<Vec10b> some_mat;

// Access 4th channel
uchar value = some_mat.at<Vec10b>(i,j)(4); 

// or 
uchar value = some_mat.at<Vec10b>(i,j)[4];

希望对您有所帮助。请注意,您可以省略 typedef 行,我只是认为这样更容易。

关于c++ - 如何在 opencv 中访问 Mat 的第 n 个 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45349927/

相关文章:

select - 选择中的 Golang channel 未接收

c++ - libstdc++ 的 max_align_t 定义中的属性

关于假定未声明的函数的 C++ 编译器错误

python - 如何使用opencv python将RGB颜色范围更改为红色

python-2.7 - Python-OpenCV cv2 OpenCV错误: Assertion failed (scn == 3 || scn == 4) in unknown function,文件..\..\..\modules\imgproc\src\color.cpp

audio - 使用音频工具 sox,如何确定立体声录音是否实际上是单声道?

c++ - 自定义列表类的初始值设定项列表构造函数

c++ - 如何将 float 作为参数传递(内联汇编)?

c++ - 在 visual studio 中使用 calcOpticalFlowPyrLK() 函数

haskell - 如何使用 Haskell 模拟 Go 的 channel ?