Repository navigation
Expand file tree
/
Copy pathtags.cpp
More file actions
70 lines (57 loc) · 1.63 KB
/
Copy pathtags.cpp
File metadata and controls
70 lines (57 loc) · 1.63 KB
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
70
#include "tags.h"
#include <opencv2/opencv.hpp>
#include <optional>
#include <map>
#include <iostream>
#include <fstream>
#include "absl/log/check.h"
namespace robot_vision {
Tags::Tags(Tags&& other) {
absl::MutexLock lock_this{&mu_};
absl::MutexLock lock_other{&other.mu_};
tag_to_world_ = std::move(other.tag_to_world_);
}
bool Tags::TagExists(TagId tag) const {
return tag_to_world_.find(tag) != tag_to_world_.end();
}
Tags& Tags::operator=(Tags&& other) {
absl::MutexLock lock_this{&mu_};
absl::MutexLock lock_other{&other.mu_};
tag_to_world_ = std::move(other.tag_to_world_);
return *this;
}
std::optional<Transformation> Tags::GetTagToWorld(TagId tag) {
absl::MutexLock lock{&mu_};
auto it = tag_to_world_.find(tag);
// CHECK(it != tag_to_world_.end()) << "Tag " << tag << " doesn't exist";
if (it == tag_to_world_.end()) {
return std::nullopt;
}
return it->second;
}
void Tags::emplace(TagId tag, Transformation pos) {
absl::MutexLock lock{&mu_};
tag_to_world_.emplace(tag, pos);
}
Tags ReadTags(const std::string& filename) {
Tags tags;
std::ifstream file(filename);
CHECK(file) << "Could not open file " << filename;
int tag_num;
CHECK(file >> tag_num) << "Error reading from " << filename;
for (int i=0; i<tag_num; ++i) {
int tag;
CHECK(file >> tag) << "Error reading from " << filename;
cv::Mat pos(4, 4, CV_64F);
for (int j=0; j<4; ++j) {
for (int k=0; k<4; ++k) {
double val;
CHECK(file >> val) << "Error reading from " << filename;
pos.at<double>(j, k) = val;
}
}
tags.emplace(tag, Transformation(pos));
}
return std::move(tags);
}
}