| 53 | namespace warp_perspective { |
| 54 | |
| 55 | void warp_perspective_cv_exec( |
| 56 | _megdnn_tensor_in src, _megdnn_tensor_in mat, _megdnn_tensor_in dst, |
| 57 | float border_val, BorderMode bmode, InterpolationMode imode, |
| 58 | _megdnn_workspace workspace, cudaStream_t stream) { |
| 59 | megdnn_assert(src.layout[3] == 1 || src.layout[3] == 3, "unsupported src channel"); |
| 60 | megdnn_assert( |
| 61 | src.layout.dtype != dtype::Float32() || src.layout.dtype != dtype::Uint8(), |
| 62 | "unsupported src dtype"); |
| 63 | if (imode == InterpolationMode::INTER_AREA) { |
| 64 | imode = InterpolationMode::INTER_LINEAR; |
| 65 | } |
| 66 | using namespace megcv; |
| 67 | const float* trans_ptr = mat.ptr<dt_float32>(); |
| 68 | double* workspace_ptr = workspace.ptr<double>(); |
| 69 | for (size_t i = 0; i < src.layout.shape[0]; ++i) { |
| 70 | if (dst.layout.dtype == dtype::Float32()) { |
| 71 | Mat<float> src_mat = TensorND2Mat<float>(src, i); |
| 72 | Mat<float> dst_mat = TensorND2Mat<float>(dst, i); |
| 73 | if (src_mat.channels() == 1) { |
| 74 | warp_perspective_cv_proxy<float, 1>( |
| 75 | src_mat.ptr(), dst_mat.ptr(), src_mat.rows(), src_mat.cols(), |
| 76 | dst_mat.rows(), dst_mat.cols(), src_mat.step(), dst_mat.step(), |
| 77 | bmode, imode, trans_ptr, border_val, workspace_ptr, stream); |
| 78 | } else { |
| 79 | warp_perspective_cv_proxy<float, 3>( |
| 80 | src_mat.ptr(), dst_mat.ptr(), src_mat.rows(), src_mat.cols(), |
| 81 | dst_mat.rows(), dst_mat.cols(), src_mat.step(), dst_mat.step(), |
| 82 | bmode, imode, trans_ptr, border_val, workspace_ptr, stream); |
| 83 | } |
| 84 | } else if (dst.layout.dtype == dtype::Uint8()) { |
| 85 | Mat<uchar> src_mat = TensorND2Mat<uchar>(src, i); |
| 86 | Mat<uchar> dst_mat = TensorND2Mat<uchar>(dst, i); |
| 87 | if (src_mat.channels() == 1) { |
| 88 | warp_perspective_cv_proxy<uchar, 1>( |
| 89 | src_mat.ptr(), dst_mat.ptr(), src_mat.rows(), src_mat.cols(), |
| 90 | dst_mat.rows(), dst_mat.cols(), src_mat.step(), dst_mat.step(), |
| 91 | bmode, imode, trans_ptr, static_cast<uchar>(border_val), |
| 92 | workspace_ptr, stream); |
| 93 | } else { |
| 94 | warp_perspective_cv_proxy<uchar, 3>( |
| 95 | src_mat.ptr(), dst_mat.ptr(), src_mat.rows(), src_mat.cols(), |
| 96 | dst_mat.rows(), dst_mat.cols(), src_mat.step(), dst_mat.step(), |
| 97 | bmode, imode, trans_ptr, static_cast<uchar>(border_val), |
| 98 | workspace_ptr, stream); |
| 99 | } |
| 100 | |
| 101 | } else { |
| 102 | megdnn_throw("Unsupported datatype of WarpPerspective optr."); |
| 103 | } |
| 104 | |
| 105 | trans_ptr += 3 * 3; |
| 106 | workspace_ptr += 3 * 3; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | } // namespace warp_perspective |
| 111 |
no test coverage detected