Access pixel value of matrix A

How to get the value of a pixel in OpenCV without knowing the channel depth? For example in the following example I have to know beforehand that the matrix a has three channels.

Mat a;
Vec3b pixel=a.at<Vec3b>(0,0);

How can I write a function that can read both 1 channel matrix and 3 channel matrix? I'm planning to hold feature vectors in matrix, so it can also be an arbitrary constant number.


Take a look at the documentation for at. If you want to select a channel from a 3 channel floating point image you'd do it as such:

float pixel = img.at<float>(i,j,k); //i - row, j - col, k - channel

You can check number of channels using

int nChannels = img.channels();
链接地址: http://www.djcxy.com/p/67010.html

上一篇: 访问Mat时出错结果

下一篇: 访问矩阵A的像素值