how to use pyopencv_to function

asked 2020-07-23 08:19:42 -0600

Xerror gravatar image

updated 2020-07-23 08:54:58 -0600

I am trying to create a wrapper in pybind11 to create part of the code in c ++ and I need to use pyopencv_to inside my function but when I want to build my project I'm getting this error error: ‘pyopencv_to’ was not declared in this scope pyopencv_to(frame, frame_gpu);. How can I use pyopencv_to function?

#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
#include <opencv2/core/cuda.hpp>
#include <ATen/ATen.h>
#include <pybind11/pybind11.h>

at::Tensor gpumat2torch(PyObject* frame) {
     cv::cuda::GpuMat frame_gpu;
     pyopencv_to(frame, frame_gpu);
     at::ScalarType torch_type = get_torch_type(frame_gpu.type());
     auto options = torch::TensorOptions().dtype(torch_type).device(torch::kCUDA);
     std::vector<int64_t> sizes = {1,
                              static_cast<int64_t>(frame_gpu.channels()),
                              static_cast<int64_t>(frame_gpu.rows),
                              static_cast<int64_t>(frame_gpu.cols)};
     return torch::from_blob(frame_gpu.data, sizes, options);
}
PYBIND11_MODULE(gpumat, m) {
     m.doc() = "gpumat2torch function!";
     m.def("gpumat2torch", &gpumat2torch, "A function to convert GpuMat to CudaTorch");

}
edit retag flag offensive close merge delete

Comments

I am trying to create a wrapper in pybind11

that's an entirely different binding system, mixing that with opencv's sounds like a terrible idea.

berak gravatar imageberak ( 2020-07-23 08:41:17 -0600 )edit

and why do you think, you need this ?

the template declarations are here and will call this for GPUMat but NONE OF IT IS PART OF THE PUBLIC API

berak gravatar imageberak ( 2020-07-23 08:50:26 -0600 )edit

because I will get this error incompatible function arguments. The following argument types are supported: 1. (arg0: cv::cuda::GpuMat) -> at::Tensor without using pyopencv_to. The problem is that I have to transfer a python cuda_gpuMat image to its namesake cv :: cuda :: GpuMat in c ++ and I think I need to use pyopencv_to to transfer it to c++ or there is another way which I dont know. Do you have any idea?

Xerror gravatar imageXerror ( 2020-07-23 09:03:28 -0600 )edit