How can I create a custom class in c++ and import the output in python? Riight now, the example given is:
torch::Tensor warp_perspective(torch::Tensor image, torch::Tensor warp) {
cv::Mat image_mat(/*rows=*/image.size(0),
/*cols=*/image.size(1),
/*type=*/CV_32FC1,
/*data=*/image.data_ptr<float>());
cv::Mat warp_mat(/*rows=*/warp.size(0),
/*cols=*/warp.size(1),
/*type=*/CV_32FC1,
/*data=*/warp.data_ptr<float>());
cv::Mat output_mat;
cv::warpPerspective(image_mat, output_mat, warp_mat, /*dsize=*/{8, 8});
torch::Tensor output = torch::from_blob(output_mat.ptr<float>(), /*sizes=*/{8, 8});
return output.clone();
}
TORCH_LIBRARY(my_ops, m) {
m.def("warp_perspective", warp_perspective);
}
But suppose I want to create a class in c++, initialise the class and call a method from that in python, like:
Class imageTransform()
{
initialise()
{
/////initialise some values
}
torch::Tensor warp_perspective () {
////use the initialised value here
////here do the transform and return the tensor
}
}
How can I write the python binding for this case?