I'm currently working on a python project. It's about image detection. I have to processes, which are running simultaneously with multiprocessing. The first function communicates with the frame grabber and is doing some image processing. The second function communicates with a neural net, which does the actual image-detection. The second function needs the image grabbed in the first function for the detection. The second function should then provide the results, which are used by the first function to draw rectangles on the video stream (where the detected objects are).
The code looks something like this:
import multiprocessing
import cv2
import json
def fun1():
while True:
# Shows video-stream, does image editing, grabs frames
# and stores them in an external folder
# Accesses the result for drawing rectangles from the
# .json file
def fun2():
while True:
# Uses frames from the external folder
# does image-detection, saves result to .json file
if __name__ == "__main__":
s = Process(target=fun1)
r = Process(target=fun2)
s.start()
r.start()
s.join()
r.join()
As you can see, both processes are running in an infinite while loop. As for now, I save the images created in fun1 in a folder, where fun2 can access them. The results from the neural net from fun2 are saved in a .json file, where fun1 can access them.
Both, the result and the image, change every iteration. I was wondering, if there is a way to send the current image directly to fun2 and to send the result from fun2 to fun1 without using an extern .json file. Is there a way to communicate directly?
I hope that I could explain my problem understandably.
Thanks for helping me out!