I have four functions; three camera functions to (take a picture save the image, save the path to a CSV file), the fourth function is to grab data from a serial connection via an arduino
. Each function works as intended independently and via normal multiprocessing
(without join()
). I cannot use the join()
method because of the way the opencv
function work. I understand that the join method works, where it waits for the child processes
to complete before running it again.
I need to be able to return a value (Boolean: True/ False or 0/1) from the arduino
function to the camera function before starting again. Arduino
code takes the longest and needs time to run.
generic code below
import cv2
import multiprocessing
import Serial
def camera1():
global cap1
cap1 = cv2.VideoCapture(0)
while True:
_, frame1 = cap1.read()
cv2.imshow('frame1', frame1)
k = cv2.waitKey(5)
if k == 27:
break
"""
Saves image and add to csv file
while loop checking for ard_serial is complete to repeat
"""
cap1.release()
def camera2():
global cap2
cap2 = cv2.VideoCapture(1)
while True:
_, frame2 = cap2.read()
cv2.imshow('frame2', frame2)
k = cv2.waitKey(5)
if k == 27:
break
"""
Saves image and add to csv file
while loop checking for ard_serial is complete to repeat
"""
cap2.release()
def camera3():
global cap3
cap3 = cv2.VideoCapture(2)
while True:
_, frame3 = cap3.read()
cv2.imshow('frame3', frame3)
k = cv2.waitKey(5)
if k == 27:
break
"""
Saves image and add to csv file
while loop checking for ard_serial is complete to repeat
"""
cap3.release()
def ard_serial():
"""
Serial Stuff happens here
When Complete sends value to cam functions
to start again.
"""
if __name__ == '__main__':
for _ in range(20)
p1 = multiprocessing.Process(target=camera1)
p1.start()
p2 = multiprocessing.Process(target=camera2)
p2.start()
p3 = multiprocessing.Process(target=camera3)
p3.start()
p4 = multiprocessing.Process(target=ard_serial)
p4.start()
"""
p1.join()
p2.join()
p3.join()
p4.join()
"""
I need to have all four functions to start at the same time and have the cam functions wait for the arduino function to finish before starting again. What can I use for this? I wasn't sure if I have to use Queue
or something different. Plus most examples have just one worker function that returns something. I need one function to send a return value to another function. join()
method won't work because of the potentially never ending while loop, until it is complete