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 BSD-2-Clause-License with
7// no commercial use allowed, the full terms of which are made available
8// in the LICENSE file. No license in patents is granted.
9//
10// You can contact the authors at <alessandro.fornasier@ieee.org>
11
12#ifndef VISUALIZER_HPP
13#define VISUALIZER_HPP
14
15#include <opencv2/opencv.hpp>
16
17#include "sensors/sensor_data.hpp"
18#include "vision/track_manager.hpp"
19
20namespace msceqf
21{
23{
24 public:
30 Visualizer(const TrackManager& track_manager) : track_manager_(track_manager), colors_(), delay_(1)
31 {
32 colors_.emplace(0, cv::Scalar(38, 0, 165)); // red
33 colors_.emplace(1, cv::Scalar(39, 48, 215)); // dark red
34 colors_.emplace(2, cv::Scalar(67, 109, 244)); // orange
35 colors_.emplace(3, cv::Scalar(97, 174, 253)); // light orange
36 colors_.emplace(4, cv::Scalar(139, 224, 254)); // yellow
37 colors_.emplace(5, cv::Scalar(191, 255, 255)); // light yellow
38 colors_.emplace(6, cv::Scalar(139, 239, 217)); // light green
39 colors_.emplace(7, cv::Scalar(106, 217, 166)); // green
40 colors_.emplace(8, cv::Scalar(99, 189, 102)); // slightly darker green
41 colors_.emplace(9, cv::Scalar(80, 152, 26)); // dark green
42 colors_.emplace(10, cv::Scalar(55, 104, 0)); // very dark green
43 }
44
50 cv::Mat3b imageWithTracks(const Camera& cam, const std::string& text = "") const
51 {
52 cv::Mat undistorted_image;
53 track_manager_.cam()->undistortImage(cam.image_, undistorted_image);
54
55 cv::Mat3b color_image = undistorted_image;
56 if (undistorted_image.channels() == 1)
57 {
58 cv::cvtColor(undistorted_image, color_image, cv::COLOR_GRAY2BGR, 3);
59 }
60
61 cv::Mat mask;
62 track_manager_.cam()->undistortImage(cam.mask_, mask);
63 mask = cv::Scalar(255) - mask;
64
65 std::vector<cv::Mat> channels;
66 cv::split(color_image, channels);
67 channels[2] = channels[2] + mask;
68 cv::merge(channels, color_image);
69
70 if (text.compare("") != 0)
71 {
72 cv::putText(color_image, text, cv::Point(50, 50), cv::FONT_HERSHEY_TRIPLEX, 1, cv::Scalar(255, 0, 0), 2);
73 }
74
75 Tracker::Keypoints active_kpts;
76 std::unordered_set<uint> active_ids;
77
78 track_manager_.activeTracksIds(cam.timestamp_, active_ids);
79 if (!active_ids.empty())
80 {
81 const auto& tracks = track_manager_.tracks();
82 for (auto& id : active_ids)
83 {
84 const auto& color = colors_.at(id % colors_.size());
85 for (size_t i = 0; i < tracks.at(id).size() - 1; ++i)
86 {
87 cv::line(color_image, tracks.at(id).uvs_.at(i), tracks.at(id).uvs_.at(i + 1), color, 1);
88 }
89 cv::circle(color_image, tracks.at(id).uvs_.back(), 3, color, -1);
90 }
91 }
92
93 return color_image;
94 }
95
101 void visualizeImageWithTracks(const Camera& cam, const std::string& text = "") const
102 {
103 cv::imshow("Undistorted image with tracks", imageWithTracks(cam, text));
104 cv::waitKey(delay_);
105 }
106
107 private:
108 const TrackManager& track_manager_;
109 std::unordered_map<uint, cv::Scalar> colors_;
110 int delay_;
111};
112} // namespace msceqf
113
114#endif // VISUALIZER_HPP
This class manages the multiple tracks of feature traked in time.
Definition track_manager.hpp:28
void activeTracksIds(const fp &timestamp, std::unordered_set< uint > &active_ids) const
Get all the ids corresponding to active tracks at a given timestamp. Active tracks are defined as tra...
const Tracks & tracks() const
Get all the tracks.
const PinholeCameraUniquePtr & cam() const
Get the camera pointer.
std::vector< cv::KeyPoint > Keypoints
A vector of features keypoints.
Definition tracker.hpp:33
Definition visualizer.hpp:23
Visualizer(const TrackManager &track_manager)
Construct a new Visualizer object.
Definition visualizer.hpp:30
void visualizeImageWithTracks(const Camera &cam, const std::string &text="") const
Visualize imge with history of tracks.
Definition visualizer.hpp:101
cv::Mat3b imageWithTracks(const Camera &cam, const std::string &text="") const
Camera image with overlayed tracks.
Definition visualizer.hpp:50
Definition sensor_data.hpp:78
cv::Mat mask_
The mask for the given image, 255 in valid reagions, 0 in regions to be masked out.
Definition sensor_data.hpp:93
fp timestamp_
Timestamp of the Camera reading.
Definition sensor_data.hpp:94
cv::Mat image_
The image taken from the camera.
Definition sensor_data.hpp:92