Skip to content

Commit 04bfaa8

Browse files
committed
Create test_calibration_optimize.ipynb
1 parent 15ae103 commit 04bfaa8

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 5,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# test calibration using scipy.optimize\n",
10+
"\n",
11+
"import numpy as np\n",
12+
"import scipy.optimize as opt"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 6,
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"import unittest\n",
22+
"\n",
23+
"import numpy as np\n",
24+
"\n",
25+
"from openptv_python.calibration import (\n",
26+
" Calibration,\n",
27+
")\n",
28+
"from openptv_python.imgcoord import image_coordinates\n",
29+
"from openptv_python.orientation import (\n",
30+
" external_calibration,\n",
31+
")\n",
32+
"from openptv_python.parameters import ControlPar, OrientPar, VolumePar, read_control_par\n",
33+
"from openptv_python.tracking_frame_buf import TargetArray\n",
34+
"from openptv_python.trafo import arr_metric_to_pixel"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 7,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"class TestGradientDescent(unittest.TestCase):\n",
44+
" # Based on the C tests in liboptv/check_orientation.c\n",
45+
"\n",
46+
" def setUp(self):\n",
47+
" control_file_name = \"testing_folder/corresp/control.par\"\n",
48+
" # self.control = ControlPar(4)\n",
49+
" self.control = read_control_par(control_file_name)\n",
50+
"\n",
51+
" self.orient_par_file_name = \"testing_folder/corresp/orient.par\"\n",
52+
" self.orient_par = OrientPar().from_file(self.orient_par_file_name)\n",
53+
"\n",
54+
" self.cal = Calibration().from_file(\n",
55+
" \"testing_folder/calibration/cam1.tif.ori\",\n",
56+
" \"testing_folder/calibration/cam1.tif.addpar\",\n",
57+
" )\n",
58+
" self.orig_cal = Calibration().from_file(\n",
59+
" \"testing_folder/calibration/cam1.tif.ori\",\n",
60+
" \"testing_folder/calibration/cam1.tif.addpar\",\n",
61+
" )\n",
62+
"\n",
63+
" \n",
64+
" def test_external_calibration(self):\n",
65+
" \"\"\"External calibration using clicked points.\"\"\"\n",
66+
" ref_pts = np.array(\n",
67+
" [\n",
68+
" [-40.0, -25.0, 8.0],\n",
69+
" [40.0, -15.0, 0.0],\n",
70+
" [40.0, 15.0, 0.0],\n",
71+
" [40.0, 0.0, 8.0],\n",
72+
" ]\n",
73+
" )\n",
74+
"\n",
75+
" # Fake the image points by back-projection\n",
76+
" targets = arr_metric_to_pixel(\n",
77+
" image_coordinates(ref_pts, self.cal, self.control.mm),\n",
78+
" self.control,\n",
79+
" )\n",
80+
"\n",
81+
" # Jigg the fake detections to give raw_orient some challenge.\n",
82+
" targets[:, 1] -= 0.1\n",
83+
"\n",
84+
" self.assertTrue(external_calibration(self.cal, ref_pts, targets, self.control))\n",
85+
" np.testing.assert_array_almost_equal(\n",
86+
" self.cal.get_angles(), self.orig_cal.get_angles(), decimal=3\n",
87+
" )\n",
88+
" np.testing.assert_array_almost_equal(\n",
89+
" self.cal.get_pos(), self.orig_cal.get_pos(), decimal=3\n",
90+
" )"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 8,
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"name": "stderr",
100+
"output_type": "stream",
101+
"text": [
102+
"test_external_calibration (__main__.TestGradientDescent)\n",
103+
"External calibration using clicked points. ... ok\n",
104+
"\n",
105+
"----------------------------------------------------------------------\n",
106+
"Ran 1 test in 0.120s\n",
107+
"\n",
108+
"OK\n"
109+
]
110+
},
111+
{
112+
"name": "stdout",
113+
"output_type": "stream",
114+
"text": [
115+
"Coefficients (beta): [ 1.80534911e-04 -6.77499328e-05 -6.52416361e-04 -1.77426081e-05\n",
116+
" -1.31470856e-07 4.02517087e-06]\n",
117+
"Residuals: []\n",
118+
"rank: 6\n",
119+
"singular_values: None\n"
120+
]
121+
},
122+
{
123+
"data": {
124+
"text/plain": [
125+
"<unittest.main.TestProgram at 0x7f10eb2886a0>"
126+
]
127+
},
128+
"execution_count": 8,
129+
"metadata": {},
130+
"output_type": "execute_result"
131+
}
132+
],
133+
"source": [
134+
"unittest.main(argv=[''], verbosity=2, exit=False)"
135+
]
136+
}
137+
],
138+
"metadata": {
139+
"kernelspec": {
140+
"display_name": "openptvpy",
141+
"language": "python",
142+
"name": "python3"
143+
},
144+
"language_info": {
145+
"codemirror_mode": {
146+
"name": "ipython",
147+
"version": 3
148+
},
149+
"file_extension": ".py",
150+
"mimetype": "text/x-python",
151+
"name": "python",
152+
"nbconvert_exporter": "python",
153+
"pygments_lexer": "ipython3",
154+
"version": "3.10.9"
155+
}
156+
},
157+
"nbformat": 4,
158+
"nbformat_minor": 2
159+
}

0 commit comments

Comments
 (0)