Skip to content
Snippets Groups Projects
Commit 1d0f65c5 authored by Sebastian Gomez-Gonzalez's avatar Sebastian Gomez-Gonzalez
Browse files

Adding a ZMQ driver for ball likelihood operator (Not tested or used yet)

parent a9cd7e8a
Branches dev
No related tags found
No related merge requests found
......@@ -14,6 +14,8 @@ find_library(CAMLIB NAMES camera)
find_path(CAMLIB_INC NAMES camera.hpp)
find_library(ROBOTICS NAMES robotics)
find_path(ROBOTICS_INC NAMES robotics.hpp)
find_library(ROB_PROTO NAMES rob_proto)
find_path(ROB_PROTO_INC NAMES rob_proto/frame.pb.h)
if (CUDA_FOUND)
option (WITH_CUDA "Compile the library with GPU implementations" ON)
......@@ -42,6 +44,7 @@ include_directories(include
${ZMQPP_INCLUDES}
${CAMLIB_INC}
${ROBOTICS_INC}
${ROB_PROTO_INC}
)
add_library(ball_tracking SHARED
......@@ -60,6 +63,7 @@ target_link_libraries(ball_tracking
${Boost_LIBRARIES}
${ARMADILLO_LIBRARIES}
${ROBOTICS}
${ROB_PROTO}
)
......
......@@ -79,7 +79,9 @@ namespace ball_tracking {
//3) Start the cameras and call backs
BOOST_LOG_TRIVIAL(info) << "Starting the cameras...";
BOOST_LOG_TRIVIAL(info) << "Driver: " << conf.at("cameras").at("type");
cams = CameraSet(conf.at("cameras"));
BOOST_LOG_TRIVIAL(info) << "Cameras successfully started";
for (auto& p: trackers) {
unsigned int ID = p.first;
......
......@@ -6,6 +6,8 @@
#include <json.hpp>
#include <queue>
#include <unordered_set>
#include <zmqpp/zmqpp.hpp>
#include <rob_proto/frame.pb.h>
#ifdef WITH_CUDA
#include <ball_tracking/cuda/tracker.hpp>
......@@ -88,6 +90,46 @@ namespace ball_tracking {
}
};
/**
* Network based image log likelihood
*/
class ZMQ_log_lh {
private:
shared_ptr<zmqpp::context> ctx;
shared_ptr<zmqpp::socket> sk;
public:
ZMQ_log_lh(const json& conf) {
ctx = shared_ptr<zmqpp::context>(new zmqpp::context);
sk = shared_ptr<zmqpp::socket>(new zmqpp::socket(*ctx, zmqpp::socket_type::req));
sk->connect(conf.at("server"));
}
cv::Mat operator()(cv::InputArray _src) {
cv::Mat m = _src.getMat();
rob_proto::Image img;
img.set_height(m.rows);
img.set_width(m.cols);
img.set_channels(m.channels());
img.set_data((const char*)m.data, m.rows*m.cols*m.channels());
string s_img = img.SerializeAsString();
zmqpp::message req,res;
req << s_img;
sk->send(req);
cv::Mat ans (m.rows, m.cols, CV_64FC1);
sk->receive(res);
res >> s_img;
if (s_img.size() != ans.total()*sizeof(double)) {
BOOST_LOG_TRIVIAL(error) << "Error in ZMQ_log_lh. Obtained response size different than expected";
} else {
std::copy(s_img.begin(), s_img.end(), ans.data);
}
return ans;
}
};
/**
* OpenCV Blob detection algorithm
*/
......@@ -244,6 +286,8 @@ namespace ball_tracking {
const json& conf = config.at("conf");
if (type == "cb_log_reg") {
bll = CB_log_reg(conf);
} else if (type == "zmq_log_lh") {
bll = ZMQ_log_lh(conf);
} else {
throw std::logic_error("Type of ball log likelihood algorithm not recognized");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment