E_l*_*ner 8 iteration opencv iterator matrix
我是OpenCV的新手.我试图使用迭代器而不是"for"循环,这对我的情况来说太慢了.我试过这样的代码:
MatIterator_<uchar> it, end;
for( it = I.begin<uchar>(), end = I.end<uchar>(); it != end; ++it)
{
//some codes here
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何转换for循环,如:
for ( int i = 0; i < 500; i ++ )
{
exampleMat.at<int>(i) = srcMat>.at<int>( i +2, i + 3 )
}
Run Code Online (Sandbox Code Playgroud)
进入迭代器模式?也就是说,如何以迭代器形式执行"i + 2,i + 3"?我只能通过"*it"获得相应的值,但我无法得到它的计数数字.提前谢谢了.
Mar*_*ett 21
这不是for循环,exampleMat.at<int>(i)它是做范围检查的慢.
要有效地遍历所有像素,您可以使用.ptr()获取指向每行开头数据的指针.
for(int row = 0; row < img.rows; ++row) {
uchar* p = img.ptr(row);
for(int col = 0; col < img.cols; ++col) {
*p++ //points to each pixel value in turn assuming a CV_8UC1 greyscale image
}
or
for(int col = 0; col < img.cols*3; ++col) {
*p++ //points to each pixel B,G,R value in turn assuming a CV_8UC3 color image
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22906 次 |
| 最近记录: |