我正在学习如何使用OpenCV的新C++界面。
如何访问多通道矩阵的元素?例如:
Mat myMat(size(3, 3), CV_32FC2);
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
//myMat_at_(i,j) = (i,j);
}
}
做这件事最简单的方法是什么?有点像旧界面的cvSet2D。
最有效的方法是什么?类似于在旧接口中使用直接指针。
发布于 2010-06-10 03:50:58
Vic您必须使用Vec3b而不是Vec3i:
for (int i=0; i<image.rows; i++)
{
for (int j=0; j<image.cols; j++)
{
if (someArray[i][j] == 0)
{
image.at<Vec3b>(i,j)[0] = 0;
image.at<Vec3b>(i,j)[1] = 0;
image.at<Vec3b>(i,j)[2] = 0;
}
}
}
发布于 2012-01-27 20:23:05
您可以直接访问底层数据数组:
Mat myMat(size(3, 3), CV_32FC2);
myMat.ptr<float>(y)[2*x]; // first channel
myMat.ptr<float>(y)[2*x+1]; // second channel
发布于 2014-10-13 09:50:53
它取决于您正在使用的Mat的数据类型,如果它是数字类型,如CV_32FC1,您可以使用:
myMat.at<float>(i, j)
如果它是uchar类型,则可以使用
(symb.at<Vec3b>(i, j)).val[k]
其中k是通道,灰度图像为0,彩色图像为3
https://stackoverflow.com/questions/1824787
复制相似问题