Advertisement
Guest User

Untitled

a guest
Aug 13th, 2013
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. void cv::remap( InputArray _src, OutputArray _dst,
  2.                 InputArray _map1, InputArray _map2,
  3.                 int interpolation, int borderType, const Scalar& borderValue )
  4. {
  5.     static RemapNNFunc nn_tab[] =
  6.     {
  7.         remapNearest<uchar>, remapNearest<schar>, remapNearest<ushort>, remapNearest<short>,
  8.         remapNearest<int>, remapNearest<float>, remapNearest<double>, 0
  9.     };
  10.  
  11.     static RemapFunc linear_tab[] =
  12.     {
  13.         remapBilinear<FixedPtCast<int, uchar, INTER_REMAP_COEF_BITS>, RemapVec_8u, short>, 0,
  14.         remapBilinear<Cast<float, ushort>, RemapNoVec, float>,
  15.         remapBilinear<Cast<float, short>, RemapNoVec, float>, 0,
  16.         remapBilinear<Cast<float, float>, RemapNoVec, float>,
  17.         remapBilinear<Cast<double, double>, RemapNoVec, float>, 0
  18.     };
  19.  
  20.     static RemapFunc cubic_tab[] =
  21.     {
  22.         remapBicubic<FixedPtCast<int, uchar, INTER_REMAP_COEF_BITS>, short, INTER_REMAP_COEF_SCALE>, 0,
  23.         remapBicubic<Cast<float, ushort>, float, 1>,
  24.         remapBicubic<Cast<float, short>, float, 1>, 0,
  25.         remapBicubic<Cast<float, float>, float, 1>,
  26.         remapBicubic<Cast<double, double>, float, 1>, 0
  27.     };
  28.  
  29.     static RemapFunc lanczos4_tab[] =
  30.     {
  31.         remapLanczos4<FixedPtCast<int, uchar, INTER_REMAP_COEF_BITS>, short, INTER_REMAP_COEF_SCALE>, 0,
  32.         remapLanczos4<Cast<float, ushort>, float, 1>,
  33.         remapLanczos4<Cast<float, short>, float, 1>, 0,
  34.         remapLanczos4<Cast<float, float>, float, 1>,
  35.         remapLanczos4<Cast<double, double>, float, 1>, 0
  36.     };
  37.  
  38.     Mat src = _src.getMat(), map1 = _map1.getMat(), map2 = _map2.getMat();
  39.  
  40.     CV_Assert( map1.size().area() > 0 );
  41.     CV_Assert( !map2.data || (map2.size() == map1.size()));
  42.  
  43.     _dst.create( map1.size(), src.type() );
  44.     Mat dst = _dst.getMat();
  45.     if( dst.data == src.data )
  46.         src = src.clone();
  47.  
  48.     int depth = src.depth();
  49.     RemapNNFunc nnfunc = 0;
  50.     RemapFunc ifunc = 0;
  51.     const void* ctab = 0;
  52.     bool fixpt = depth == CV_8U;
  53.     bool planar_input = false;
  54.  
  55.     if( interpolation == INTER_NEAREST )
  56.     {
  57.         nnfunc = nn_tab[depth];
  58.         CV_Assert( nnfunc != 0 );
  59.     }
  60.     else
  61.     {
  62.         if( interpolation == INTER_AREA )
  63.             interpolation = INTER_LINEAR;
  64.  
  65.         if( interpolation == INTER_LINEAR )
  66.             ifunc = linear_tab[depth];
  67.         else if( interpolation == INTER_CUBIC )
  68.             ifunc = cubic_tab[depth];
  69.         else if( interpolation == INTER_LANCZOS4 )
  70.             ifunc = lanczos4_tab[depth];
  71.         else
  72.             CV_Error( CV_StsBadArg, "Unknown interpolation method" );
  73.         CV_Assert( ifunc != 0 );
  74.         ctab = initInterTab2D( interpolation, fixpt );
  75.     }
  76.  
  77.     const Mat *m1 = &map1, *m2 = &map2;
  78.  
  79.     if( (map1.type() == CV_16SC2 && (map2.type() == CV_16UC1 || map2.type() == CV_16SC1 || !map2.data)) ||
  80.         (map2.type() == CV_16SC2 && (map1.type() == CV_16UC1 || map1.type() == CV_16SC1 || !map1.data)) )
  81.     {
  82.         if( map1.type() != CV_16SC2 )
  83.             std::swap(m1, m2);
  84.     }
  85.     else
  86.     {
  87.         CV_Assert( ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && !map2.data) ||
  88.             (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) );
  89.         planar_input = map1.channels() == 1;
  90.     }
  91.  
  92.     RemapInvoker invoker(src, dst, m1, m2,
  93.                          borderType, borderValue, planar_input, nnfunc, ifunc,
  94.                          ctab);
  95.     parallel_for_(Range(0, dst.rows), invoker, dst.total()/(double)(1<<16));
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement