aihot  2017-05-22 21:02:56  OpenCV |   查看评论   

split实现代码split.hpp:

  1. // fbc_cv是免费软件,并且使用与OpenCV相同的许可证
  2. #ifndef FBC_CV_SPLIT_HPP_  
  3. #define FBC_CV_SPLIT_HPP_  
  4.   
  5. /* reference: include/opencv2/core.hpp 
  6.               core/src/convert.cpp 
  7.           core/src/split.cpp 
  8. */  
  9.   
  10. #include <vector>  
  11. #include "core/mat.hpp"  
  12.   
  13. #ifndef __cplusplus  
  14.     #error split.hpp header must be compiled as C++  
  15. #endif  
  16.   
  17. namespace fbc {  
  18.   
  19. // 将多通道阵列拆分为单独的单通道阵列
  20. template<typename _Tp, int chs1, int chs2>  
  21. int split(const Mat_<_Tp, chs1>& src, std::vector<Mat_<_Tp, chs2>>& dst)  
  22. {  
  23.     FBC_Assert(src.data != NULL);  
  24.     FBC_Assert((dst.size() == chs1) && (chs2 == 1));  
  25.     for (int i = 0; i < dst.size(); i++) {  
  26.         FBC_Assert((dst[i].data != NULL) && (dst[i].rows == src.rows) && (dst[i].cols == src.cols));  
  27.     }  
  28.   
  29.     int cn = src.channels;  
  30.     if (cn == 1) {  
  31.         memcpy(dst[0].data, src.data, src.step * src.rows);  
  32.         return 0;  
  33.     }  
  34.   
  35.     _Tp* pSrc = (_Tp*)src.data;  
  36.     int len = src.rows * src.cols;  
  37.   
  38.     for (int i = 0; i < cn; i++) {  
  39.         _Tp* pDst = (_Tp*)dst[i].data;  
  40.   
  41.         for (int j = 0; j < len; j++) {  
  42.             pDst[j] = pSrc[j * cn + i];  
  43.         }  
  44.     }  
  45.   
  46.     return 0;  
  47. }  
  48.   
  49. // 命名空间fbc
  50.   
  51. #endif // FBC_CV_SPLIT_HPP_  

 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV的代码提取:合并/拆分(merge/split)函数的实现

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]