how to use pyopencv_to function
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");
}
that's an entirely different binding system, mixing that with opencv's sounds like a terrible idea.
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
because I will get this error
incompatible function arguments. The following argument types are supported: 1. (arg0: cv::cuda::GpuMat) -> at::Tensor
without usingpyopencv_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 usepyopencv_to
to transfer it to c++ or there is another way which I dont know. Do you have any idea?