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

Add json fish poses to trajectory

parent bfd7abd0
No related branches found
No related tags found
No related merge requests found
......@@ -11,8 +11,10 @@
#include "BioTrackerTrackingAlgorithm.h"
#include <future>
#include "TrackedComponents/TrackedComponentFactory.h"
#include "TrackedComponents/pose/FishPose.h"
#include <chrono>
#include <zmq.hpp>
#define JSON_USE_IMPLICIT_CONVERSIONS 0
#include "json.hpp"
using json = nlohmann::json;
......@@ -70,7 +72,7 @@ void BioTrackerTrackingAlgorithm::request_shared_memory() {
_sock.send(zmq::buffer(j.dump()));
auto res = _sock.recv(_zmq_msg, zmq::recv_flags::none);
auto msg = json::parse(_zmq_msg.to_string_view());
std::string shm_path = msg["path"];
std::string shm_path = msg["path"].get<std::string>();
_shm_img = (float*)init_shm_mmap(shm_path.c_str(), _imageX * _imageY * sizeof(float));
}
......@@ -113,6 +115,8 @@ void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, u
return;
}
std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
cv::Mat grayscale, float_img;
cv::cvtColor(*p_image, grayscale, cv::COLOR_BGR2GRAY);
grayscale.convertTo(float_img, CV_32F);
......@@ -128,6 +132,34 @@ void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, u
auto res = _sock.recv(_zmq_msg, zmq::recv_flags::none);
auto msg = json::parse(_zmq_msg.to_string_view());
std::vector<FishPose> poses;
for (auto pos : msg["data"]) {
auto pose = FishPose(
cv::Point2f(1.0, 1.0), // FIXME: Calculate cm
cv::Point2f(pos["x"].get<int>(), pos["y"].get<int>()),
pos["orientation"].get<float>(),
pos["orientation"].get<float>() * (180.0 / CV_PI),
1.0, // FIXME: width
1.0, // FIXME: height
1.0 // FIXME: score
);
poses.push_back(pose);
}
//Insert new poses into data structure
int trajNumber = 0;
for (int i = 0; i < _TrackedTrajectoryMajor->size(); i++) {
BST::TrackedTrajectory *t = dynamic_cast<BST::TrackedTrajectory *>(_TrackedTrajectoryMajor->getChild(i));
if (t && t->getValid() && !t->getFixed()) {
BST::TrackedElement *e = new BST::TrackedElement(t, "n.a.", t->getId());
e->setFishPose(poses[trajNumber]);
e->setTime(start);
t->add(e, framenumber);
trajNumber++;
}
}
std::string newSel = _TrackingParameter->getNewSelection();
Q_EMIT emitChangeDisplayImage("Original");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment