Skip to content
Snippets Groups Projects
Commit c3407622 authored by Max Breitenfeldt's avatar Max Breitenfeldt
Browse files

Start python adapter from tracking plugin

parent cd1ca271
No related branches found
No related tags found
No related merge requests found
...@@ -47,9 +47,12 @@ BioTrackerTrackingAlgorithm::BioTrackerTrackingAlgorithm(IController *parent, IM ...@@ -47,9 +47,12 @@ BioTrackerTrackingAlgorithm::BioTrackerTrackingAlgorithm(IController *parent, IM
_lastImage = nullptr; _lastImage = nullptr;
_lastFramenumber = -1; _lastFramenumber = -1;
start_python();
}
_sock = zmq::socket_t(_ctx, zmq::socket_type::req); BioTrackerTrackingAlgorithm::~BioTrackerTrackingAlgorithm()
_sock.bind("ipc:///tmp/biotracker.python.zmq"); {
stop_python();
} }
void BioTrackerTrackingAlgorithm::request_shared_memory() { void BioTrackerTrackingAlgorithm::request_shared_memory() {
...@@ -65,12 +68,29 @@ 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)); _shm_img = (float*)init_shm_mmap(shm_path.c_str(), _imageX * _imageY * sizeof(float));
} }
void BioTrackerTrackingAlgorithm::receiveAreaDescriptorUpdate(IModelAreaDescriptor *areaDescr) { void BioTrackerTrackingAlgorithm::stop_python() {
_areaInfo = areaDescr; 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() { void BioTrackerTrackingAlgorithm::receiveParametersChanged() {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "TrackerParameter.h" #include "TrackerParameter.h"
#include <boost/process.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "Interfaces/IModel/IModelTrackingAlgorithm.h" #include "Interfaces/IModel/IModelTrackingAlgorithm.h"
#include "Interfaces/IModel/IModelDataExporter.h" #include "Interfaces/IModel/IModelDataExporter.h"
...@@ -38,6 +39,8 @@ public Q_SLOTS: ...@@ -38,6 +39,8 @@ public Q_SLOTS:
private: private:
void request_shared_memory(); void request_shared_memory();
void start_python();
void stop_python();
BST::TrackedTrajectory* _TrackedTrajectoryMajor; BST::TrackedTrajectory* _TrackedTrajectoryMajor;
TrackerParameter* _TrackingParameter; TrackerParameter* _TrackingParameter;
...@@ -45,7 +48,8 @@ private: ...@@ -45,7 +48,8 @@ private:
int _noFish; int _noFish;
//std::ofstream _ofs; std::optional<boost::process::child> _python_process;
boost::process::group _python_process_group;
int _imageX; int _imageX;
int _imageY; int _imageY;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment