MSCEqF 1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Loading...
Searching...
No Matches
visualizer.hpp
1// Copyright (C) 2023 Alessandro Fornasier.
2// Control of Networked Systems, University of Klagenfurt, Austria.
3//
4// All rights reserved.
5//
6// This software is licensed under the terms of the Apache License, Version 2.0
7// (the "License"); you may not use this file except in compliance with the
8// License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15// License for the specific language governing permissions and limitations
16// under the License.
17//
18// You can contact the authors at <alessandro.fornasier@ieee.org>
19
20#ifndef VISUALIZER_HPP
21#define VISUALIZER_HPP
22
23#include <opencv2/opencv.hpp>
24
25#include "sensors/sensor_data.hpp"
26#include "vision/track_manager.hpp"
27
28namespace msceqf
29{
31{
32 public:
38 Visualizer(const TrackManager& track_manager) : track_manager_(track_manager), colors_(), delay_(1)
39 {
40 colors_.emplace(0, cv::Scalar(38, 0, 165)); // red
41 colors_.emplace(1, cv::Scalar(39, 48, 215)); // dark red
42 colors_.emplace(2, cv::Scalar(67, 109, 244)); // orange
43 colors_.emplace(3, cv::Scalar(97, 174, 253)); // light orange
44 colors_.emplace(4, cv::Scalar(139, 224, 254)); // yellow
45 colors_.emplace(5, cv::Scalar(191, 255, 255)); // light yellow
46 colors_.emplace(6, cv::Scalar(139, 239, 217)); // light green
47 colors_.emplace(7, cv::Scalar(106, 217, 166)); // green
48 colors_.emplace(8, cv::Scalar(99, 189, 102)); // slightly darker green
49 colors_.emplace(9, cv::Scalar(80, 152, 26)); // dark green
50 colors_.emplace(10, cv::Scalar(55, 104, 0)); // very dark green
51 }
52
58 cv::Mat3b imageWithTracks(const Camera& cam, const std::string& text = "") const
59 {
60 cv::Mat undistorted_image;
61 track_manager_.cam()->undistortImage(cam.image_, undistorted_image);
62
63 cv::Mat3b color_image = undistorted_image;
64 if (undistorted_image.channels() == 1)
65 {
66 cv::cvtColor(undistorted_image, color_image, cv::COLOR_GRAY2BGR, 3);
67 }
68
69 cv::Mat mask;
70 track_manager_.cam()->undistortImage(cam.mask_, mask);
71 mask = cv::Scalar(255) - mask;
72
73 std::vector<cv::Mat> channels;
74 cv::split(color_image, channels);
75 channels[2] = channels[2] + mask;
76 cv::merge(channels, color_image);
77
78 if (text.compare("") != 0)
79 {
80 cv::putText(color_image, text, cv::Point(50, 50), cv::FONT_HERSHEY_TRIPLEX, 1, cv::Scalar(255, 0, 0), 2);
81 }
82
83 Tracker::Keypoints active_kpts;
84 std::unordered_set<uint> active_ids;
85
86 track_manager_.activeTracksIds(cam.timestamp_, active_ids);
87 if (!active_ids.empty())
88 {
89 const auto& tracks = track_manager_.tracks();
90 for (auto& id : active_ids)
91 {
92 const auto& color = colors_.at(id % colors_.size());
93 for (size_t i = 0; i < tracks.at(id).size() - 1; ++i)
94 {
95 cv::line(color_image, tracks.at(id).uvs_.at(i), tracks.at(id).uvs_.at(i + 1), color, 1);
96 }
97 cv::circle(color_image, tracks.at(id).uvs_.back(), 3, color, -1);
98 }
99 }
100
101 return color_image;
102 }
103
109 void visualizeImageWithTracks(const Camera& cam, const std::string& text = "") const
110 {
111 cv::imshow("Undistorted image with tracks", imageWithTracks(cam, text));
112 cv::waitKey(delay_);
113 }
114
115 private:
116 const TrackManager& track_manager_;
117 std::unordered_map<uint, cv::Scalar> colors_;
118 int delay_;
119};
120} // namespace msceqf
121
122#endif // VISUALIZER_HPP
This class manages the multiple tracks of feature traked in time.
Definition track_manager.hpp:36
std::vector< cv::KeyPoint > Keypoints
A vector of features keypoints.
Definition tracker.hpp:41
Visualizer(const TrackManager &track_manager)
Construct a new Visualizer object.
Definition visualizer.hpp:38
void visualizeImageWithTracks(const Camera &cam, const std::string &text="") const
Visualize imge with history of tracks.
Definition visualizer.hpp:109
cv::Mat3b imageWithTracks(const Camera &cam, const std::string &text="") const
Camera image with overlayed tracks.
Definition visualizer.hpp:58
Definition sensor_data.hpp:86
cv::Mat mask_
The mask for the given image, 255 in valid reagions, 0 in regions to be masked out.
Definition sensor_data.hpp:101
fp timestamp_
Timestamp of the Camera reading.
Definition sensor_data.hpp:102
cv::Mat image_
The image taken from the camera.
Definition sensor_data.hpp:100