1

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;
}
Hossein
  • 24,202
  • 35
  • 119
  • 224
  • please post the error you get. – bolov Aug 05 '20 at 05:19
  • does this answer your question: https://stackoverflow.com/questions/60949451/how-to-send-a-cvmat-to-python-over-shared-memory ? – bolov Aug 05 '20 at 05:29
  • @bolov : yes, thats the exact same question. and also thats why I voted to close this as a duplicate rather than deleting it. this helps to redirect users to the right question much faster imho. – Hossein Aug 05 '20 at 06:02

0 Answers0