好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

opencv像素遍历三种方法.pdf

2页
  • 卖家[上传人]:飞***
  • 文档编号:47694712
  • 上传时间:2018-07-04
  • 文档格式:PDF
  • 文档大小:24.78KB
  • / 2 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • Dd 高效的方法: C 操作符 [ ]最快的是直接用C 风格的内存访问操作符[]来访问:[cpp]view plaincopy1.Mat 5.int channels = I.channels(); 6.int nRows = I.rows ; 7.int nCols = I.cols* channels; 8.if (I.isContinuous()) 9. { 10. nCols *= nRows; 11. nRows = 1; 12. } 13.int i,j; 14. uchar* p; 15.for ( i = 0; i (i); 18.for ( j = 0; j it, end; 11.for ( it = I.begin(), end = I.end(); it != end; ++i t) 12. *it = table[*it]; 13.break ; 14. } 15.case 3: 16. { 17. MatIterator_ it, end; 18.for ( it = I.begin(), end = I.end(); it != end; ++i t) 19. { 20. (*it)[0] = table[(*it)[0]]; 21. (*it)[1] = table[(*it)[1]]; 22. (*it)[2] = table[(*it)[2]]; 23. } 24. } 25. } 26.return I; 27.} 这里我们只定义了一个迭代器,用了一个for 循环,这是因为在OpenCV 里迭代器会访问每一列然后自动跳到下一行,不用管在内存上是否isContinous 。

      另外要注意的是在三通道图像中我们定义的是 格式的迭代器,如果定义成uchar ,则只能访问到B 即蓝色通道的值这种方式虽然安全,但是挺慢的,一会儿就知道了更慢的方法:动态地址计算这种方法在需要连续扫描所有点的应用时并不推荐,因为它更实用与随机访问这种方法最基本的用途是访问任意的某一行某一列:[cpp]view plaincopy1.Mat 5.constint channels = I.channels(); 6.switch(channels) 7. { 8.case 1: 9. { 10.for ( int i = 0; i (i,j) = table[I.at(i,j)]; 13.break ; 14. } 15.case 3: 16. { 17. Mat_ _I = I; 18. 19.for ( int i = 0; i < I.rows; ++i) 20.for ( int j = 0; j < I.cols; ++j ) 21. { 22. _I(i,j)[0] = table[_I(i,j)[0]]; 23. _I(i,j)[1] = table[_I(i,j)[1]]; 24. _I(i,j)[2] = table[_I(i,j)[2]]; 25. } 26. I = _I; 27.break ; 28. } 29. } 30.return I; 31.} 因为这种方法是为随机访问设计的,所以真的是奇慢无比。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.