checkerboard_unittest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import roslib; roslib.load_manifest('calibration_estimation')
00035 
00036 import sys
00037 import unittest
00038 import rospy
00039 import time
00040 import numpy
00041 
00042 from calibration_estimation.checkerboard import Checkerboard
00043 from numpy import *
00044 
00045 class TestCheckerboard(unittest.TestCase):
00046     def test_init(self):
00047         cb = Checkerboard( {"corners_x": 2,
00048                             "corners_y": 3,
00049                             "spacing_x": 10,
00050                             "spacing_y": 20 } )
00051 
00052         self.assertEqual(cb._corners_x, 2)
00053         self.assertEqual(cb._corners_y, 3)
00054         self.assertEqual(cb._spacing_x, 10)
00055         self.assertEqual(cb._spacing_y, 20)
00056 
00057     def test_params_to_config(self):
00058         cb = Checkerboard( {"corners_x": 2,
00059                             "corners_y": 3,
00060                             "spacing_x": 10,
00061                             "spacing_y": 20 } )
00062         config = cb.params_to_config( matrix([5,6], float).T )
00063         self.assertEquals( config["corners_x"], 2)
00064         self.assertEquals( config["corners_y"], 3)
00065         self.assertAlmostEquals( config["spacing_x"], 5, 6)
00066         self.assertAlmostEquals( config["spacing_y"], 6, 6)
00067 
00068     def test_deflate(self):
00069         cb = Checkerboard()
00070         param_vec = matrix([10,20], float).T
00071         cb.inflate( param_vec )
00072         result = cb.deflate()
00073         print ""
00074         print result
00075         self.assertAlmostEqual(numpy.linalg.norm(result - param_vec), 0.0, 6)
00076 
00077     def test_generate_points(self):
00078         cb = Checkerboard({"corners_x":  2,
00079                             "corners_y": 3,
00080                             "spacing_x": 10,
00081                             "spacing_y": 20 })
00082         result = cb.generate_points()
00083         expected = matrix( [ [ 0, 10,   0, 10,  0, 10],
00084                              [ 0,  0,  20, 20, 40, 40],
00085                              [ 0,  0,   0,  0,  0,  0],
00086                              [ 1,  1,   1,  1,  1,  1] ], float)
00087         print ""
00088         print result
00089         self.assertAlmostEqual(numpy.linalg.norm(result - expected), 0.0, 6)
00090 
00091     def test_get_length(self):
00092         cb = Checkerboard()
00093         self.assertEqual(cb.get_length(), 2)
00094 
00095 if __name__ == '__main__':
00096     import rostest
00097     rostest.unitrun('calibration_estimation', 'test_Checkerboard', TestCheckerboard, coverage_packages=['calibration_estimation.checkerboard'])
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


calibration_estimation
Author(s): Vijay Pradeep, Michael Ferguson
autogenerated on Thu Aug 15 2013 10:15:40