diff --git a/Src/Model/BioTrackerTrackingAlgorithm.cpp b/Src/Model/BioTrackerTrackingAlgorithm.cpp index 24939cc4d8de934a154afe0f0ba1d64913de8dfa..c9d320545e64cbcbc2e2c4dc7872c7fdf718d545 100644 --- a/Src/Model/BioTrackerTrackingAlgorithm.cpp +++ b/Src/Model/BioTrackerTrackingAlgorithm.cpp @@ -47,9 +47,12 @@ BioTrackerTrackingAlgorithm::BioTrackerTrackingAlgorithm(IController *parent, IM _lastImage = nullptr; _lastFramenumber = -1; + start_python(); +} - _sock = zmq::socket_t(_ctx, zmq::socket_type::req); - _sock.bind("ipc:///tmp/biotracker.python.zmq"); +BioTrackerTrackingAlgorithm::~BioTrackerTrackingAlgorithm() +{ + stop_python(); } void BioTrackerTrackingAlgorithm::request_shared_memory() { @@ -65,12 +68,29 @@ void BioTrackerTrackingAlgorithm::request_shared_memory() { _shm_img = (float*)init_shm_mmap(shm_path.c_str(), _imageX * _imageY * sizeof(float)); } -void BioTrackerTrackingAlgorithm::receiveAreaDescriptorUpdate(IModelAreaDescriptor *areaDescr) { - _areaInfo = areaDescr; +void BioTrackerTrackingAlgorithm::stop_python() { + if (_python_process.has_value()) { + _python_process_group.terminate(); + _python_process.value().wait(); + } } -BioTrackerTrackingAlgorithm::~BioTrackerTrackingAlgorithm() -{ +void BioTrackerTrackingAlgorithm::start_python() { + stop_python(); + _python_process = boost::process::child( + boost::process::search_path("python3"), + boost::process::args({ + "-c", "from biotracker import BiotrackerAdapter;" + "BiotrackerAdapter('/home/max/tmp/example.multi_instance'" + ",verbose=True).run();" + }), _python_process_group); + + _sock = zmq::socket_t(_ctx, zmq::socket_type::req); + _sock.connect("ipc:///tmp/biotracker.python.zmq"); +} + +void BioTrackerTrackingAlgorithm::receiveAreaDescriptorUpdate(IModelAreaDescriptor *areaDescr) { + _areaInfo = areaDescr; } void BioTrackerTrackingAlgorithm::receiveParametersChanged() { diff --git a/Src/Model/BioTrackerTrackingAlgorithm.h b/Src/Model/BioTrackerTrackingAlgorithm.h index 87e62c6581d9e19e47252018ba083127c2815301..74275bf0c2514ce656f38a5131f5d8786a1a4144 100644 --- a/Src/Model/BioTrackerTrackingAlgorithm.h +++ b/Src/Model/BioTrackerTrackingAlgorithm.h @@ -6,6 +6,7 @@ #include "TrackerParameter.h" +#include <boost/process.hpp> #include <opencv2/opencv.hpp> #include "Interfaces/IModel/IModelTrackingAlgorithm.h" #include "Interfaces/IModel/IModelDataExporter.h" @@ -38,6 +39,8 @@ public Q_SLOTS: private: void request_shared_memory(); + void start_python(); + void stop_python(); BST::TrackedTrajectory* _TrackedTrajectoryMajor; TrackerParameter* _TrackingParameter; @@ -45,7 +48,8 @@ private: int _noFish; - //std::ofstream _ofs; + std::optional<boost::process::child> _python_process; + boost::process::group _python_process_group; int _imageX; int _imageY;