Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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);

}

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");

}

}

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");

}