I'm trying to send an image (cv::Mat
to be exact) to a Python method. Doing the reverse is explained here, However, I'm not sure how to send this to Python!.
The stl
and numpy
headers are included, so I assumed the automatic cast should be happening, but seems I'm wrong.
What is missing here and how should I be sending the image to Python?
This is my simplistic demo for now which fails :
#include <iostream>
#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
namespace py = pybind11;
using namespace py::literals;
#include <opencv2/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
void show_image(cv::Mat img, std::string title)
{
cv::namedWindow(title, cv::WINDOW_NORMAL); // Create a window for display.
cv::imshow(title, img);
cv::waitKey(0);
}
int main()
{
py::scoped_interpreter guard{};
auto serviceUtilsModule = py::module::import("MyPackage.MyModule");
auto aligner = serviceUtilsModule.attr("aligner");
auto pil_converter = serviceUtilsModule.attr("cv_to_pil");
auto currentPath = "D:\\imgs\\img1.jpg";
auto img1 = cv::imread(currentPath);
//PyErr_Print();
auto img_pil = pil_converter(img1);
auto lst = aligner(img_pil);
py:print(lst);
return 0;
}