checkerboard.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2008, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import numpy
00034 from numpy import matrix, vsplit, sin, cos, reshape
00035 import rospy
00036 
00037 param_names = ['spacing_x', 'spacing_y']
00038 
00039 class Checkerboard:
00040     '''
00041     Primitive for generating 3D points of a checkerboard.
00042     '''
00043 
00044     # Dictionary with four elems
00045     #  num_x:   number of internal corners along x axis (Not configurable)
00046     #  num_y:   number of internal corners along y axis (Not configurable)
00047     #  width_x: spacing between corners along x direction
00048     #  width_y: spacing between corners along y direction
00049     def __init__(self, config = {'corners_x': 2,
00050                                  'corners_y': 2,
00051                                  'spacing_x': .10,
00052                                  'spacing_y': .10} ):
00053         rospy.logdebug('Initializing Checkerboard')
00054         self._corners_x = config['corners_x']
00055         self._corners_y = config['corners_y']
00056 
00057         param_vec = reshape( matrix([ config['spacing_x'], config['spacing_y'] ], float), (-1,1))
00058         self.inflate(param_vec)
00059 
00060     def calc_free(self, free_config):
00061         return [free_config[x] == 1 for x in param_names]
00062 
00063     def params_to_config(self, param_vec):
00064         return { 'corners_x' : self._corners_x,
00065                  'corners_y' : self._corners_y,
00066                  'spacing_x' : float(param_vec[0,0]),
00067                  'spacing_y' : float(param_vec[1,0]) }
00068 
00069     # Convert column vector of params into config
00070     def inflate(self, param_vec):
00071         self._spacing_x = param_vec[0,0]
00072         self._spacing_y = param_vec[1,0]
00073 
00074     # Return column vector of config
00075     def deflate(self):
00076         param_vec = reshape(matrix( [self._spacing_x, self._spacing_y], float ), (-1,1))
00077         return param_vec
00078 
00079     # Returns # of params needed for inflation & deflation
00080     def get_length(self):
00081         return len(param_names)
00082 
00083     # Generate the 3D points associated with all the corners of the checkerboard
00084     # returns - 4xN numpy matrix with all the points (in homogenous coords)
00085     def generate_points(self):
00086         N = self._corners_x * self._corners_y
00087         pts = matrix(numpy.zeros((4,N), float))
00088         for y in range(0,self._corners_y):
00089             for x in range(0,self._corners_x):
00090                 n = y*self._corners_x + x
00091                 pts[:,n] = numpy.matrix([ [(x-float(self._corners_x-1)/2) * self._spacing_x],
00092                                           [-1*(y-float(self._corners_y-1)/2) * self._spacing_y],
00093                                           [0],
00094                                           [1] ])
00095         return pts
00096 


calibration_estimation
Author(s): Vijay Pradeep, Michael Ferguson
autogenerated on Wed Aug 26 2015 10:56:21