How to Store a Mat data of Size (1920*1080) and Use it in another program?
Hello!! I am using Opencv with C++ and I want to Store a Mat of size (1920*1080) and use that in another program. The options that I have:
I could store the Mat data as an Image and can access it in another program or I can store all the values in a file and can access it. But, the most important thing in my implementation is speed as I need to process 60 frames in a second.
I can take all the values in a header and could initialise to a Mat but it keeps on building the program and I haven't looked at the performance.
I am looking for a Solution to access the Mat very efficiently. Thank you in Advance!!
Do you mean, another process entirely or just another part of the same process? Either way, you can use the Mat constructor to wrap a section of memory and then copy into or out of it.
Take a look at constructor 11 HERE.
progA | progB | progC
(just write/read to stdout, and use pipes ..)
@Tetragramm I need to store Mat data and process it in completely new program.
@berak I tried it but it takes more time than usual. Could you provide me a code to check?
hmm, ok. seems i underestimated the size ;(
yea tried my own dogfood - it sucks.
10 images read took 8.76731 seconds. 10 images write took 13.6398 seconds.
Ok, so storing data to disk and reading it in a new program, and 60 FPS do not go together.
You either need to set up shared memory and some events or... I dunno how else, but that's the way I would do it.
Create the shared memory and an event in both processes. In program A map the shared memory into a Mat and do your progA processing. When you're done with A, wait for the event to be unset, then image.copyTo(shared), then set the event. In Program B, wait for the event to be set, copy the image out of the shared buffer, then unset the event.