Robot Localization
|
Classes | |
class | Camera |
This class contains the camera's intrinsic and extrinsic parameters and the functions used for calibration. More... | |
class | Image |
The class Image contains all image- and object space positions of the reference points and the robot location in the respective images. More... | |
Functions | |
def | combinations (array, number) |
returns vector with all possible camera combinations of specified length (in vector) | |
def | get_param () |
returns parameters from command line | |
def | get_leastsquares (cam, pt, method='hz', r_height='', p_real='') |
Solve least squares problem for point position with or without fixed height. More... | |
def | get_leastsquares_combinations (n_cameras, numbers, cam, pt, method='hz', r_height='', p_real='') |
Applies get_leastsquares function to all possible combinations of length "number" made of elements of "n_cameras". More... | |
def | get_best_combination (crit) |
get best camera combination based on criterium "crit" (err2D or err3D) | |
def | save_combinations (out_dir, fname, arrs, pts, errs, errors='', title='') |
Saves obtained 2D and 3D errors in .png and textfile. More... | |
def | triangulate (P1, P2, i1, i2, p_real='') |
Performs triangulation with cv2-function triangulatePoints. More... | |
def | change_wall_to_ref (pts_basis, margin, pt_wall) |
Change of basis from wall to reference points. More... | |
def | change_ref_to_wall (pts_basis, margin, pt_ref) |
inverse of change_wall_to_ref | |
def | write_ref (dirname, name, pts_img, M, pts_obj) |
Save reference points positions in file, overwriting old results. More... | |
def | write_pos (dirname, name, p) |
Save robot position (img,obj or real) in file, appending to old results. More... | |
Contains Image and Camera classes.
Contains all functions necessary for intrinsic and extrinsic camera calibration, including the triangulation between cameras for 3D reconstruction.
All functions using more than one camera are not owned by an object.
created by Frederike Duembgen, August 2015
def calibrate.change_wall_to_ref | ( | pts_basis, | |
margin, | |||
pt_wall | |||
) |
Change of basis from wall to reference points.
Parameters: (all distances in mm)
pts_basis: list of positions of first and second reference points in wall
reference. ([x1,y1],[x2,y2])
margin: margin from leftmost and downmost reference points to new reference.
pt_wall: position of point in wall reference
Returns:
position of point in reference point basis (in meters)
def calibrate.get_leastsquares | ( | cam, | |
pt, | |||
method = 'hz' , |
|||
r_height = '' , |
|||
p_real = '' |
|||
) |
Solve least squares problem for point position with or without fixed height.
Parameters:
cam: nparray of Camera objects used for triangulation
pt: nparray of points to be measured
method: 'hz' (default) uses Hartley Zisserman Aglorithm, 'my' uses own algorithm. Only use 'hz' only!
r_height: real height of robot in mm. if specified, the fixed height algorithm is used.
p_real: nparray of real position of robot (3x1), for error calculation only. default '' returns err2=err3=0.
Returns:
x: nparray of real positions of points. Size 3xN_pts
err2: nparray of 2D errors. Size 1xN_pts
err3: nparray of 3D errors. Size 1xN_pts
def calibrate.get_leastsquares_combinations | ( | n_cameras, | |
numbers, | |||
cam, | |||
pt, | |||
method = 'hz' , |
|||
r_height = '' , |
|||
p_real = '' |
|||
) |
Applies get_leastsquares function to all possible combinations of length "number" made of elements of "n_cameras".
Parameters:
n_cameras: array of cameras to be tested (e.g. [139,141,145])
numbers: array of numbers of cameras to be tested.
cam: list of corresponding camera instances
pt: vector of augmented image positions of point to be triangulated (matrix with [x,y,1]) in all cameras
method: method to be used in leastsquares (with or without fixed height), see get_leastsquares() for more details.
r_height: real height of point (if known)
p_real: real position of point (if known)
Returns:
pts: 3D position
2D: 2D error
3D: 3D error
arrs: list of camera number combination
def calibrate.save_combinations | ( | out_dir, | |
fname, | |||
arrs, | |||
pts, | |||
errs, | |||
errors = '' , |
|||
title = '' |
|||
) |
Saves obtained 2D and 3D errors in .png and textfile.
Parameters:
out_dir: output directory
fname: file name
arrs: list of used camera combinations
pts: array with estimated positions for all camera combinations
errs: array with errors for all camera combinations
Returns:
Nothing
def calibrate.triangulate | ( | P1, | |
P2, | |||
i1, | |||
i2, | |||
p_real = '' |
|||
) |
Performs triangulation with cv2-function triangulatePoints.
Parameters:
P1,P2: camera Projection matrixes
i1,i2: point image positions in 2 cameras
p_real: real position of point (if known), for error calculation
Returns:
position of corresponding 3D point, 2D and 3D error.
def calibrate.write_pos | ( | dirname, | |
name, | |||
p | |||
) |
Save robot position (img,obj or real) in file, appending to old results.
Parameters:
dirname = directory
name = name of file
p = np array with robot position (x,y)
Returns: Nothing
def calibrate.write_ref | ( | dirname, | |
name, | |||
pts_img, | |||
M, | |||
pts_obj | |||
) |
Save reference points positions in file, overwriting old results.
Parameters:
dirname = directory
name = name of file
pts_img = np array with image positions of reference points.
M = geometric transformation np matrix(3x3) obtained from geometric_transformationN
pts_obj = np array with object positions of reference points
format of pts_img, pts_obj: row i: (pi_x, pi_y) with i going from 1 to m (m = number of reference points)
Returns: Nothing