Share OpenCV C ++ Object with Python

Scenario:

A C ++ software process captures an image using OpenCV. Another process using Python and OpenCV has a common memory area (with mmap) with the first program.

Problem:

How to create in the Python process a link to the same image that already exists in the shared memory area? This part of the Python process can be written as a C-module and imported into Python.

For my specific needs, only the C ++ process creates and writes data, while the Python process simply reads (and processes) it.

Additional Information:

Given the same image field datain C ++ cv::Matand numpy.arrayis equal to (the same size and contents). Therefore, there is no need to convert.

Since languages ​​are separated by memory managers, you may need to use some external synchronization (for example, a semaphore) to avoid one process using a freed area from another.

My problem is creating in a Python object numpy.arraythat data fields point to a specific area in shared memory.

+4
source share

Source: https://habr.com/ru/post/1677212/


All Articles