[modules/imgcodecs/src/loadsave.cpp](https://github.com/opencv/opencv/blob/f663e8f903645a3dd66f6833f63717b86e861d77/modules/imgcodecs/src/loadsave.cpp#L400) defines a function `imread_` that allows the caller to read image directly to some already existing Mat, potentially having an already allocated memory. However, neither the `cv::imread` in the C++ API, nor `cv2.imread` in Python API [seem to allow](https://docs.opencv.org/4.1.0/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56) reading images this way, forcing the user to allocate a new buffer every time. I'm using OpenCV version 4.1.0.
If I am wrong and this is indeed possible, please let me know what should I read up on to get it to work. If not, how complex would it be to implement this functionality? I'm particularly interested in exposing it as a Python binding.
What I'm trying to do is to have a master process doing IO and several worker processes to do some heavy work on the images. To cut on the inter-process communication time, I'd like to allocate some amount of shared memory, where the master would put images it reads, allowing workers to access it. I reckon it would be faster if master could store images *directly* into this shared memory, instead of allocating a new buffer, reading to it, and copying data from this buffer to shared mem.
I've asked a [similar question on StackOverflow](https://stackoverflow.com/q/57161866/6919631).
↧