[英]Accessing all pixels in cv::Mat
Is this the correct way of accessing all pixels in cv::Mat
: 这是访问
cv::Mat
所有像素的正确方法:
for( row = 0; row < mat.rows; ++row)
{
for ( col = 0; col < mat.cols; ++col)
{
}
}
Or is there a formula method similar to this formula for an IplImage *
: 还是有一个类似于
IplImage *
的公式方法:
temp_ptr = &((uchar*)(img->imageData + (img->widthStep*pt.x)))[pt.y*3];
In the best case, where all the pixels are stored contiguously you should be able to do: 在最好的情况下,所有像素都连续存储,您应该能够:
uchar* pixel = mat.data;
for(int i = 0; i < mat.rows * mat.cols; ++i)
{
// access pixel[0],pixel[1],pixel[2] here
pixel += 3; // move to next pixel
}
To be a bit more generic, but still fast, have a look at the sample code mentioned with Mat::isContinuous()
. 为了更通用一些,但仍然较快,请看一下
Mat::isContinuous()
提到的示例代码 。 The general formula for calculating the address of an element can be seen here (Reproduced below). 可以在此处看到用于计算元素地址的通用公式(转载如下)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.