modules/imgcodecs/src/loadsave.cpp 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 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.