bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
downward_camera.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_DOWNWARD_CAMERA_H
2#define BITSIM_SENSORS_DOWNWARD_CAMERA_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_OPENCV
7
9#include "bitsim/extern/nlohmann/json/json.hpp"
10
11#include <opencv2/core.hpp>
12
13#include <array>
14#include <functional>
15#include <string>
16#include <vector>
17
18namespace bitsim
19{
20namespace sensors
21{
22
31{
32 public:
38 FloorImage(const cv::Mat &image, real_t width);
39
52 const std::function<bool(real_t, real_t)> &is_ink, uchar paper = 235,
53 uchar ink = 25);
54
59 void write_texture(const std::string &path) const;
60
61 const cv::Mat &image() const noexcept { return image_; }
62
66 real_t width() const noexcept { return width_; }
67
71 real_t height() const noexcept { return metres_per_pixel_ * image_.rows; }
72
76 real_t metres_per_pixel() const noexcept { return metres_per_pixel_; }
77
81 cv::Point2d to_pixel(real_t x, real_t y) const;
82
86 std::array<real_t, 2> to_world(const cv::Point2d &pixel) const;
87
94 real_t reflectance(real_t x, real_t y) const;
95
96 private:
97 cv::Mat image_;
98 real_t width_;
99 real_t metres_per_pixel_;
100};
101
112{
113 public:
117 struct Config
118 {
124
130
135
141
146
150 void read(const nlohmann::json &j);
151 };
152
157
158 explicit DownwardCamera(const Config &config);
159
160 const Config &config() const noexcept { return config_; }
161
166 cv::Mat view(const FloorImage &floor, real_t x, real_t y, real_t yaw) const;
167
173 std::array<real_t, 2> to_robot(real_t column, real_t row) const;
174
185 std::vector<std::array<real_t, 2>> line_points(const cv::Mat &view, uint_t n_bands = 4,
186 real_t dark_ratio = 0.6,
187 real_t min_share = 0.02) const;
188
193 std::array<std::array<real_t, 2>, 4> footprint(real_t x, real_t y, real_t yaw) const;
194
195 private:
196 Config config_;
197};
198
199} // namespace sensors
200} // namespace bitsim
201
202#endif
203#endif // BITSIM_SENSORS_DOWNWARD_CAMERA_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
std::array< real_t, 2 > to_robot(real_t column, real_t row) const
Where a pixel of the camera's image is relative to the robot.
Definition downward_camera.cpp:135
std::vector< std::array< real_t, 2 > > line_points(const cv::Mat &view, uint_t n_bands=4, real_t dark_ratio=0.6, real_t min_share=0.02) const
Where a dark line crosses the camera's image: the image is cut into n_bands bands across the robot's ...
Definition downward_camera.cpp:143
cv::Mat view(const FloorImage &floor, real_t x, real_t y, real_t yaw) const
What the camera sees with the robot at (x, y) heading yaw.
Definition downward_camera.cpp:195
std::array< std::array< real_t, 2 >, 4 > footprint(real_t x, real_t y, real_t yaw) const
The corners of the floor the camera sees, in world coordinates: far left, far right,...
Definition downward_camera.cpp:180
const Config & config() const noexcept
Definition downward_camera.h:160
DownwardCamera()
A camera with the default Config.
Definition downward_camera.cpp:117
An image of the floor, centred on the world origin.
Definition downward_camera.h:31
real_t width() const noexcept
The width of the floor, along x [m].
Definition downward_camera.h:66
real_t reflectance(real_t x, real_t y) const
How bright the floor is at a point, from 0 for black to 1 for white: the brightness of the pixel ther...
Definition downward_camera.cpp:84
std::array< real_t, 2 > to_world(const cv::Point2d &pixel) const
The point of the floor at the given pixel, with fractions.
Definition downward_camera.cpp:78
real_t height() const noexcept
The height of the floor, along y [m].
Definition downward_camera.h:71
FloorImage(const cv::Mat &image, real_t width)
Constructor.
Definition downward_camera.cpp:18
static FloorImage draw(real_t width, real_t height, real_t metres_per_pixel, const std::function< bool(real_t, real_t)> &is_ink, uchar paper=235, uchar ink=25)
Draw a floor: a grey picture of width x height metres of paper, with ink wherever is_ink(x,...
Definition downward_camera.cpp:32
void write_texture(const std::string &path) const
Write the image as a colour PNG, for a texture: Irrlicht reads colour pictures more reliably than gre...
Definition downward_camera.cpp:54
cv::Point2d to_pixel(real_t x, real_t y) const
The pixel, with fractions, at the given point of the floor.
Definition downward_camera.cpp:71
real_t metres_per_pixel() const noexcept
The size of a pixel [m].
Definition downward_camera.h:76
const cv::Mat & image() const noexcept
Definition downward_camera.h:61
Definition infrared_line_follower.h:9
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
The camera's mounting and image.
Definition downward_camera.h:118
real_t update_rate
How many images the camera takes per second [1/s].
Definition downward_camera.h:145
uint_t image_height
Definition downward_camera.h:140
uint_t image_width
The size of the camera's image [pixels].
Definition downward_camera.h:139
real_t view_length
The length of the floor the camera sees along the robot's heading [m].
Definition downward_camera.h:129
void read(const nlohmann::json &j)
Read the values that the json gives.
Definition downward_camera.cpp:107
real_t offset
How far ahead of the reference point the centre of the view is [m].
Definition downward_camera.h:123
real_t view_width
The width of the floor the camera sees across the robot [m].
Definition downward_camera.h:134