0

I have two opencv2/Python scripts running at the same time on the same Raspberry PI.

  1. A streaming server script based on this, that outputs a live camera feed to the web
  2. a motion detection script, that detects movement from a camera

Only one of these scripts can access the NOIR camera board at once, so I need a way of passing/sharing each frame gathered to the other script.

They both grab the frame from the NOIR camera board using opencv2's rc,img = capture.read(); so i'll have to remove that from one of them and somehow pass the img to the other script when rc is true.

As the camera frame rate is substantial, I don't think it's feasible to save the img (numpy array) to a file on a disc that they can both access; but I may be wrong!

I've been scratching my head and searching the net for examples on scripts that pass data, but alas i'm stuck.

How could I share a numpy array between two running python programs on the same Raspberry PI, and could someone kindly provide me some example code?

  • No chance of merging the two scripts? Is the numpy (img) array a fixed size? – joan Jun 5 '15 at 9:18
  • Iv'e tried to merge the scripts, but the streaming server script waits for a get request, prior to it starting the motion function (which iv'e placed around line 21). I cannot figure out a way to fool the server script that someone has accessed the stream; hence a different approach. I'm not sure if the numpy array is the same size each time. The camera view is constantly changing. – reggie Jun 5 '15 at 9:45
  • could I use mmap to store the current img, in memory, and replace it with each new frame? – reggie Jun 5 '15 at 10:07
  • Plenty of methods. Using shared memory (mmap) may be the most efficient. You still need to know the size though. – joan Jun 5 '15 at 10:34
  • how would I find out the size? is it the size of the resultant picture created from the numpy array? that's about 60Kb. – reggie Jun 5 '15 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.