How to convert cv2.cuda_GpuMat to cv::cuda::GpuMat

asked 2020-07-22 08:26:09 -0600

I am trying to create a wrapper in pybind11 to create part of the code in c ++. The problem is that I have to transfer a cuda_gpuMat image to its namesake cv :: cuda :: GpuMat in c ++.

Is there a way?

at::Tensor gpumat2torch(cv::cuda::GpuMat& frame) {
    at::ScalarType torch_type = get_torch_type(frame.type());
    auto options = torch::TensorOptions().dtype(torch_type).device(torch::kCUDA);
    std::vector<int64_t> sizes = {1,
    return torch::from_blob(, sizes, options);
PYBIND11_MODULE(gpumat, m) {
    m.doc() = "gpumat2torch function!";
    m.def("gpumat2torch", &gpumat2torch, "A function to convert GpuMat to CudaTorch");
    m.attr("__version__") = VERSION_INFO;
    m.attr("__version__") = "dev";
edit retag flag offensive close merge delete