00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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( [ [ -5, 5, -5, 5, -5, 5],
00084 [ 20, 20, 0, 0,-20,-20],
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'])