Fawkes API
Fawkes Development Version
|
This class encapsulates the routines necessary for interactive mirror calibration. More...
#include <mirror_calib.h>
Classes | |
class | CartesianImage |
Wraps an image so that access to (0, 0) is mapped to the middle of the image and so on. More... | |
class | CartesianPoint |
A cartesian point is a 2d point which can have negative X and Y coords. More... | |
class | Hole |
A hole is a sequence of pixels between two lines. More... | |
class | Image |
A container for a YUV-buffer etc. More... | |
class | PixelPoint |
A pixel point is a 2d point with positive X and Y coords. More... | |
class | Point |
Abstract Point class. More... | |
class | StepResult |
The result of a step contains a YUV buffer. More... | |
Public Member Functions | |
void | draw_mark_lines (unsigned char *yuv_buffer) |
Draws a crosshair with the lines in the directions of the keys of the mark map. More... | |
MirrorCalibTool () | |
Constructor. More... | |
~MirrorCalibTool () | |
Destructor. More... | |
void | load_mask (const char *mask_file_name) |
Loads a PNM mask file for the robot's bars. More... | |
void | push_back (const unsigned char *yuv_buffer, size_t buflen, int width, int height, double ori) |
Store image for calibration process. More... | |
void | abort () |
Aborts the calibration process. More... | |
void | next_step () |
Performs one step in the calibration process. More... | |
const unsigned char * | get_last_yuv_buffer () const |
Get last created YUV buffer. More... | |
const char * | get_state_description () const |
Get description of next step. More... | |
void | set_center (int x, int y) |
Sets preliminary center point. More... | |
int | center_x () const |
Center X accessor. More... | |
int | center_y () const |
Center Y accessor. More... | |
void | eval (unsigned int x, unsigned int y, float *x_ret, float *y_ret) |
Get the assumed distance and orientation of a pixel point. More... | |
void | load (const char *filename) |
Loads a calibration file. More... | |
void | save (const char *filename) |
Saves calibration data to a file. More... | |
Static Public Member Functions | |
static void | draw_line (unsigned char *yuv_buffer, double angle_deg, int center_x, int center_y, int width, int height) |
Draws a line from the image center in the given angle. More... | |
static void | draw_crosshair (unsigned char *yuv_buffer, int center_x, int center_y, int width, int height) |
Draws a crosshair in the YUV-buffer. More... | |
This class encapsulates the routines necessary for interactive mirror calibration.
The input is N pairs (degree,image) and (optionally) a filter mask. The calibration runs in multiple phases: (1) Edge detection. (2) Assume center point in the middle of the image unless it is set explicitly. (3) Pre-marking: Find the edges that lie at `degree' wrt. Y axis in image. (4) Final marking: Try to filter false-positive marks. (5) Centering: Average the first marks in each direction to get the `real' center point of the mirror. (6) Again do steps (3) and (5) with the new center point. (7) Generate bulb files. The polar coordinates of each pixel are determined as follows: (a) Determine the polar coordinates of the pixel. (b) Get the two mark streams that enclose the pixel. (c) Do linear interpolation in both mark streams to get two distances. (d) Add the weightened distances (the nearer the pixel is to the mark stream the higher is its weight). (e) Now we have an estimated distance. We need to multiply the angle with -1.0 (!!!) to consider the fact that the image is mirrored: what looks to left from the robot on the image, is on the right of the robot in reality! Note that all the time we worked on the mirrored image with angles that were correct from the perspective of the image. But to make them correct from the perspective of the robot, we have to mirror everything.
Definition at line 43 of file mirror_calib.h.
firevision::MirrorCalibTool::MirrorCalibTool | ( | ) |
Constructor.
Definition at line 937 of file mirror_calib.cpp.
firevision::MirrorCalibTool::~MirrorCalibTool | ( | ) |
Destructor.
Definition at line 949 of file mirror_calib.cpp.
References fawkes::deg2rad(), and fawkes::normalize_rad().
void firevision::MirrorCalibTool::abort | ( | ) |
Aborts the calibration process.
Definition at line 1057 of file mirror_calib.cpp.
References firevision::FilterMin::apply(), firevision::FilterSharpen::apply(), firevision::FilterMedian::apply(), firevision::FilterOr::apply(), firevision::FilterSobel::apply(), firevision::ROI::full_image(), firevision::Filter::set_dst_buffer(), and firevision::Filter::set_src_buffer().
|
inline |
|
inline |
|
static |
Draws a crosshair in the YUV-buffer.
The crosshair consists of three lines from the origin (0, 0) with the angles 0 degree, 120 degrees, 240 degrees.
yuv_buffer | The in/out parameter for the image. |
center_x | X-coordinate of center point in image pixels. |
center_y | Y-coordinate of center point in image pixels. |
width | Width of image. |
height | Height of image. |
Definition at line 2047 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::CartesianImage::contains(), fawkes::deg2rad(), firevision::MirrorCalibTool::CartesianImage::max_radius(), fawkes::normalize_rad(), and firevision::MirrorCalibTool::CartesianImage::set_color().
|
static |
Draws a line from the image center in the given angle.
yuv_buffer | The in/out parameter for the image. |
angle_deg | Angle of line in degrees. |
center_x | X-coordinate of center point in image pixels. |
center_y | Y-coordinate of center point in image pixels. |
width | Width of image. |
height | Height of image. |
Definition at line 1992 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::CartesianImage::contains(), fawkes::deg2rad(), firevision::MirrorCalibTool::CartesianImage::max_radius(), fawkes::normalize_rad(), and firevision::MirrorCalibTool::CartesianImage::set_color().
void firevision::MirrorCalibTool::draw_mark_lines | ( | unsigned char * | yuv_buffer | ) |
Draws a crosshair with the lines in the directions of the keys of the mark map.
yuv_buffer | The in/out parameter for the image. |
Definition at line 2018 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::CartesianImage::contains(), firevision::MirrorCalibTool::Image::height(), firevision::MirrorCalibTool::CartesianImage::max_radius(), firevision::MirrorCalibTool::Image::ori(), firevision::MirrorCalibTool::CartesianImage::set_color(), and firevision::MirrorCalibTool::Image::width().
void firevision::MirrorCalibTool::eval | ( | unsigned int | x, |
unsigned int | y, | ||
float * | dist_ret, | ||
float * | ori_ret | ||
) |
Get the assumed distance and orientation of a pixel point.
x | The X coordinate of the pixel that is to be evaluated. |
y | The Y coordinate of the pixel that is to be evaluated. |
dist_ret | The distance in the real world to the pixel. |
ori_ret | The orientation in the real world to the pixel. |
Definition at line 1941 of file mirror_calib.cpp.
References firevision::Bulb::getWorldPointRelative(), fawkes::polar_coord_2d_t::phi, and fawkes::polar_coord_2d_t::r.
Referenced by center_y().
const unsigned char * firevision::MirrorCalibTool::get_last_yuv_buffer | ( | ) | const |
Get last created YUV buffer.
This is the result of the most recent step. Memory management is done by MirrorCalibTool.
Definition at line 1928 of file mirror_calib.cpp.
Referenced by next_step().
const char * firevision::MirrorCalibTool::get_state_description | ( | ) | const |
Get description of next step.
Definition at line 1198 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::Hole::from_length, firevision::MirrorCalibTool::CartesianImage::highlight_line(), firevision::MirrorCalibTool::CartesianImage::highlight_point(), firevision::MirrorCalibTool::CartesianImage::is_line(), firevision::MirrorCalibTool::CartesianImage::max_radius(), firevision::MirrorCalibTool::Image::results(), firevision::MirrorCalibTool::Hole::size(), and firevision::MirrorCalibTool::Hole::to_length.
Referenced by next_step().
void firevision::MirrorCalibTool::load | ( | const char * | filename | ) |
Loads a calibration file.
filename | Name of the file containing the calibration data. |
Definition at line 1960 of file mirror_calib.cpp.
Referenced by center_y().
void firevision::MirrorCalibTool::load_mask | ( | const char * | mask_file_name | ) |
Loads a PNM mask file for the robot's bars.
The mask is used to ignore those pixels that are part of the robot's bar.
mask_file_name | The mask file name. |
Definition at line 1005 of file mirror_calib.cpp.
References firevision::PNMReader::colorspace(), firevision::PNMReader::pixel_height(), firevision::PNMReader::pixel_width(), firevision::PNMReader::read(), and firevision::PNMReader::set_buffer().
void firevision::MirrorCalibTool::next_step | ( | ) |
Performs one step in the calibration process.
In each step, a filter is applied to the image. The resulting image of the n-th step is stored in the stepResults-vector on the (n-1)-th position.
Definition at line 1465 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::Image::add_result(), firevision::MirrorCalibTool::Point::atan(), firevision::MirrorCalibTool::StepResult::buflen(), firevision::MirrorCalibTool::Image::buflen(), get_last_yuv_buffer(), get_state_description(), firevision::MirrorCalibTool::StepResult::height(), firevision::MirrorCalibTool::Image::height(), firevision::MirrorCalibTool::CartesianImage::highlight_pixel(), firevision::MirrorCalibTool::CartesianImage::highlight_point(), firevision::MirrorCalibTool::Point::length(), firevision::MirrorCalibTool::Image::marks(), fawkes::normalize_mirror_rad(), fawkes::normalize_rad(), firevision::MirrorCalibTool::Image::ori(), firevision::MirrorCalibTool::Image::premarks(), fawkes::rad2deg(), firevision::MirrorCalibTool::Image::result(), firevision::MirrorCalibTool::Image::results(), firevision::MirrorCalibTool::Image::set_marks(), firevision::MirrorCalibTool::Image::set_premarks(), firevision::Bulb::setCenter(), firevision::Bulb::setOrientation(), firevision::Bulb::setWorldPoint(), firevision::MirrorCalibTool::CartesianImage::to_cartesian(), firevision::MirrorCalibTool::CartesianImage::to_pixel(), firevision::MirrorCalibTool::StepResult::width(), firevision::MirrorCalibTool::Image::width(), firevision::MirrorCalibTool::Point::x, firevision::MirrorCalibTool::Point::y, firevision::MirrorCalibTool::StepResult::yuv_buffer(), and firevision::MirrorCalibTool::Image::yuv_buffer().
void firevision::MirrorCalibTool::push_back | ( | const unsigned char * | yuv_buffer, |
size_t | buflen, | ||
int | width, | ||
int | height, | ||
double | ori | ||
) |
Store image for calibration process.
yuv_buffer | The image's yuv_buffer. It may be freeed by the caller immediately, the MirrorCalibTool works with a copy of it. |
buflen | The length of yuv_buffer. |
width | The width of the image. |
height | The height of the image. |
ori | The polar angle in degrees (!) relative to the Y axis of the image (!) where the marks are in the image (!) (not in in reality from the robot's perspective). |
Definition at line 1037 of file mirror_calib.cpp.
void firevision::MirrorCalibTool::save | ( | const char * | filename | ) |
Saves calibration data to a file.
filename | The name of the file. |
Definition at line 1970 of file mirror_calib.cpp.
References firevision::MirrorCalibTool::Image::height(), firevision::Bulb::save(), and firevision::MirrorCalibTool::Image::width().
Referenced by center_y().
|
inline |
Sets preliminary center point.
x | X-coordinate |
y | Y-coordinate |
Definition at line 69 of file mirror_calib.h.