checkerboard_unittest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 import roslib; roslib.load_manifest('calibration_estimation')
35 
36 import sys
37 import unittest
38 import rospy
39 import time
40 import numpy
41 
42 from calibration_estimation.checkerboard import Checkerboard
43 from numpy import *
44 
45 class TestCheckerboard(unittest.TestCase):
46  def test_init(self):
47  cb = Checkerboard( {"corners_x": 2,
48  "corners_y": 3,
49  "spacing_x": 10,
50  "spacing_y": 20 } )
51 
52  self.assertEqual(cb._corners_x, 2)
53  self.assertEqual(cb._corners_y, 3)
54  self.assertEqual(cb._spacing_x, 10)
55  self.assertEqual(cb._spacing_y, 20)
56 
58  cb = Checkerboard( {"corners_x": 2,
59  "corners_y": 3,
60  "spacing_x": 10,
61  "spacing_y": 20 } )
62  config = cb.params_to_config( matrix([5,6], float).T )
63  self.assertEquals( config["corners_x"], 2)
64  self.assertEquals( config["corners_y"], 3)
65  self.assertAlmostEquals( config["spacing_x"], 5, 6)
66  self.assertAlmostEquals( config["spacing_y"], 6, 6)
67 
68  def test_deflate(self):
69  cb = Checkerboard()
70  param_vec = matrix([10,20], float).T
71  cb.inflate( param_vec )
72  result = cb.deflate()
73  print ""
74  print result
75  self.assertAlmostEqual(numpy.linalg.norm(result - param_vec), 0.0, 6)
76 
78  cb = Checkerboard({"corners_x": 2,
79  "corners_y": 3,
80  "spacing_x": 10,
81  "spacing_y": 20 })
82  result = cb.generate_points()
83  expected = matrix( [ [ -5, 5, -5, 5, -5, 5],
84  [ 20, 20, 0, 0,-20,-20],
85  [ 0, 0, 0, 0, 0, 0],
86  [ 1, 1, 1, 1, 1, 1] ], float)
87  print ""
88  print result
89  self.assertAlmostEqual(numpy.linalg.norm(result - expected), 0.0, 6)
90 
91  def test_get_length(self):
92  cb = Checkerboard()
93  self.assertEqual(cb.get_length(), 2)
94 
95 if __name__ == '__main__':
96  import rostest
97  rostest.unitrun('calibration_estimation', 'test_Checkerboard', TestCheckerboard, coverage_packages=['calibration_estimation.checkerboard'])


calibration_estimation
Author(s): Vijay Pradeep, Michael Ferguson
autogenerated on Fri Apr 2 2021 02:12:53