Ask Your Question
1

How to Store a Mat data of Size (1920*1080) and Use it in another program?

asked 2017-05-24 13:08:03 -0500

Dronzer gravatar image

updated 2018-12-26 16:31:03 -0500

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:

  1. 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.

  2. 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!!

edit retag flag offensive close merge delete

Comments

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.

Tetragramm gravatar imageTetragramm ( 2017-05-24 20:19:14 -0500 )edit

progA | progB | progC

(just write/read to stdout, and use pipes ..)

berak gravatar imageberak ( 2017-05-24 23:09:45 -0500 )edit

@Tetragramm I need to store Mat data and process it in completely new program.

Dronzer gravatar imageDronzer ( 2017-05-25 02:35:34 -0500 )edit
1

@berak I tried it but it takes more time than usual. Could you provide me a code to check?

Dronzer gravatar imageDronzer ( 2017-05-25 02:36:06 -0500 )edit

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.

berak gravatar imageberak ( 2017-05-25 03:17:38 -0500 )edit

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.

Tetragramm gravatar imageTetragramm ( 2017-05-25 21:59:54 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-12-26 15:22:24 -0500

iamsurya gravatar image

updated 2018-12-27 11:43:54 -0500

You can use shared memory (Interprocess communication) to do this. It should be fast enough for 60 fps communication.

See this minimal-working-example that uses OpenCV and Windows shared under MIT license. You might need to make changes for a different shared memory implementation, but the memory copy operations should remain the same.

edit flag offensive delete link more

Comments

1

@iamsurya let me explain my main motivation to edit your answer.

When a new reply is posted, the question is raised to the top of the list, but this does not happen when a user's first reply is posted. so I made changes to your answer to attract attention.

maybe your reaction is right but describing it to attempt to hijack answer is not true.

anyway thanks again for your share.

sturkmen gravatar imagesturkmen ( 2018-12-27 11:31:07 -0500 )edit
1

Ah sorry. Apologies for misunderstanding.

iamsurya gravatar imageiamsurya ( 2018-12-27 11:40:25 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-05-24 13:08:03 -0500

Seen: 489 times

Last updated: Dec 27 '18