I'm creating a object and color detection robot. Here in this case, I'm using C++ to run the camera and process the image with openCV in C++, but before I run the Camera, I want the robot to move and do other activities for which I'm using python codes. So basically, I want to run a python code and then run the C++ code and then get back to the python code. How do I do it? Thanks a lot for reading. Please help me.
You may want to launch your C++ application via a subprocess, launched from python, then communicate with it using stdin/stdout. This way, both programm will run in parrallel (python needs to be launched first), avoiding the need to switch from one to the other.
Here is how to launch your subprocess:
import subprocess mysubproc = subprocess.Popen('/myfolder/myprogram', shell=True, stdin=subprocess.PIPE, )
then to pass some information from python to C++ :
And to read the result from the C++ program :
while True: line = mysubproc.stdout.readline()
This will work fine, unless you have to tranfer large amount of datas (i.e. images). In this case, I would write these data to a temporary file, then only pass the file location via stdin/stdout.