1- import copy
1+
22import unittest
33
44import numpy as np
55
6- from openptv_python .calibration import Calibration , Interior
6+ from openptv_python .calibration import Calibration , interior_dtype
77from openptv_python .parameters import ControlPar
88from openptv_python .trafo import (
99 dist_to_flat ,
@@ -19,48 +19,47 @@ class TestFlatToDist(unittest.TestCase):
1919 """Test the flat_to_dist function."""
2020
2121 def setUp (self ):
22- self .cal = Calibration ()
23- print (f" k1 = { self .cal .added_par .k1 } " )
24-
2522 self .cpar = ControlPar ()
2623 self .cpar .imx = 1024
2724 self .cpar .imy = 1008
2825 self .cpar .pix_x = 0.010
2926 self .cpar .pix_y = 0.010
3027
3128 def test_zero_coordinates (self ):
32- dist_x , dist_y = flat_to_dist (0 , 0 , self .cal )
29+ """Test the case when the input coordinates are zero."""
30+ cal = Calibration ()
31+ dist_x , dist_y = flat_to_dist (0 , 0 , cal )
3332 self .assertEqual (dist_x , 0 )
3433 self .assertEqual (dist_y , 0 )
3534
3635 def test_positive_coordinates (self ):
37- cal = copy .copy (self .cal )
36+ """Test the case when the input coordinates are positive."""
37+ cal = Calibration ()
3838 cal .int_par .xh = 100
3939 cal .int_par .yh = 50
40- print ("inside test_positive_coordinates\n " )
41- print (f"cal.added_par.k1 = { cal .added_par .k1 } \n " )
42- print (f"self.cal.added_par.k1 = { self .cal .added_par .k1 } \n " )
4340 dist_x , dist_y = flat_to_dist (50 , 25 , cal )
4441 self .assertEqual (dist_x , 150 )
4542 self .assertEqual (dist_y , 75 )
4643
4744 def test_distortion (self ):
48- cal = copy .copy (self .cal )
49- cal .set_added_par (np .array ([1e-5 , 0 , 0 , 0 , 0 , 1 , 0 ]))
45+ """Test the case when the distortion is not zero."""
46+ cal = Calibration ()
47+ cal .set_added_par (np .array ([1e-5 , 0 , 0 , 0 , 0 , 1 , 0 ], dtype = np .float64 ))
5048 dist_x , dist_y = flat_to_dist (100 , 200 , cal )
5149 self .assertAlmostEqual (dist_x , 150 , places = 3 )
5250 self .assertAlmostEqual (dist_y , 300 , places = 3 )
5351
5452 def test_pixel_to_metric_and_back (self ):
55- cpar = copy . copy ( self . cpar )
56- cpar .from_file ("tests/testing_folder/control_parameters/control.par" )
53+ """Test the pixel_to_metric and metric_to_pixel functions."""
54+ cpar = ControlPar () .from_file ("tests/testing_folder/control_parameters/control.par" )
5755
5856 x , y = metric_to_pixel (1 , 1 , cpar )
5957 x , y = pixel_to_metric (x , y , cpar )
6058 self .assertTrue (abs (x - 1 ) < EPS )
6159 self .assertTrue (abs (y - 1 ) < EPS )
6260
6361 def test_0_0 (self ):
62+ """Test the case when the input coordinates are zero."""
6463 xc = 0.0
6564 yc = 0.0
6665
@@ -71,6 +70,7 @@ def test_0_0(self):
7170 self .assertTrue (abs (yc1 - yc ) < EPS )
7271
7372 def test_1_0 (self ):
73+ """Test the case when the input coordinates are (1, 0)."""
7474 xc = 1.0
7575 yc = 0.0
7676
@@ -81,6 +81,7 @@ def test_1_0(self):
8181 self .assertTrue (abs (yc1 - yc ) < EPS )
8282
8383 def test_0_neg1 (self ):
84+ """Test the case when the input coordinates are (0, -1)."""
8485 xc = 0.0
8586 yc = - 1.0
8687
@@ -91,6 +92,7 @@ def test_0_neg1(self):
9192 self .assertTrue (abs (yc1 - yc ) < EPS )
9293
9394 def dist_flat_round_trip (self ):
95+ """Test the round trip from flat to distorted and back."""
9496 # /* Cheks that the order of operations in converting metric flat image to
9597 # distorted image coordinates and vice-versa is correct.
9698
@@ -104,9 +106,9 @@ def dist_flat_round_trip(self):
104106 y = 10.0
105107 iter_eps = 1e-5
106108
107- cal = copy . copy ( self . cal )
108- cal .int_par = Interior ( 1.5 , 1.5 , 60.0 )
109- cal .set_added_par ([0.0005 , 0 , 0 , 0 , 0 , 1 , 0 ])
109+ cal = Calibration ( )
110+ cal .int_par = np . array ( ( 1.5 , 1.5 , 60.0 ), dtype = interior_dtype ). view ( np . recarray )
111+ cal .set_added_par (np . array ( [0.0005 , 0 , 0 , 0 , 0 , 1 , 0 ], dtype = np . float64 ) )
110112
111113 xres , yres = flat_to_dist (x , y , cal )
112114 xres , yres = dist_to_flat (xres , yres , cal , 0.00001 )
0 commit comments