Fawkes API  Fawkes Development Version
firevision::MirrorCalibTool Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MirrorCalibTool()

firevision::MirrorCalibTool::MirrorCalibTool ( )

Constructor.

Definition at line 937 of file mirror_calib.cpp.

◆ ~MirrorCalibTool()

firevision::MirrorCalibTool::~MirrorCalibTool ( )

Destructor.

Definition at line 949 of file mirror_calib.cpp.

References fawkes::deg2rad(), and fawkes::normalize_rad().

Member Function Documentation

◆ abort()

◆ center_x()

int firevision::MirrorCalibTool::center_x ( ) const
inline

Center X accessor.

Returns
center X value

Definition at line 76 of file mirror_calib.h.

◆ center_y()

int firevision::MirrorCalibTool::center_y ( ) const
inline

Center Y accessor.

Returns
center Y value

Definition at line 79 of file mirror_calib.h.

References eval(), load(), and save().

◆ draw_crosshair()

void firevision::MirrorCalibTool::draw_crosshair ( unsigned char *  yuv_buffer,
int  center_x,
int  center_y,
int  width,
int  height 
)
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.

Parameters
yuv_bufferThe in/out parameter for the image.
center_xX-coordinate of center point in image pixels.
center_yY-coordinate of center point in image pixels.
widthWidth of image.
heightHeight 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().

◆ draw_line()

void firevision::MirrorCalibTool::draw_line ( unsigned char *  yuv_buffer,
double  angle_deg,
int  center_x,
int  center_y,
int  width,
int  height 
)
static

Draws a line from the image center in the given angle.

Parameters
yuv_bufferThe in/out parameter for the image.
angle_degAngle of line in degrees.
center_xX-coordinate of center point in image pixels.
center_yY-coordinate of center point in image pixels.
widthWidth of image.
heightHeight 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().

◆ draw_mark_lines()

void firevision::MirrorCalibTool::draw_mark_lines ( unsigned char *  yuv_buffer)

◆ eval()

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.

Parameters
xThe X coordinate of the pixel that is to be evaluated.
yThe Y coordinate of the pixel that is to be evaluated.
dist_retThe distance in the real world to the pixel.
ori_retThe 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().

◆ get_last_yuv_buffer()

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.

Returns
most recent result's YUV buffer

Definition at line 1928 of file mirror_calib.cpp.

Referenced by next_step().

◆ get_state_description()

◆ load()

void firevision::MirrorCalibTool::load ( const char *  filename)

Loads a calibration file.

Parameters
filenameName of the file containing the calibration data.

Definition at line 1960 of file mirror_calib.cpp.

Referenced by center_y().

◆ load_mask()

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.

Parameters
mask_file_nameThe 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().

◆ next_step()

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().

◆ push_back()

void firevision::MirrorCalibTool::push_back ( const unsigned char *  yuv_buffer,
size_t  buflen,
int  width,
int  height,
double  ori 
)

Store image for calibration process.

Parameters
yuv_bufferThe image's yuv_buffer. It may be freeed by the caller immediately, the MirrorCalibTool works with a copy of it.
buflenThe length of yuv_buffer.
widthThe width of the image.
heightThe height of the image.
oriThe 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.

◆ save()

void firevision::MirrorCalibTool::save ( const char *  filename)

Saves calibration data to a file.

Parameters
filenameThe 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().

◆ set_center()

void firevision::MirrorCalibTool::set_center ( int  x,
int  y 
)
inline

Sets preliminary center point.

Parameters
xX-coordinate
yY-coordinate

Definition at line 69 of file mirror_calib.h.


The documentation for this class was generated from the following files: