1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include <torch/extension.h> #include <vector> #include <opencv2/core/core.hpp> #include <opencv2/opencv.hpp> #include <opencv2/imgproc.hpp>
using namespace cv; using namespace std;
torch::Tensor extend_gray(torch::Tensor image, torch::Tensor warp) { cv::Mat image_mat(image.size(0), image.size(1), CV_32FC1, image.data_ptr<float>());
cv::Mat warp_mat(warp.size(0), warp.size(1), CV_32FC1, warp.data_ptr<float>());
cv::Mat output_mat; cv::warpPerspective(image_mat, output_mat, warp_mat, {8, 8});
torch::Tensor output = torch::from_blob(output_mat.ptr<float>(), {8, 8}); return output.clone(); }
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { m.def("extend_gray", &extend_gray, "extend gray"); }
|