Как получить изображение OpenCV из Python и использовать его на C++ в pybind11?C++

Программы на C++. Форум разработчиков
Ответить
Гость
 Как получить изображение OpenCV из Python и использовать его на C++ в pybind11?

Сообщение Гость »


I'm trying to figure out how it is possible to receive an OpenCV image from a Python in C++. I'm trying to send a callback function, from C++ to my Python module, and then when I call a specific python method in my C++ app, I can access the needed image.

Before I add more details, I need to add that there are already several questions in this regard including :
  • how-to-convert-opencv-image-data-from-python-to-c
  • pass-image-data-from-python-to-cvmat-in-c
  • writing-python-bindings-for-c-code-that-use-opencv
  • c-conversion-from-numpy-array-to-mat-opencv

but none of them have anything about

Код: Выделить всё

Pybind11
. In fact they are all using the

Код: Выделить всё

PyObject
(from

Код: Выделить всё

Python.h
header) with and without

Код: Выделить всё

Boost.Python
. So my first attempt is to know how it is possible in

Код: Выделить всё

Pybind11
knowing that it has support for arrays, so it can hopefully make things much easier.

Also On the side, has two versions, 3.x and 4.x which 4.x as I've recently found, is compliant. on Python side, I used OpenCV and I'm on a crossroad of which one to choose and what implications it has when it comes to

Код: Выделить всё

Pybind11
.

What I have tried so far: I made a quick dummy callback and tried passing a simple

Код: Выделить всё

cv::Mat&
like this :

Код: Выделить всё

#include  #include  #include  #include  namespace py = pybind11; ... void cpp_callback1(bool i, std::string id, cv::Mat img) {      auto timenow = chrono::system_clock::to_time_t(chrono::system_clock::now());     cout  

Источник: [url]https://stackoverflow.com/questions/60917800/how-to-get-the-opencv-image-from-python-and-use-it-in-c-in-pybind11[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»