I am attempting to send a character input from one python script to another (run as a subprocess with subprocess.Popen()
and subprocess.Popen.send_signal()
). The sub-process uses openCV's cv2.waitKey(x) == ord('y')
to determine when to perform a specific operation.
I've read that openCV's waitKey doesn't listen to console input, so how can I communicate with it? Is there a better way to send a signal to an openCV window as a subprocess?
EDIT: The subprocess does NOT need to communicate with the parent process. The parent simply needs to send a signal to the subprocess' waitKey(). Simply terminating the subprocess will cause it to exit before completing desired operations.
My first attempt (confident that it would fail) looked something like this:
path-to-python-environment = "/home/user1/virtual-env/bin/python3"
path-to-python-script = "/home/user1/scripts/myScript.py"
while true:
inputValue = input("enter value")
if(inputValue == "start"):
p = subprocess.Popen([path-to-python-environment, path-to-python-script])
elif(inputValue == "function-y"):
p.send_signal('y')
#assuming that user will send "start" BEFORE "function-y"
The subprocess file runs in the specified environment and uses a simple loop, which is broken on a waitKey() input. It looks somewhat like:
import cv2
while true:
img = cv2.imread("image1.png")
cv2.imshow("picture",img)
if cv2.waitKey(10) == ord('y')
break
print("some string")
cv2.destroyAllWindows()