"components/git@gitlab.utu.fi:nicolaspope/ftl.git" did not exist on "c9629aedea03f7893440bda0c9931927edb2805f"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <ftl/net_source.hpp>
#include <vector>
#include <thread>
#include <chrono>
using ftl::rgbd::NetSource;
using ftl::net::Universe;
using std::string;
using ftl::rgbd::CameraParameters;
using std::mutex;
using std::unique_lock;
using std::vector;
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
static bool getCalibration(Universe &net, string src, ftl::rgbd::CameraParameters &p) {
while(true) {
auto buf = net.findOne<vector<unsigned char>>((string) src +"/calibration");
if (buf) {
memcpy((char*)&p, (*buf).data(), (*buf).size());
if (sizeof(p) != (*buf).size()) {
LOG(ERROR) << "Corrupted calibration";
return false;
}
return true;
} else {
LOG(INFO) << "Could not get calibration, retrying";
sleep_for(milliseconds(500));
}
}
}
NetSource::NetSource(nlohmann::json &config) : RGBDSource(config) {
}
NetSource::NetSource(nlohmann::json &config, ftl::net::Universe *net)
: RGBDSource(config, net) {
has_calibration_ = getCalibration(*net, config["uri"].get<string>(), params_);
net->subscribe(config["uri"].get<string>(), [this](const vector<unsigned char> &jpg, const vector<unsigned char> &d) {
unique_lock<mutex> lk(m_);
cv::imdecode(jpg, cv::IMREAD_COLOR, &rgb_);
//Mat(rgb_.size(), CV_16UC1);
cv::imdecode(d, cv::IMREAD_UNCHANGED, &depth_);
depth_.convertTo(depth_, CV_32FC1, 1.0f/(16.0f*100.0f));
});
}
NetSource::~NetSource() {
// TODO Unsubscribe
}
void NetSource::grab() {
// net_.broadcast("grab");
}
bool NetSource::isReady() {
return has_calibration_ && !rgb_.empty();
}
void NetSource::getRGBD(cv::Mat &rgb, cv::Mat &depth) {
unique_lock<mutex> lk(m_);
rgb_.copyTo(rgb);
depth_.copyTo(depth);
}