title: How to send an image(cv::Mat) from C++ to Python using Pybind11?
body: <p>I'm trying to send an image (<code>cv::Mat</code> to be exact) to a Python method. Doing the reverse is explained <a href="https://stackoverflow.com/questions/60917800/how-to-get-the-opencv-image-from-python-and-use-it-in-c-in-pybind11">here</a>, However, I'm not sure how to send this to Python!.
  The <code>stl</code> and <code>numpy</code> headers are included, so I assumed the automatic cast should be happening, but seems I'm wrong.<br />
  What is missing here and how should I be sending the image to Python?
  This is my simplistic demo for now which fails :</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  
  #include &lt;pybind11/pybind11.h&gt;
  #include &lt;pybind11/embed.h&gt;
  #include &lt;pybind11/numpy.h&gt;
  #include &lt;pybind11/stl.h&gt;
  #include &lt;pybind11/functional.h&gt;
  namespace py = pybind11;
  using namespace py::literals;
  
  #include &lt;opencv2/core.hpp&gt;
  #include&lt;opencv2/imgproc/imgproc.hpp&gt;
  #include&lt;opencv2/highgui/highgui.hpp&gt;
  
  
  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(&quot;MyPackage.MyModule&quot;);
      auto aligner = serviceUtilsModule.attr(&quot;aligner&quot;);
      auto pil_converter = serviceUtilsModule.attr(&quot;cv_to_pil&quot;);
  
      auto currentPath = &quot;D:\\imgs\\img1.jpg&quot;;
      auto img1 = cv::imread(currentPath);
      //PyErr_Print();
  
      auto img_pil = pil_converter(img1);
      auto lst = aligner(img_pil);
  
       py:print(lst);
  
      return 0;
  }
  </code></pre>