• DepthAI-v2
  • Call Python script to build pipeline then pass back to C++

I have an application in C++ which will be using DepthAI, but for the purposes of easier development I would like to construct the pipeline in python then pass it back to C++ then unwrap the python object back into a dai::Device object which can then be manipulated(including the now running pipeline) in C++, is there an accepted way to do this? In summary:

  • from C++ call some file, say "pipeline_builder.py" which contains some method "build" which builds a pipeline and returns a dai.device python object
  • get the returned object and unwrap/cast(?) as dai::Device

Hi @TheHiddenWaffle
Not sure if that is possible without knowing the address of device in memory. The python wrapper and C++ syntax is 1:1 so it would probably be easier to just write the python code, then GPT it to C++.

Thoughts?

    Hi @TheHiddenWaffle

    TheHiddenWaffle I guess what I was thinking is i could initialize the device(or maybe even just the pipeline) then cast it to a python object via pybind11 and then push it through python and cast back

    Apparently this is not possible since Device object is not serializable as it maintains a constant connection to the device, so sharing it between processes is impossible (even OS won't allow it).

      jakaskerl I did experience that, so I just dropped back and built only the pipeline from python, which after some utterly ignorant guesswork and reading the pybind11 docs has worked! I still need to clean up the project for a minimal example because I have ugly code strewn about everywhere but I was able to create a pipeline in cpp, pass to the python script, attach a simple XLinkIn->XLinkOut example to the pipeline and extract it from the returned py::object then assign it to the device on the cpp side and do an echo! Unsure if this will be useful for anyone else owing to the fact that as you said the device must still be configured on the cpp side but I think it's still rather neat.

      I suppose one might be able to feed in DeviceInfo object to the python script and configure that as well then back in C++ use the Device(const Pipeline& pipeline, const DeviceInfo& devInfo); constructor to set up the device as well as the pipeline?

        Hi @TheHiddenWaffle

        TheHiddenWaffle I suppose one might be able to feed in DeviceInfo object to the python script and configure that as well then back in C++ use the Device(const Pipeline& pipeline, const DeviceInfo& devInfo); constructor to set up the device as well as the pipeline?

        That would be possible, though I'm not sure if/how it would be useful.

        Thanks,
        Jaka