├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── calib_data ├── ground_truth │ ├── 1 │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── 2 │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── 3 │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ └── 5.png │ ├── calibration_pattern.blend │ ├── calibration_pattern_1.blend │ ├── calibration_pattern_2.blend │ └── calibration_pattern_3.blend └── zhang_data │ ├── data1.txt │ ├── data2.txt │ ├── data3.txt │ ├── data4.txt │ ├── data5.txt │ └── model.txt ├── scripts ├── blender_test.py └── camera.py ├── src ├── calib.cpp ├── calib.hpp ├── calibpattern.cpp ├── calibpattern.hpp ├── homography.cpp ├── homography.hpp ├── main.cpp ├── optimize.cpp └── optimize.hpp └── tests ├── 600D ├── 600D_1.log ├── im_files.txt ├── pattern.txt ├── real_data.txt ├── reprojection_0.png ├── reprojection_1.png ├── reprojection_2.png ├── reprojection_3.png ├── reprojection_4.png ├── reprojection_5.png ├── reprojection_6.png ├── reprojection_7.png └── reprojection_8.png ├── GT-I9300 ├── apect_ratio_fixed │ ├── GT-I9300_3.log │ ├── reprojection_0.png │ ├── reprojection_1.png │ ├── reprojection_2.png │ ├── reprojection_3.png │ ├── reprojection_4.png │ ├── reprojection_5.png │ ├── reprojection_6.png │ ├── reprojection_7.png │ ├── reprojection_8.png │ └── reprojection_9.png ├── aspect_ratio_free │ ├── GT-I9300_2.log │ ├── reprojection_0.png │ ├── reprojection_1.png │ ├── reprojection_2.png │ ├── reprojection_3.png │ ├── reprojection_4.png │ ├── reprojection_5.png │ ├── reprojection_6.png │ ├── reprojection_7.png │ ├── reprojection_8.png │ └── reprojection_9.png ├── im_files.txt ├── pattern.txt └── real_data.txt ├── GoPro ├── dist_2 │ ├── GoPro_2.log │ ├── reprojection_0.png │ ├── reprojection_1.png │ ├── reprojection_10.png │ ├── reprojection_2.png │ ├── reprojection_3.png │ ├── reprojection_4.png │ ├── reprojection_5.png │ ├── reprojection_6.png │ ├── reprojection_7.png │ ├── reprojection_8.png │ └── reprojection_9.png ├── dist_full │ ├── GoPro_2.log │ ├── reprojection_0.png │ ├── reprojection_1.png │ ├── reprojection_10.png │ ├── reprojection_2.png │ ├── reprojection_3.png │ ├── reprojection_4.png │ ├── reprojection_5.png │ ├── reprojection_6.png │ ├── reprojection_7.png │ ├── reprojection_8.png │ └── reprojection_9.png ├── im_files.txt ├── pattern.txt ├── real_data.txt └── reprojection_dist.jpg ├── old └── results.zip └── synthetic ├── results_synthetic.tar.gz ├── synthetic_1_3.log ├── synthetic_1_4.log ├── synthetic_1_5.log ├── synthetic_1_6.log └── synthetic_1_9.log /.gitignore: -------------------------------------------------------------------------------- 1 | ./Build/ 2 | ./.vimrc 3 | ./camera_calibration.vim 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(camera_calibration) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | set(OUT_EXEC "camera_calibration") 5 | file(GLOB SRC_FILES "./src/*.cpp" "./src/*.c") 6 | 7 | set(WITH_GUI TRUE CACHE BOOL "Is the LibCV compiled with gui?") 8 | set(DOUBLE_REAL TRUE CACHE BOOL "Should the real type be double(true) or float(false). - should be same as LibCV") 9 | 10 | if (WIN32) 11 | set(CMAKE_CXX_FLAGS "/fopenmp /W3") 12 | set(CMAKE_CXX_FLAGS_DEBUG "/DEBUG") 13 | set(CMAKE_CXX_FLAGS_RELEASE "/Ox /DNDEBUG") 14 | 15 | set(LIBCV_INCLUDE_DIR "/usr/local/include/cv" CACHE PATH "Path to the libcv include directory") 16 | set(LIBCV_LIB "/usr/local/lib" CACHE FILEPATH "Path to the libcv lib file.") 17 | 18 | else(WIN32) 19 | set(CMAKE_CXX_FLAGS "-std=c++11 -fopenmp -Wall") 20 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") 21 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") 22 | 23 | set(LIBCV_INCLUDE_DIR "cv/include/" CACHE PATH "Path to the libcv include directory") 24 | set(LIBCV_LIB "cv.lib" CACHE FILEPATH "Path to the libcv lib file.") 25 | 26 | endif(WIN32) 27 | 28 | if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) 29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") 30 | elseif(CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES RELEASE) 31 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") 32 | endif(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) 33 | 34 | if (NOT ${WITH_GUI}) 35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCV_IGNORE_GUI") 36 | else(NOT ${WITH_GUI}) 37 | message("-- Compiling LibCV with GUI") 38 | endif(NOT ${WITH_GUI}) 39 | 40 | if(${DOUBLE_REAL}) 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCV_REAL_TYPE_DOUBLE") 42 | message("-- LibCV real type set to double.") 43 | endif(${DOUBLE_REAL}) 44 | 45 | if(NOT (IS_DIRECTORY ${LIBCV_INCLUDE_DIR})) 46 | message( FATAL_ERROR "LibCV include directory is not valid." ) 47 | endif(NOT (IS_DIRECTORY ${LIBCV_INCLUDE_DIR})) 48 | 49 | if(NOT (EXISTS ${LIBCV_LIB})) 50 | message( FATAL_ERROR "LibCV lib file is not valid." ) 51 | endif(NOT (EXISTS ${LIBCV_LIB})) 52 | 53 | include_directories(${LIBCV_INCLUDE_DIR}) 54 | 55 | add_executable(${OUT_EXEC} ${SRC_FILES}) 56 | target_link_libraries(${OUT_EXEC} ${LIBCV_LIB}) 57 | 58 | 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ljubobratovic Relja 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Camera Calibration 2 | 3 | **Bachelor of Engineering thesis, Faculty of Technical Science, Novi Sad, Serbia, 2015** 4 | 5 | 6 | Implementation and revision of Zhengyou Zhang's algorithm for camera calibration, 7 | *Flexible Camera Calibration By Viewing a Plane From Unknown Orientations*, 1999. 8 | 9 | [Here is compiled version for Windows 8, compiled using Visual Studio 2013.](https://www.dropbox.com/s/k3i2dy4lhbp4dt6/camera_calibration_vc12_x64.zip?dl=0) 10 | 11 | All needed dlls should be there - if there's any missing, please let me know via email, it would help a lot! 12 | 13 | 14 | ## Program instructions 15 | Program offers pattern detection routine, and calibration routine. Calibration 16 | pattern detection can be triggered using flags: 17 | 18 | ``` 19 | camera_calibration --detection --p-rows 6 --p-cols 9 20 | ``` 21 | 22 | After storing the calibration pattern corners (let's say you've stored it as **pattern.data**), path to that stored file needs to be given as first 23 | argument for calibration program: 24 | 25 | ``` 26 | camera_calibration ./path/to/pattern.data 27 | ``` 28 | 29 | Program should output the calibration results, and write reprojection points in the same directory as executable, as reprojection_*.png. 30 | 31 | ## Dependencies 32 | 33 | This project relies on LibCV library, present in other repository of mine: 34 | https://github.com/ljubobratovicrelja/libcv 35 | 36 | It is developed using the version of the library which was tagged as v0.1 37 | in github, and it can be downloaded as that *release* tag: 38 | https://github.com/ljubobratovicrelja/libcv/releases/tag/v0.1 39 | 40 | 41 | ## Compilation 42 | 43 | Compilation should be straight-forward on any linux distro using GCC with c++11 support, 44 | and is tested on Windows 8 using VC13. See LibCV readme for more info on compilation. 45 | As long as the LibCV is compiled, compilation of this project should be easy using CMake (GUI). 46 | 47 | -------------------------------------------------------------------------------- /calib_data/ground_truth/1/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/1.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/2.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/3.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/4.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/5.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/6.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/7.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/8.png -------------------------------------------------------------------------------- /calib_data/ground_truth/1/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/1/9.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/1.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/10.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/11.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/12.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/2.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/3.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/4.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/5.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/6.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/7.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/8.png -------------------------------------------------------------------------------- /calib_data/ground_truth/2/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/2/9.png -------------------------------------------------------------------------------- /calib_data/ground_truth/3/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/3/1.png -------------------------------------------------------------------------------- /calib_data/ground_truth/3/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/3/2.png -------------------------------------------------------------------------------- /calib_data/ground_truth/3/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/3/3.png -------------------------------------------------------------------------------- /calib_data/ground_truth/3/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/3/4.png -------------------------------------------------------------------------------- /calib_data/ground_truth/3/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/3/5.png -------------------------------------------------------------------------------- /calib_data/ground_truth/calibration_pattern.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/calibration_pattern.blend -------------------------------------------------------------------------------- /calib_data/ground_truth/calibration_pattern_1.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/calibration_pattern_1.blend -------------------------------------------------------------------------------- /calib_data/ground_truth/calibration_pattern_2.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/calibration_pattern_2.blend -------------------------------------------------------------------------------- /calib_data/ground_truth/calibration_pattern_3.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/calib_data/ground_truth/calibration_pattern_3.blend -------------------------------------------------------------------------------- /calib_data/zhang_data/data1.txt: -------------------------------------------------------------------------------- 1 | 63.43921044061905 405.57679766845445 92.46270141677354 407.4556539075571 91.80636571669007 438.65765085408424 62.58724663945761 436.28844212118605 2 | 116.28035530429925 409.17858333240645 146.4502700963233 410.92321756063495 145.61153657396474 442.5588539245722 115.4621289243657 440.2901448310849 3 | 170.832696837639 412.46038130831136 201.84874167693556 414.36697339157973 201.07282342562434 446.1786800590262 169.96948547603384 444.042108267029 4 | 226.86846784643092 415.8660937726924 258.87750024773584 417.22223666696067 258.08798862732573 449.41640881455425 226.0553704310925 447.6506825567973 5 | 284.39049681092564 418.52561560191134 317.01817945273046 419.98793760569293 316.1712829180094 452.3706948520459 283.5861111501101 450.9388521872858 6 | 342.94734878624087 420.86862691813366 376.1245562808719 422.3172738779539 375.24863154252097 454.83514722151205 342.1840598520928 453.6168480341424 7 | 402.3786597601738 423.0391036991514 435.72956489670617 424.20940447867986 434.98422652908897 456.88887090081624 401.45536423673747 455.9696204207402 8 | 462.1274425133204 424.698227870397 495.62861462004776 425.5479869350395 494.7495320186444 458.47489778930264 461.1799178175738 457.66236923420036 9 | 65.23122858749674 349.6907027733138 94.30183727827091 351.12546728374343 93.23507926418313 382.38177879422614 64.27786871137394 380.54241920809346 10 | 118.03455996929435 352.3848197690597 147.98680923141626 354.01596384534196 147.1334778042088 385.58292122207763 116.97639180153158 383.78400187003655 11 | 172.4001628011494 355.22103054344683 203.50159386767763 356.65269887912734 202.56706339414532 388.5784118083934 171.4295974886723 386.88382222997456 12 | 228.3763298691328 357.91781697436124 260.4854396311641 358.96780241375814 259.6000573984108 391.3137043231141 227.6420682328298 389.68242228437725 13 | 285.9599818293802 360.10319357751825 318.57576183243066 361.1265526155113 317.7411318242701 393.93767327832836 285.09556588104186 392.33800905551436 14 | 344.4946104549276 362.0295359924154 377.5509954189492 363.0679898204286 376.88103318552385 395.91657094761024 343.8079167050693 394.7450286079274 15 | 403.8459777399356 363.76076192996504 437.1753362687191 364.7803580321149 436.5114425602332 397.6482184157768 402.9865433268136 396.67180088443877 16 | 463.4920805680829 365.13759047476947 496.9690783916478 365.94270062509526 496.2936229532057 398.9040828929399 462.7885699204803 398.34305893392695 17 | 67.41852441860404 293.9966296559016 96.2996638468353 294.86708975640414 95.21880533786468 326.1526966610338 66.20942498804324 324.6015117542396 18 | 119.9797486243428 295.99698063712265 149.98046369020764 296.8234292084584 148.8622849025551 328.5778206906491 118.84154740821056 327.2008936139261 19 | 174.3238625443077 297.9337108902351 205.32440388271883 298.81948923125844 204.26387925076293 330.85516599102203 173.12604613032883 329.6705367196501 20 | 230.1838096287344 299.78921796236745 262.2172840881351 300.677440774854 261.14524042693716 332.79591332166734 229.2884221624275 331.9480900414264 21 | 287.5611603285242 301.40750765891795 320.14751935472316 302.3671596041222 319.2027528811983 334.8347458357048 286.6438819868344 333.97214717182084 22 | 346.0130820428916 302.8615772015612 379.0677388819915 303.7957537856288 378.3339386738518 336.5805840212778 345.2182561259263 335.843219257846 23 | 405.0691571796657 304.3961263202983 438.41717278293885 304.99688117013096 437.85545990744623 338.00377524078317 404.45067311096983 337.4059120750199 24 | 464.5704816546494 305.55438512850714 497.94524811768565 306.28013663961235 497.4371600744771 339.24988398535123 464.09880007911033 338.63175674901987 25 | 70.14223570324233 238.36941313466673 98.86114133690076 238.84131089611782 97.38912834418213 269.8173495386012 68.53014212303921 268.8503327762575 26 | 122.32352404284693 239.49645820189613 152.23942540172192 240.19688114269897 150.872602337958 271.62715879713767 121.08044696801852 270.37870470871 27 | 176.46490664036455 240.6218321347413 207.36728039961167 241.2475433383001 206.27615277174473 273.1040616865928 175.21667919503284 272.1572623355096 28 | 232.11481951556652 241.93435972850207 263.9300248457965 242.5287028990519 262.87107309468615 274.63077976483817 231.08995394797975 273.8112794575494 29 | 289.2384705637213 242.95729366739042 321.5337457679127 243.6600536961319 320.73257253175547 276.09008335458935 288.2794389274066 275.39372168651227 30 | 347.4351242513755 244.16872583239353 380.2972613660385 244.6842257670856 379.6203130875602 277.514357672965 346.6144077255984 276.6308423343543 31 | 406.2245843264435 245.03205353779114 439.32454611059444 245.78320406939844 438.95955854175656 278.55480967980185 405.7563010061142 278.03596874238934 32 | 465.523092053566 246.1775260488285 498.63262103377616 246.72000146662035 498.4129722935344 279.658382849206 465.04901656798677 279.0123121351177 33 | 72.98910805171106 183.3229223758834 101.57463441315905 183.49198561366057 100.09857449688496 214.10704494688503 71.43642583229588 213.4076996960149 34 | 125.08462582171373 183.7455308332811 154.68888982212854 183.9569419183901 153.35543141407427 214.87035104151312 123.50751216393613 214.24532611208156 35 | 178.69793526089177 184.17588311789484 209.38547191170966 184.4149866893724 208.32632007393886 215.816865163078 177.56024952453845 215.3875007735427 36 | 234.15457949117916 184.67925083341942 265.64410806300134 184.82534476323218 264.69677759703745 216.6334416237104 233.03835668835987 216.1338650834502 37 | 290.8999148937342 185.18321246496123 322.9613083389533 185.56511405421102 322.24922844674023 217.59122880349022 289.95420589419564 217.06522312910695 38 | 348.6042810219786 185.89123718698139 381.2161913991703 186.33644067633875 380.84160911108586 218.48890929985095 347.9742627254581 218.1472837090741 39 | 407.1003826281793 186.57807793920117 439.99256288727724 186.93865298697168 439.7794124297235 219.43935044225728 406.66560533027723 219.0113464325632 40 | 465.97490215671394 187.31221128756985 498.8092261636818 187.89124186686726 498.8142188051502 220.34532859483318 465.81321821059464 219.9816384799639 41 | 76.16710425446853 129.06339843948058 104.5852956509872 128.8425785419921 102.882696473362 158.95642184704198 74.54384069975231 158.74926666996453 42 | 127.84130625665146 128.69339578967518 157.29464864747442 128.57148699423428 155.84566988736125 158.96976408495513 126.31962763479108 158.9222018940725 43 | 181.25563306460265 128.48382994356055 211.56324530847388 128.38054962303733 210.5125690153265 159.1928186390215 179.8549091694371 158.9349814420825 44 | 236.23365624522017 128.40228658023835 267.3728975599716 128.37901878197925 266.46612305601394 159.56799682573126 235.03913293409497 159.28494789041306 45 | 292.4588748930849 128.45043466848207 324.2021890861506 128.4998278268141 323.683049063933 159.90477698842471 291.5610558693335 159.71051205855028 46 | 349.69159518414097 128.56678071162221 382.08565036168295 128.74391121952144 381.69575364562104 160.41391042633012 349.19225434394997 160.22658072535293 47 | 407.61257650834744 128.87175784461283 440.21386867030157 129.24873333934843 440.2466596537764 161.1199048787604 407.4541577361327 160.7616376611002 48 | 465.9575137851354 129.54762183209073 498.5191646360089 130.01544776211577 498.8504617586597 161.9092884855256 466.0144855394268 161.502931927803 49 | 79.51086377384169 76.19294770503798 107.72760925898355 75.41244919346603 105.93776102770526 104.78608333700375 77.71646886659819 105.20484050795187 50 | 130.72333248421154 74.89725312608094 159.79765093257953 74.44149227856785 158.55797820100344 104.18386819887714 129.17092808378453 104.50373341344348 51 | 183.58843498593697 74.10334829270418 213.7663629190863 73.59563219244947 212.50741525881378 103.75238960231005 182.35955107574372 103.98313217828678 52 | 238.07365326917147 73.31630178493887 268.9554136481982 72.95119617351462 268.0935755023774 103.40299422659594 237.049184408764 103.4990934976946 53 | 293.83525186897225 72.8290660404367 325.2090973644488 72.68535034332865 324.71245241280917 103.33351475987702 292.94903847729967 103.3090982766722 54 | 350.4720860096607 72.61004387294248 382.3410371878173 72.62884900946133 382.1122927885521 103.52727723304999 350.0087703803872 103.48974886634046 55 | 407.6771939926995 72.68022846248228 439.8799789508232 72.81301005757938 440.1644449999867 103.96505623432648 407.66162856253777 103.73815275707749 56 | 465.4727459783836 72.99430375637395 497.6351232743503 73.46253296957076 498.15308375465145 104.46788349927444 465.765584699386 104.18293940908576 57 | 83.91124369483907 24.449609965519024 111.79005415568118 23.257341560463768 109.29980562808932 51.892922631222824 81.34217687233917 52.44578665482459 58 | 134.6306229879343 22.615817432586987 163.49441025609957 21.671251860251502 161.55748385723356 50.49984983220744 132.43151031727066 51.21217702660153 59 | 187.12492527401574 20.95504911622112 216.67521054436148 20.304119686517467 215.04386760074533 49.460075092826045 185.00188073977358 50.02127396914791 60 | 240.9165999666756 19.803724782257063 271.3308786513925 19.12826253252501 269.908315557608 48.58731916715348 239.2069709255986 48.99785244231144 61 | 295.9948347437614 18.78111909293907 326.9933298673003 18.468968619199003 325.8087109253044 48.09948571686872 294.5326210707748 48.45749239278437 62 | 351.92099001188586 18.26130021351024 383.4184929907958 18.06838345680369 382.6677477731744 47.952648408265226 350.91728600206545 48.04757384310984 63 | 408.526106159246 17.991288029486068 440.32310912108886 18.119723541002404 440.00887945970663 48.06368484279363 407.88019701489196 48.206850869211536 64 | 465.65621424059066 18.207516413716252 497.2680150495579 18.3853339481393 497.3887395771093 48.524780190788825 465.38938336026433 48.307397872545906 65 | -------------------------------------------------------------------------------- /calib_data/zhang_data/data2.txt: -------------------------------------------------------------------------------- 1 | 74.95173767129486 409.09267757581756 104.31259784448483 410.8263322391833 106.06048939567938 438.7099113674728 77.00428944064123 436.94253844835623 2 | 127.82252063924655 412.2041930215117 157.94718654000116 413.6707476599427 159.23134690487825 442.0125923370657 129.4639745161323 439.99858857260546 3 | 181.84295543141715 414.98756134254074 212.70112359460154 416.543317839545 213.47114738670456 444.7447412257028 183.11454542957057 443.2278534824685 4 | 237.12102868837414 417.61764879300614 268.55826654085524 418.852674771769 268.8150768678729 447.17723979813155 237.8078707974472 445.950167626018 5 | 293.18762081188373 419.83695853105417 325.0180501810139 420.8740440704354 324.67712919336066 449.3977505029976 293.2126583968135 448.2589138688724 6 | 349.9194813487409 421.5926044159451 382.12327419554975 422.54835931648904 380.97582814286795 451.04240885138336 349.40221370123817 450.2125738475785 7 | 406.99836748473933 422.9847167646322 439.0964955393227 423.7697485925279 437.5183046443977 452.39253346207715 405.7278356666805 451.84863819736125 8 | 464.0038872204549 424.13271228547285 495.9202537619488 424.6547713748391 493.7813847888604 453.28364372783864 462.1709581733631 452.74248921975243 9 | 71.29513562533573 357.6942633948015 101.13294410137546 358.9622385554008 102.80850482138675 388.21586421691745 73.30573447367999 386.4767447881153 10 | 124.85876349944454 360.14700880628453 155.61997640789926 361.61280610173435 156.7838146051699 390.9051710115854 126.51737869491649 389.51725088873985 11 | 179.86316734884443 362.63102501359486 211.2827322130613 363.96280707661003 212.12539080292166 393.55484670034025 181.01914390337387 392.0355895970633 12 | 236.16730364497818 364.81259801424477 268.1944847698603 365.95903062989 268.3038399388999 395.7985907139001 236.64681524393112 394.43212128571446 13 | 293.27736544637816 366.85190781014205 325.72269444833324 367.97840546651037 325.37205306669284 397.7869384211426 293.2457060390575 396.5189321718967 14 | 351.0824026293796 368.4938576438795 383.84757028281734 369.2861712805573 382.76085788516536 399.07115871698323 350.5740318919249 398.43078070498115 15 | 409.237369470657 369.89469625644654 441.87611047771463 370.62118575553274 440.32005212563485 400.4309030598217 407.95170291684246 399.9145988638514 16 | 467.22528388902015 370.8611321393432 499.6959573489727 371.46784725362465 497.6020979564682 401.29605660975375 465.46554233286633 400.8545300359704 17 | 67.86990551193277 304.15854104273126 98.12885497344568 305.33197106088465 99.77819307361712 335.66616896503956 69.78806919531887 333.9997736514897 18 | 122.24349452326419 306.2762726445089 153.42608687474538 307.3619437579255 154.62456270751449 338.04724089010506 123.68836013916045 336.5298452809776 19 | 178.05244645201566 308.2732746098075 210.04283883837203 309.2866480093317 210.80656304857428 340.1661345721875 179.1043022405136 338.76683845120425 20 | 235.25161840257564 310.25100921872996 267.8995197596447 311.0069342698467 267.9812366770928 342.10484581060655 235.7676912887818 340.9797983589521 21 | 293.3421842610446 311.8508340598895 326.4107861778687 312.70108967971555 325.9937545174971 343.78803683860355 293.32037510063236 342.76892669500995 22 | 352.244687578723 313.2272280064658 385.5214358275944 314.1048574991225 384.5008786606961 345.12373435771724 351.5868749524029 344.410642579454 23 | 411.28840290448835 314.50849735444723 444.5481870825223 315.13401987774097 443.13349796474347 346.34953229624506 410.18687250840617 345.8239604794856 24 | 470.2577135508111 315.65909088057236 503.27077885824934 316.22686007167863 501.3805328070552 347.18742977811763 468.70349434440226 346.7560520199094 25 | 64.75555278435645 249.00623198940218 95.48727692893543 249.90024474066985 96.77853196544768 280.9531641627545 66.50285015566611 279.93996248245764 26 | 119.76637875562051 250.43888034309919 151.406678513741 251.24922461470567 152.62503287410277 282.8870830458499 121.16646574019978 281.85078270235715 27 | 176.42971625799623 251.97401222878347 208.95894733301532 252.74164858372015 209.6156030548792 284.59964936793904 177.33604375408984 283.64791860105083 28 | 234.50709637791988 253.35502367526004 267.59477254156945 254.157198026143 267.7563510783289 286.2138260527267 234.88161049293558 285.3543003487409 29 | 293.509685485772 254.65618927479554 327.0613850150518 255.41048392294988 326.71144380703106 287.6984729173571 293.468510478582 286.79827409858785 30 | 353.26154729214403 256.0041375953487 387.1069584708076 256.66019783617827 386.154995927957 288.9345881008247 352.7308387249233 288.29009630103457 31 | 413.24709354626935 257.07095581919504 447.0692508880799 257.7836137149599 445.73560874133767 290.07609857973375 412.2948987836504 289.53669467669806 32 | 473.2646573411307 258.25170894636994 506.67785551887835 258.85507270586254 504.931572461884 290.95612069363284 471.6952673825678 290.48170514810204 33 | 62.05888397044999 192.35510221204711 92.973573602527 192.6256960084795 94.42398637216003 224.7833346239519 63.53242170109247 223.94026132221578 34 | 117.73390592637882 193.02538500590614 149.6943482354319 193.4988728783249 150.77534351473102 226.01677846779737 118.82776505525653 225.38296264851147 35 | 175.03678176202516 193.94265924027135 207.889510217968 194.43129394274365 208.48194860586497 227.19674664247498 175.88441284032862 226.45328914274808 36 | 233.843922785267 194.7555301320053 267.3777418393208 195.3874117062764 267.5443089922755 228.3218048766975 234.33779280479558 227.70071094866387 37 | 293.7353783366339 195.803516382801 327.6970613761579 196.4711762821226 327.3889658167848 229.52911112372314 293.6500777506575 228.8110834993607 38 | 354.2987015865003 196.78147138286732 388.4849459792602 197.49460817273027 387.7937028320226 230.65810793406578 353.8000492581166 230.14462212875998 39 | 415.07650445349185 197.92445468093158 449.3308394788536 198.60662180792693 448.1539514082538 231.78398429067403 414.24844896105515 231.30838538530855 40 | 475.93976313131697 198.98183996148856 509.7574510695092 199.78829504865965 508.1533012693523 232.8117044470386 474.5063537120867 232.3143594301496 41 | 59.42172685465347 134.179092671166 90.79563380077005 134.16829202352145 92.04393556053701 166.99318051552203 60.79330343383183 166.69186561538535 42 | 115.77372481183963 134.2042774623179 148.15875851215674 134.35470670117482 149.07771211508572 167.60190796191188 116.7725210991517 167.28748980898044 43 | 173.7876505758194 134.43075359705995 207.05781963676378 134.6511780553312 207.550410863157 168.24328621175593 174.49051684419248 167.80884709400817 44 | 233.17777139665816 134.79815066776965 267.1800784088151 135.1592123086489 267.34730435342516 168.94765205302758 233.5599781799047 168.49399019305352 45 | 293.83886263182103 135.48528605204007 328.13567798166054 135.89570822172163 327.93506070151443 169.86489500954485 293.76466178006905 169.3701821220752 46 | 355.0451067222118 136.27656990753377 389.6404574165976 136.79751719159458 389.0779665912857 170.71268569839228 354.7071941165037 170.28075057748237 47 | 416.52661520032 137.15292513462248 451.2479336340395 137.93386478840048 450.3176960296035 171.95113934244694 415.9076249272925 171.3823479858611 48 | 478.0945516167279 138.37478658889506 512.394362045786 139.07513988401644 511.0469300869903 173.0377357635608 476.95733830092126 172.38056174998408 49 | 57.381598023792804 75.06465950658283 88.83351104668657 74.61553730941013 89.9304163352273 108.04705805566762 58.28556526837371 108.05700488373486 50 | 114.06968575478231 74.48587987763723 146.69254903597698 74.18239175914412 147.49874891068595 107.9386025922629 114.97754740987006 107.87073600006566 51 | 172.48640816024854 74.1320277432348 205.98112889526138 73.91141793568957 206.65670882129842 108.02344712477311 173.17947329518339 108.02381014432494 52 | 232.5402874913855 73.97411559857558 266.81072091139373 73.98323424586648 267.01863060705887 108.25217204121056 232.91109474136306 108.02894328662387 53 | 293.77480578263754 74.14953797150977 328.325043775219 74.44184216005387 328.27224478118325 108.78803395866298 293.76995102474336 108.41527464498355 54 | 355.60254590572043 74.58162759095768 390.7998266849856 75.10955281713126 389.50524941087275 109.72447580472327 355.37801298727476 109.15622837397015 55 | 417.7098217713907 75.50504947291813 452.5633467311652 76.15652138137034 451.95764284685765 110.67035773523023 417.12859463144565 110.13804207439752 56 | 479.76163911602845 76.6873930120917 514.3350725570377 77.59046461460535 513.428612823896 111.98049797339957 478.9269312311011 111.29662440065181 57 | 56.318999635465964 15.145508059133235 88.16800951840939 14.456765578207007 88.37464036332754 48.07119748594406 56.48107062537793 48.77035555231163 58 | 113.57672948180384 13.862934726294393 146.57939917208532 13.420609517873295 146.51866338886308 47.317801235745925 113.71699864703074 47.72110446290457 59 | 172.64025607990797 12.56360906633607 206.3672799590248 12.938007025302493 206.03924093846 46.692609262276555 172.36156656202832 47.316280514385795 60 | 233.0920953642154 12.318481092420383 267.55203807986044 12.170727528606527 266.9529851616901 46.534627736208456 232.60592968457212 46.53453970141745 61 | 294.595375305751 11.997888025947153 329.5230030696627 12.112134100357016 328.72822099684635 46.68475547129191 293.8955520649313 46.85347075226735 62 | 356.9130755447031 12.395678586510696 392.1190375663112 12.489431916359342 391.0341841697656 47.41213179408572 356.03343320732023 47.046267665217954 63 | 419.55084342282595 13.012494018315612 454.74142333183613 13.561538861376613 453.3894601132962 48.449962793221545 418.3458748608592 47.94928261066575 64 | 481.9960132940097 14.223576647359778 516.8439627848335 14.980006351467088 515.3867454236566 49.82835534331021 480.63356573462875 49.12278317911614 65 | -------------------------------------------------------------------------------- /calib_data/zhang_data/data3.txt: -------------------------------------------------------------------------------- 1 | 137.22826265754128 394.36338179898917 160.187943549149 397.0974538410207 159.34730413574266 425.12927320814157 136.29854255272394 421.95770763177325 2 | 180.16912538559387 399.3808729240103 204.86292900573017 402.06267557016076 203.72675697709863 431.01683243234135 179.18487675331212 427.73591150424966 3 | 225.75104300713795 404.3630066605049 251.92825010658618 407.17957914453706 250.96538074145894 436.9423114376981 224.6283650625028 433.54478632758776 4 | 274.06364553672006 409.5082639415724 301.845689852696 412.2722130109322 300.855821319876 442.76108985271657 272.846916254779 439.6032903759656 5 | 325.0825655137707 414.4173174859092 354.56388295710303 417.32550750800846 353.4016250896212 448.65435521077524 323.7860690982621 445.54103473242196 6 | 378.98388879169886 419.4444513141882 410.0604841328458 422.2039805082526 408.85117262972864 454.38482473382624 377.6671696081526 451.26830627507445 7 | 435.3672294584237 424.3107037363906 468.0969116124544 426.8910599406407 466.95007815152167 460.1653980686303 434.20075412259564 456.9437196591225 8 | 494.4674585750879 428.932852781578 528.5406867041781 431.57904282941973 527.4730212174464 465.5991091485938 493.31225978611377 462.4166739830104 9 | 139.23128225352067 343.82883420371434 162.40607857026552 345.5637340468602 161.0441281117406 373.7886888759932 138.12614881899736 371.3766195986743 10 | 182.0956177210248 347.34328675090325 206.8424541757716 349.1157783812819 205.5644696549492 378.2297015637484 181.0161572851171 375.71604266612775 11 | 227.77183133008973 350.75951555377674 253.9653299433438 352.8241482209459 252.9555029278685 382.68944678757265 226.47691666256662 380.0110151937857 12 | 276.0055916396826 354.34376925094153 303.93503480902314 356.4293131651769 302.82792251283917 387.03240018019005 274.88706451551496 384.57729729393145 13 | 327.097679977267 358.0025148055112 356.56018588224526 359.78587981088856 355.52539639340546 391.34697706149575 325.83378024849895 389.06651105202144 14 | 380.80323390705894 361.3858374680148 411.97019276328894 363.3228932787287 411.0335491945596 395.6766263372238 379.82115738144716 393.44439552805926 15 | 437.3161307891978 364.6838758307422 470.05281208035706 366.7650017205178 468.85296474447273 399.86250660947536 436.4377484591397 397.6409678059681 16 | 496.5259261096069 368.1086909818487 530.3780740777048 369.80509453316364 529.4759505908793 403.86752895336264 495.4268070108007 401.71843649389274 17 | 141.46861683034936 293.0742154572436 164.5807409773764 294.202800008571 163.32783519897518 322.4205278535629 140.21123771562725 320.6584022285569 18 | 184.29973188639207 295.09574730151354 209.06410790314035 296.2964901801406 207.72358870907408 325.3152966701542 183.1030826056004 323.5749572452371 19 | 229.8310926051587 297.15398989000835 255.99132992913994 298.3593237643727 255.0622296963477 328.2848248403561 228.6674247723076 326.46538419427435 20 | 278.01506574164137 299.2639193616573 305.9565666041089 300.5134281874246 304.8897061538117 331.08662768564045 277.0002019566349 329.540576281349 21 | 329.0596770303812 301.1764953193146 358.5456190236702 302.59129350271263 357.59500503076407 334.08415542516224 328.01542314104705 332.3558666225793 22 | 382.7568264528644 303.2440789128329 413.89270946473846 304.5056748646233 412.9544147013671 336.7897872351801 381.7915596675668 335.385089410781 23 | 439.1076523453959 305.0927844274493 471.7497534859193 306.4249869242272 470.999379335398 339.4421967758366 438.32507915702837 338.11611219785857 24 | 498.20319243576364 306.9549946877856 531.9294217707754 308.2043138290165 531.2729288550549 342.2115675535977 497.2893671822999 340.690746009066 25 | 144.02690053062062 242.6718680818291 166.96949659348394 242.79906452471883 165.6802366892435 270.86191691721774 142.5804002864817 270.01268397954476 26 | 186.77027044489435 243.14467479496832 211.2787425176295 243.3891036611437 210.1154157332669 272.4215883511979 185.38970733384068 271.45267488666263 27 | 231.9840600903537 243.8498032983192 258.2096645155677 244.09467272560116 257.1869478735508 273.85575185886955 230.93991568769496 272.8597279547398 28 | 280.1539980943389 244.45522572209077 307.96643002142963 244.67396263072644 306.8693797335895 275.1017068970548 279.08217662955565 274.31309494871505 29 | 331.0118139734911 244.8505182769471 360.318612489999 245.11586017335702 359.4651255209697 276.5254314547623 330.01507818262917 275.9096248037888 30 | 384.4956750345099 245.32783257739558 415.4097293518747 245.68446247412308 414.7211611827516 278.06013833307645 383.6665987672307 277.2249618635972 31 | 440.6855471964129 245.90994004685442 473.1066324144036 246.23444578995014 472.49663863500444 279.1002917498545 439.9952968232801 278.4653232806003 32 | 499.3795257678252 246.37083852688656 533.0144174415416 246.64625376414494 532.6201119517865 280.30037732055115 498.8282297359098 279.8298821894797 33 | 146.62005436903283 192.63570149359077 169.668466366421 192.14247972173544 168.14088993315153 219.8757107467198 145.2969262244527 219.63629040041084 34 | 189.19997922929988 191.81378016298464 213.74151943863703 191.0475267146833 212.41295950311167 219.8074441995837 187.95100093277827 219.68941121809857 35 | 234.47993108486497 190.88652205812798 260.4388922869358 190.47597841835986 259.22075869636967 219.78209264179628 233.0990866604428 219.7454369362106 36 | 282.40479346925423 190.16562891048716 309.92597592744846 189.45585866535663 308.8553839397174 219.5534855787983 281.11315313638664 219.6428951878254 37 | 332.8725536440233 188.97316935994638 362.0265145134641 188.55415057351158 361.23205732432086 219.43249559610635 331.96307842138845 219.6077214885436 38 | 386.04522463062176 188.21089480538737 416.80214965147997 187.61406026618334 416.26598017327336 219.391277252366 385.37921692899846 219.51607369240566 39 | 441.98872926357933 187.07929156095236 474.01775768578074 186.6431408910057 473.5888253285411 219.22969721026237 441.35277762388336 219.44508721115855 40 | 500.2881129514194 186.29351513598155 533.4944104093779 185.8462742415477 533.3330406949578 219.01045194464146 499.9513161783174 219.2656102300742 41 | 149.54446166549693 143.23993886908247 172.07535986703343 142.12710431456216 170.908091123399 169.34733553687684 147.98243824747257 169.8986237310783 42 | 192.02698305909564 140.9532635865463 216.18079723876303 139.89521042007132 214.73695710877334 167.69271164749344 190.39642142820853 168.66447956031104 43 | 236.82599989671436 138.81359207082616 262.57914678420235 137.4441117299256 261.46865512653267 166.11855592552345 235.6778682904718 166.80546253087076 44 | 284.4659594003672 136.5489122466196 311.8160682235616 135.00285127515974 310.6837217860684 164.54946513884929 283.3415369449946 165.41328309895414 45 | 334.5057948401551 134.1289277694715 363.4735676519659 132.61376484746475 362.7977034731471 163.063277769898 333.7890865969108 164.0076343528107 46 | 387.3688333267982 131.66081409515422 417.81852521202524 130.37219077422017 417.2828758620442 161.67596336090472 386.79452891455617 162.50987641387474 47 | 442.62430145277176 129.3503753046519 474.5382097952027 128.22188783483872 474.38006611193555 160.18332975316684 442.31456510635167 160.962411733703 48 | 500.5166852013382 127.09848842356901 533.357763369392 126.12860808767306 533.5704860509042 158.58359274764643 500.41678339749706 159.5221664931279 49 | 152.6941041120487 94.76135047288122 174.91272059872486 92.78205768032805 173.44284156368943 119.43478530436579 150.78631088055204 120.83198766190286 50 | 194.4685357560373 91.27497856507841 218.32913322759768 89.2289199555576 217.25358788238765 116.40347241455032 193.17952522125708 118.0623017190104 51 | 239.10030401088463 87.444925082216 264.3997407520687 85.67268249225322 263.54638225957837 113.62245765546928 237.870604374633 115.09618602561768 52 | 286.1734015784083 83.8750500079042 313.3644901138187 81.9109204678985 312.40606354125106 110.58067195195888 285.3483395275492 112.2816332497131 53 | 335.89624139722815 80.30694821030578 364.574067544245 78.15765014026546 363.90779598681877 107.80703560845086 335.2928115089919 109.38595890583818 54 | 388.29937338446825 76.65330292365267 418.20650521222166 74.50660461571296 418.01090300828133 105.00768509345971 387.8178010502578 106.63105990897579 55 | 443.04706241212943 72.98931424770032 474.33859282443154 71.14691268145958 474.4919564859454 102.11005679277487 442.8626848900896 103.79065117678765 56 | 500.1510622911001 69.48749337226295 532.6514119558849 67.79456358965697 533.0641573657961 99.46326990343688 500.31128748448396 100.96797841765795 57 | 155.5435287110069 47.17733319510865 177.97676540879692 44.72169880469761 176.01049624693056 70.45416877603564 153.61940906768587 72.77102272710275 58 | 197.3847531971697 42.56321054309326 221.212161523322 39.784736826142975 219.69700905360477 66.30547977950724 195.7941734084905 68.58615709791889 59 | 241.7067121175821 37.593701930234246 267.0255918302831 34.87348819099037 265.41106106285343 62.1077112242518 240.19419761663568 64.45179364054138 60 | 288.40151605688584 32.77894423415306 315.32478744606584 29.950054897270267 314.0049946689135 57.907044724448724 287.1913773982965 60.25007555014178 61 | 337.76488292829356 27.740386011495826 366.0043969669435 25.15192487495098 364.99570865089214 53.70880216984636 336.7051493955836 56.189532811115164 62 | 389.5822762790428 22.957895518479983 419.278589656323 20.239300640238994 418.52729303104564 49.64030341819067 388.67513912517086 51.997930887860726 63 | 443.87428361015714 18.171841356899918 474.84941822442266 15.582173647322008 474.41788883915154 45.59782436338222 443.24029451612137 47.966912817965486 64 | 500.4966854081226 13.507183887278705 532.5638141747942 11.025372987305676 532.4770116585777 41.622561865300064 500.06984943005654 43.9859497780876 65 | -------------------------------------------------------------------------------- /calib_data/zhang_data/data4.txt: -------------------------------------------------------------------------------- 1 | 84.04443096693421 410.1275601822925 116.30017825670132 410.5640160796385 115.78761144637487 442.33308017074563 83.63008665108278 441.9120409309495 2 | 141.72697580728473 411.0320047945014 173.66965827327525 411.3014051088614 173.22470736835155 442.874524404491 141.25465254078 442.56452420352775 3 | 198.84160209514897 411.6115154837549 230.48230490547232 411.66253139457 230.00149631923614 442.81450303443023 198.35874854581763 442.9222147932338 4 | 255.29048125241334 411.76413178856507 286.5710183170346 411.8184014887793 286.1052154424992 442.57963067823584 254.92483840435918 442.812413067932 5 | 310.8563877944848 411.53170846505816 341.45385025628076 411.13086274125095 340.9807128715841 441.9018025172065 310.32786496749446 442.372442117802 6 | 365.14154221159794 410.8468994517686 395.11814798146867 410.49577206408236 394.54657884508134 440.75201748061755 364.75756167014606 441.49016294845774 7 | 418.12334794462424 410.0749383223604 447.1233421646275 409.4077946680507 446.6659541668829 439.3468523321525 417.6437479443758 440.24804913017016 8 | 469.44710399654394 408.82236579329094 497.40630506971434 408.2291202050343 496.96546839539354 437.4925416355543 469.0398791308166 438.5732397793427 9 | 85.37953462163631 352.6911734612626 117.4368404303716 353.30658732224606 116.79314954847744 385.37795532834053 84.69358691764684 384.48377373987313 10 | 142.7532108282927 353.88222801154996 174.82054779687482 354.5019195691502 174.17484598375108 386.1369384254106 142.14148922521184 385.67952170258934 11 | 199.95031028127778 354.8418530581463 231.56181142476106 355.0944960735561 231.03385504516152 386.5682184013329 199.2978443260861 386.3495186560016 12 | 256.34156128825185 355.46307001296077 287.6342017203541 355.70231135955027 286.94180745233365 386.69902084638653 255.8158685003231 386.6661851544293 13 | 311.84877343792976 355.86636171875597 342.4397036026918 355.98279193083147 341.8740980015034 386.54374887917584 311.37171768277017 386.71395041456555 14 | 366.12525672838075 355.9227752530399 395.97517479599225 355.89247608061646 395.56122884031146 386.207080610317 365.7315834094994 386.5578699709624 15 | 418.9949604588119 355.72307403893296 447.89164184157676 355.6305185116881 447.5104451704205 385.58218141166225 418.5167767001405 386.0436722757799 16 | 470.1986100852902 355.32112770491875 498.11712341720266 355.0653051299678 497.7749263716285 384.48744084519 469.8008429495167 385.1417883995249 17 | 87.04076708049563 295.2717623705317 119.00722115008298 296.09744908092813 118.19597492678935 328.0148324834598 86.12577780959948 327.17747160806965 18 | 144.21931172056645 296.71624962895044 176.23886235531612 297.42734532648944 175.28085814453715 329.1341828928605 143.51465528191176 328.4301071802956 19 | 201.17687679253876 298.10851203004745 232.91593793592236 298.6387408017938 232.09057444036836 330.15690299285603 200.4307493327377 329.6976983724004 20 | 257.42839689778856 299.1476476870004 288.6320185896951 299.7136342338716 288.0057910825919 330.7752906349735 256.91696175924784 330.39291953527913 21 | 312.8184806124381 300.11760776718137 343.31530671682185 300.53512199604444 342.8733041767828 331.3400991943669 312.30301081549095 331.12052370537583 22 | 366.9415531832442 300.7183058251445 396.7186384866738 301.12887376790275 396.33112023382427 331.6024388710668 366.5520528783003 331.5813905652987 23 | 419.6441969265521 301.30253200591716 448.57281880658826 301.6981262956366 448.2484229315521 331.65814308501206 419.35820032069535 331.74852929986594 24 | 470.7675811162934 301.80643590258603 498.59217725443636 302.11832928887446 498.3891184407877 331.49018120317834 470.56278143036997 331.67394012773985 25 | 89.06173929681611 238.14258944451336 120.92361281354324 238.93787119889916 119.85245671333331 270.65791993017456 87.94289311105582 269.8771779716072 26 | 145.96439095961492 239.86653197931125 177.8037407602414 240.67633415353237 176.8352015791996 272.2347514678646 145.05983359909095 271.4910498547869 27 | 202.59943341937188 241.44571867066892 234.07004985194723 242.3769448123599 233.46596041135535 273.76565491868274 201.82540638289512 272.7463176229811 28 | 258.6686748785791 242.9334839653305 289.69230118703643 243.95570854436795 289.11134646438444 274.8176526802191 258.0444217569889 274.242834867341 29 | 313.7390153168726 244.50985588031136 344.1439487963228 245.29318374749295 343.6841230231197 276.01009607473026 313.29953998688524 275.50673296415835 30 | 367.7233746668972 245.96045515835198 397.3281365708681 246.73840824537004 397.00205500081387 276.94795539109396 367.3217102055414 276.4649089080886 31 | 420.113032118686 247.15602820342573 448.876686706884 248.0335920776156 448.7496816227033 277.8228840547653 419.9022378519927 277.41662531538407 32 | 471.0576589443452 248.43204055677325 498.69462704616484 249.1014707277691 498.67953980492484 278.38686875047995 470.9189482521566 278.1749224646193 33 | 91.45015936007158 181.50862597428082 123.20807060826696 182.5685086563302 121.87261871427299 213.99920886780595 90.1498156938672 212.70881970527745 34 | 148.0457547322132 183.50408392570867 179.63141622295672 184.56479854367836 178.55341882413703 215.83233535849342 146.94190701406038 214.53593712889045 35 | 204.28229364512413 185.48891579397565 235.49953908698788 186.56337882533413 234.81795028874004 217.56588861938528 203.44863859823107 216.41800550254834 36 | 259.9922098463268 187.5286338669944 290.7535512776566 188.61674078717783 290.1931133753165 219.20773130627128 259.2761281347135 218.26745155612733 37 | 314.7415031780298 189.52704594808074 344.8756862939664 190.71609301577558 344.52370032102726 220.85559937074535 314.2579288822442 220.11577245887895 38 | 368.3041944424955 191.56246710653886 397.703732451675 192.75758396686362 397.60392388615463 222.59607865926296 368.0185878053382 221.83433685112269 39 | 420.40232294270123 193.62240157124128 448.94884390830947 194.77218414007902 448.99885248736933 224.24832162934288 420.2637072377896 223.45629166456487 40 | 471.02419150718754 195.60366374803445 498.49467471510246 196.81840732398942 498.6266775573443 225.76495720872376 471.08063216213856 224.93317668825492 41 | 94.22109692137786 125.83800085780929 125.56692819196921 126.88641510868688 124.21318698361289 157.89914772132937 92.69972864074096 156.46301170907824 42 | 150.38300521582437 128.0039309465524 181.5994982779156 129.1770314239806 180.4451654951775 159.9733254757279 149.0096365008795 158.67556215104196 43 | 206.02628128325355 130.28172108604093 237.06547078395238 131.60795500243844 236.27898192564638 162.15715830094135 205.16403235697155 160.73220186770484 44 | 261.31965129541436 132.64727749332698 291.790692713845 134.2932679665855 291.28190302401674 164.38134076631678 260.5319175305519 163.0564556376514 45 | 315.51314998670256 135.3265229245645 345.48566438716466 136.84943819824846 345.13842589070833 166.56540195162734 315.1908697966998 165.44996001843253 46 | 368.67232120839816 138.04082049845894 397.8688754036737 139.4682228601376 397.83196298753097 168.85058697407908 368.5096280542607 167.74107143893184 47 | 420.43715162551564 140.61661255146953 448.76337462067613 142.38418869041195 448.9659722810597 171.2364957229348 420.4846870029549 170.06852074074246 48 | 470.69111452804435 143.51880260260336 497.8707780725073 145.0562202007092 498.2964966980414 173.59790925868393 470.90647913128595 172.32073540080222 49 | 97.09281156928235 71.24292423931813 128.1061246156735 72.58775587063315 126.65444803234088 102.68696968686035 95.33814375913039 101.50046161530605 50 | 152.53290892825265 73.7637828589439 183.45326564398033 75.05753622621077 182.49287080318834 105.04938376639707 151.32558768437104 103.81538822500258 51 | 207.78903737094635 76.26360580901712 238.38770754559832 77.98261912872776 237.73853003691693 107.71633916731392 206.80705206353167 106.16669709986054 52 | 262.3885788772523 79.26306974110837 292.65980012153847 80.96132166483805 292.194935518221 110.40678055828252 261.8187613183351 108.76042831478243 53 | 316.226951361783 82.25464259975655 345.75352942651904 84.15250571723172 345.6723138566835 113.16015553599235 315.8807885237929 111.71254094054244 54 | 368.8336445940755 85.58785180482208 397.67445932507763 87.38250296896213 397.79458666471095 116.23938884884635 368.7436755838173 114.56146521314619 55 | 420.06460840397295 88.8609379105335 448.11301773994575 90.92218300215097 448.5180508387761 119.17657669448944 420.2848580722614 117.61198867867624 56 | 469.81002562166196 92.32389867224812 496.8473061479256 94.44524776682844 497.45534135844525 122.3677156781705 470.35795376220653 120.62993945706855 57 | 101.00970782167697 18.103363519108168 131.64830457591503 19.554013477350843 129.5014303581064 48.80995515065228 98.50516961356124 47.382840787775635 58 | 155.89552189367052 20.719960397126016 186.33741161443507 22.48027183424593 184.73216557465847 51.60387025662243 153.7675532196593 49.92713543000054 59 | 210.3982534058584 23.82758215460897 240.46683087472698 25.49616632652667 239.25182943840537 54.46851462339318 208.6792019304227 52.769834625558 60 | 264.16507192752834 27.051830520038266 294.0082199666479 29.014009892833432 293.0493921570094 57.52718989267175 263.1126468421716 55.890098891140056 61 | 317.29261990558007 30.574770973198902 346.3572117534144 32.71108362723538 345.93311985207527 60.917351983929535 316.46617284290727 59.24961823065278 62 | 369.2755474222269 34.33603808098457 397.649194731123 36.55072858413427 397.5769584688814 64.5725934882062 368.9235797766379 62.55924108972437 63 | 419.85385101377045 38.23308678448411 447.4759819596767 40.64911138489491 447.7728032135152 68.31847802926704 419.8272438371651 66.26045914031754 64 | 469.08155005643766 42.382012370500085 495.7493598678898 44.824566384593325 496.30676774724395 72.03715407745713 469.35696712365547 69.99918311868802 65 | -------------------------------------------------------------------------------- /calib_data/zhang_data/data5.txt: -------------------------------------------------------------------------------- 1 | 78.69152413080967 361.274660727371 106.28319698721955 366.18930491537145 101.6433121551384 392.8711331833367 74.05351537940494 387.9767155423387 2 | 128.29439935441943 369.9386524721016 155.94525664796745 374.8338236074532 150.9579436090608 401.31853717667235 123.62450536035561 396.6112255754958 3 | 177.63828694566752 378.4916243402773 204.89237151583075 383.12569450073767 199.91082493226003 409.2815249107981 172.76278045365908 404.78951194438775 4 | 226.48313127424362 386.64544523893477 253.4272567154734 391.0564330836273 248.2240766661916 416.9531807838528 221.41979772774425 412.7334118705678 5 | 274.5120681898539 394.2401800907817 300.98056670856937 398.6664525186608 295.7293840746357 424.2322343664807 269.3894849313651 420.25244261461603 6 | 321.77684077639236 401.6339307093484 347.79148899090194 405.56433609752037 342.3218570785699 431.00454771223156 316.4136489735329 427.30571197138573 7 | 368.00846360843946 408.56230340859327 393.29125405762306 412.389359351335 387.86436475270574 437.4183405579708 362.5387157965701 433.9173828418121 8 | 413.00920312893993 415.05304633130703 437.59447965202645 418.6626529566944 432.08481112638407 443.2785331595828 407.498492522264 440.04149039250547 9 | 87.2750900075558 312.3582673315689 115.14486555327808 317.42353670118666 110.17264958418068 344.657297763098 82.4053155486241 339.661054163283 10 | 137.13560548427256 321.4333060528775 164.85382167170408 326.5126041482136 159.80924168545042 353.4516195686336 132.19133764583415 348.6457331504231 11 | 186.71930701859588 330.2996162749264 214.19055408743185 335.1650383251138 209.0529991661218 361.95031470453984 181.62149262850875 357.16541388071425 12 | 235.757047274741 338.8932021696882 262.9035954003633 343.51079074030844 257.6037685274935 370.0145099185704 230.58076733971728 365.4833377126066 13 | 284.08995820462525 347.03871206962543 310.6748249423151 351.5973590477158 305.31679755636327 377.6966829114518 278.7652846946247 373.4912951273422 14 | 331.47996676392114 354.8189011224688 357.56488342121315 359.2642869317308 352.0966679140305 385.0668913059856 326.09710280951197 381.0551434153442 15 | 377.7901601525455 362.3469946965432 403.2361112529117 366.5678795323426 397.72045774085007 392.0538840965335 372.3832785560251 388.1802537967592 16 | 422.95528530172487 369.5578590050164 447.66157879036217 373.3747322390947 442.07395366043454 398.5866622435366 417.44409023037366 394.9113376306578 17 | 96.22722627556054 262.8284574907546 124.21902371058596 268.1845520687507 119.14473116606588 295.6505274302097 91.27230996520825 290.485782009713 18 | 146.3266757897717 272.1622311755597 174.18373207622275 277.484964613776 168.97622184347225 304.85947356553476 141.11396846728337 299.7387275787566 19 | 196.07660977250805 281.46178259575737 223.63592217813857 286.5575045993843 218.39460452664457 313.62631139687164 190.85807699590936 308.70107367172926 20 | 245.3015525636926 290.51739617797705 272.56750294428787 295.40005018665374 267.1380266362157 322.19448330367584 240.0258235118016 317.4179730677525 21 | 293.70515404531454 299.1425100185318 320.49315471146843 303.9079930738561 314.9709685632976 330.4501353807493 288.3718064614447 325.9360006618568 22 | 341.27168011925556 307.5200377950307 367.4543486937042 312.1467179942574 361.8989515792364 338.4082242208829 335.7905377706842 334.03840968184863 23 | 387.61397095150375 315.57312860649995 413.1762863456735 320.00419178181704 407.67746167039746 345.9750447393986 382.1918037913187 341.77414882301883 24 | 432.85379725703115 323.3358006879324 457.5735916783832 327.6021110012016 452.0195269320905 353.16060153120895 427.33229339972917 349.1258784826918 25 | 105.76987137759865 212.94380761429647 133.86341784552073 218.3243682054638 128.5027417029613 246.12452636828982 100.35523043011437 240.9175738603024 26 | 155.90726182663596 222.5838684841567 183.7834013023432 228.01251160830526 178.35233726023785 255.5657266122546 150.59350841396125 250.17865872716914 27 | 205.74754579084382 232.07514019977162 233.3641218064177 237.42671957663472 228.00114496417808 264.8574230645499 200.25241833499828 259.608501423578 28 | 255.01448793989965 241.45342474035775 282.29886907505824 246.64970037530634 276.8538534146699 273.8754357832947 249.57128497276983 268.78650806574564 29 | 303.5249047584565 250.65898774180872 330.25686698995366 255.7896290063299 324.76513513143516 282.55100968781915 298.0589736742378 277.75643707130865 30 | 351.1606006718723 259.63920826891535 377.3040070212308 264.4794019068752 371.72934859387374 291.23681546774765 345.5828817840472 286.27769879841264 31 | 397.5246027866596 268.23107809439415 422.9582048607481 273.10653885211696 417.5392693773936 299.29144709949884 391.9450117454264 294.7052081338683 32 | 442.6749445217156 276.60784060339756 467.3190107749417 281.43420158311955 461.97048467706946 307.05682531846037 437.271441028218 302.72198167939325 33 | 115.55515770161269 162.77631551896766 143.6530864805258 168.22649354512333 138.23084164188526 196.28513158618074 110.0229645662059 190.5406675597182 34 | 165.7239651344489 172.68245133907658 193.70996132113353 178.1958210317017 188.1551381055804 205.96002321106587 160.30700884319515 200.33684608596369 35 | 215.5811670509886 182.50929719856993 243.15949031726598 187.9892801639886 237.7426282541228 215.56318458680494 210.07622864904607 210.0738910253852 36 | 264.8471636771777 192.255739265883 292.0963448829428 197.75894621087588 286.7022850712927 224.69531378126143 259.4170219055687 219.56534802899228 37 | 313.2797347183294 201.9774639129238 340.1911514475721 207.29078231578347 334.5753895620433 234.18423526035906 307.8939504410158 229.16612658313724 38 | 360.92048234333413 211.40237541849658 387.0139417596264 216.6927838012499 381.6679757374664 243.34865103528432 355.38879334846763 238.28175611034075 39 | 407.2747766363627 220.57496933979866 432.7056791843601 225.89448979936458 427.3506875452972 252.1199906378452 401.84268745879825 247.272248994847 40 | 452.4328355521711 229.70137495840632 477.03154400964974 234.79210343126013 471.72318776943865 260.6094204065082 447.0132886723153 255.92023517572977 41 | 125.5000916587322 112.39703788025982 153.58127507982644 118.16018029272173 148.07508664276486 146.22323483670422 119.93469510554148 140.3758200373909 42 | 175.75003948223736 122.5925342852821 203.7219652884318 128.35552583073945 198.1070396518659 156.29961785548596 170.17277520337635 150.38275907712625 43 | 225.54837592523282 132.81346283315006 253.200324567384 138.56940995291606 247.65715212662687 166.17877447957312 220.02520005001026 160.38607568108728 44 | 274.81650943865327 143.00174967590672 301.9988863876711 148.78210638158492 296.530426380651 175.94310957500545 269.24576274021445 170.44235469554982 45 | 323.220998382946 153.10193278556466 349.9206132424254 158.77743082201474 344.4435927993162 185.7832506192083 317.75762884225895 180.3753806626757 46 | 370.74171260986896 163.09280096297266 396.82172992694854 168.73708198762768 391.35647418753575 195.43722962806592 365.19210055696107 190.10711368075775 47 | 416.95788441953715 172.93773537702012 442.3306151789606 178.51437897084827 437.0214859506541 204.8888216949907 411.5725912703093 199.62411820840916 48 | 461.94249916671635 182.6272619160663 486.4612870879415 188.07044458751966 481.29220897260325 214.01676674509065 456.6698066788524 208.82301962165832 49 | 135.59500108806986 62.45438144874405 163.55779211534053 68.2743985688686 158.02228403138136 96.18266682752143 129.81801069498675 90.32945660241154 50 | 185.6240791490438 72.85382636689017 213.4654752498429 78.76028475649173 208.08906810878747 106.48841442448054 179.99883732516614 100.68858267714339 51 | 235.34012260563037 83.37430640616488 263.004101327093 89.31252639364646 257.5474349256315 116.79330484088565 229.84946505431915 110.92585620362603 52 | 284.4691708117143 93.90734796651384 311.65781448065496 99.87946189717412 306.29362293636825 127.03098134841383 279.156819354787 121.20583775315431 53 | 332.833108988705 104.50707669328405 359.38819172285343 110.49463331376143 354.20112889718575 137.3264786363126 327.5300923567318 131.57247410126266 54 | 380.1922222397722 114.96845339129112 406.20689319837766 120.98439487394855 400.9728111354321 147.52589713438002 374.89836635509636 141.83878609055165 55 | 426.349378861027 125.44433125750037 451.5909600130173 131.29731806191666 446.508652458597 157.57520318877232 421.13505256859355 151.93360754071122 56 | 471.22500254530297 135.7352493232785 495.62649475833797 141.5012572759166 490.6189065818935 167.3052120286144 466.0912717811107 161.8957983694571 57 | 146.81572231828488 12.912321760037827 174.6124345770364 18.86776888618061 168.31790371926786 46.49860484869459 140.36841232896862 40.37465053849229 58 | 196.40807656079377 23.499184264817504 223.97972458218536 29.617183268638446 218.13947618786327 56.99210700269836 190.16322823797958 51.01695450887239 59 | 245.61747263405593 34.31023015857057 272.84991778123975 40.553668263635956 267.2163678282742 67.60137951804442 239.7378890741789 61.57492955919689 60 | 294.3435232270571 45.31418106954909 321.2199008716494 51.472664617370135 315.7892202591805 78.34344830605419 288.720260216587 72.36646103260509 61 | 342.2968085631704 56.3059646055059 368.6532260029473 62.493093345398805 363.5408535440886 89.00012806252981 336.9273090445368 83.1883384431734 62 | 389.3648436325567 67.3109068705477 415.13015144430096 73.47498305365527 410.2151554512924 99.78838265709642 384.2239879985347 93.81352446738174 63 | 435.31748654193984 78.14776640636657 460.3682072054251 84.45931435568009 455.5958662702366 110.38190724676545 430.27689679620255 104.56097359125799 64 | 479.9683091718671 89.10713199270751 504.21163339318167 95.19914907740346 499.5742300547517 120.81379002543706 475.14472073573745 115.05548468365943 65 | -------------------------------------------------------------------------------- /calib_data/zhang_data/model.txt: -------------------------------------------------------------------------------- 1 | 0 -0.5 0.5 -0.5 0.5 0 0 0 2 | 0.888889 -0.5 1.38889 -0.5 1.38889 0 0.888889 0 3 | 1.77778 -0.5 2.27778 -0.5 2.27778 0 1.77778 0 4 | 2.66667 -0.5 3.16667 -0.5 3.16667 0 2.66667 0 5 | 3.55556 -0.5 4.05556 -0.5 4.05556 0 3.55556 0 6 | 4.44444 -0.5 4.94444 -0.5 4.94444 0 4.44444 0 7 | 5.33333 -0.5 5.83333 -0.5 5.83333 0 5.33333 0 8 | 6.22222 -0.5 6.72222 -0.5 6.72222 0 6.22222 0 9 | 0 -1.38889 0.5 -1.38889 0.5 -0.888889 0 -0.888889 10 | 0.888889 -1.38889 1.38889 -1.38889 1.38889 -0.888889 0.888889 -0.888889 11 | 1.77778 -1.38889 2.27778 -1.38889 2.27778 -0.888889 1.77778 -0.888889 12 | 2.66667 -1.38889 3.16667 -1.38889 3.16667 -0.888889 2.66667 -0.888889 13 | 3.55556 -1.38889 4.05556 -1.38889 4.05556 -0.888889 3.55556 -0.888889 14 | 4.44444 -1.38889 4.94444 -1.38889 4.94444 -0.888889 4.44444 -0.888889 15 | 5.33333 -1.38889 5.83333 -1.38889 5.83333 -0.888889 5.33333 -0.888889 16 | 6.22222 -1.38889 6.72222 -1.38889 6.72222 -0.888889 6.22222 -0.888889 17 | 0 -2.27778 0.5 -2.27778 0.5 -1.77778 0 -1.77778 18 | 0.888889 -2.27778 1.38889 -2.27778 1.38889 -1.77778 0.888889 -1.77778 19 | 1.77778 -2.27778 2.27778 -2.27778 2.27778 -1.77778 1.77778 -1.77778 20 | 2.66667 -2.27778 3.16667 -2.27778 3.16667 -1.77778 2.66667 -1.77778 21 | 3.55556 -2.27778 4.05556 -2.27778 4.05556 -1.77778 3.55556 -1.77778 22 | 4.44444 -2.27778 4.94444 -2.27778 4.94444 -1.77778 4.44444 -1.77778 23 | 5.33333 -2.27778 5.83333 -2.27778 5.83333 -1.77778 5.33333 -1.77778 24 | 6.22222 -2.27778 6.72222 -2.27778 6.72222 -1.77778 6.22222 -1.77778 25 | 0 -3.16667 0.5 -3.16667 0.5 -2.66667 0 -2.66667 26 | 0.888889 -3.16667 1.38889 -3.16667 1.38889 -2.66667 0.888889 -2.66667 27 | 1.77778 -3.16667 2.27778 -3.16667 2.27778 -2.66667 1.77778 -2.66667 28 | 2.66667 -3.16667 3.16667 -3.16667 3.16667 -2.66667 2.66667 -2.66667 29 | 3.55556 -3.16667 4.05556 -3.16667 4.05556 -2.66667 3.55556 -2.66667 30 | 4.44444 -3.16667 4.94444 -3.16667 4.94444 -2.66667 4.44444 -2.66667 31 | 5.33333 -3.16667 5.83333 -3.16667 5.83333 -2.66667 5.33333 -2.66667 32 | 6.22222 -3.16667 6.72222 -3.16667 6.72222 -2.66667 6.22222 -2.66667 33 | 0 -4.05556 0.5 -4.05556 0.5 -3.55556 0 -3.55556 34 | 0.888889 -4.05556 1.38889 -4.05556 1.38889 -3.55556 0.888889 -3.55556 35 | 1.77778 -4.05556 2.27778 -4.05556 2.27778 -3.55556 1.77778 -3.55556 36 | 2.66667 -4.05556 3.16667 -4.05556 3.16667 -3.55556 2.66667 -3.55556 37 | 3.55556 -4.05556 4.05556 -4.05556 4.05556 -3.55556 3.55556 -3.55556 38 | 4.44444 -4.05556 4.94444 -4.05556 4.94444 -3.55556 4.44444 -3.55556 39 | 5.33333 -4.05556 5.83333 -4.05556 5.83333 -3.55556 5.33333 -3.55556 40 | 6.22222 -4.05556 6.72222 -4.05556 6.72222 -3.55556 6.22222 -3.55556 41 | 0 -4.94444 0.5 -4.94444 0.5 -4.44444 0 -4.44444 42 | 0.888889 -4.94444 1.38889 -4.94444 1.38889 -4.44444 0.888889 -4.44444 43 | 1.77778 -4.94444 2.27778 -4.94444 2.27778 -4.44444 1.77778 -4.44444 44 | 2.66667 -4.94444 3.16667 -4.94444 3.16667 -4.44444 2.66667 -4.44444 45 | 3.55556 -4.94444 4.05556 -4.94444 4.05556 -4.44444 3.55556 -4.44444 46 | 4.44444 -4.94444 4.94444 -4.94444 4.94444 -4.44444 4.44444 -4.44444 47 | 5.33333 -4.94444 5.83333 -4.94444 5.83333 -4.44444 5.33333 -4.44444 48 | 6.22222 -4.94444 6.72222 -4.94444 6.72222 -4.44444 6.22222 -4.44444 49 | 0 -5.83333 0.5 -5.83333 0.5 -5.33333 0 -5.33333 50 | 0.888889 -5.83333 1.38889 -5.83333 1.38889 -5.33333 0.888889 -5.33333 51 | 1.77778 -5.83333 2.27778 -5.83333 2.27778 -5.33333 1.77778 -5.33333 52 | 2.66667 -5.83333 3.16667 -5.83333 3.16667 -5.33333 2.66667 -5.33333 53 | 3.55556 -5.83333 4.05556 -5.83333 4.05556 -5.33333 3.55556 -5.33333 54 | 4.44444 -5.83333 4.94444 -5.83333 4.94444 -5.33333 4.44444 -5.33333 55 | 5.33333 -5.83333 5.83333 -5.83333 5.83333 -5.33333 5.33333 -5.33333 56 | 6.22222 -5.83333 6.72222 -5.83333 6.72222 -5.33333 6.22222 -5.33333 57 | 0 -6.72222 0.5 -6.72222 0.5 -6.22222 0 -6.22222 58 | 0.888889 -6.72222 1.38889 -6.72222 1.38889 -6.22222 0.888889 -6.22222 59 | 1.77778 -6.72222 2.27778 -6.72222 2.27778 -6.22222 1.77778 -6.22222 60 | 2.66667 -6.72222 3.16667 -6.72222 3.16667 -6.22222 2.66667 -6.22222 61 | 3.55556 -6.72222 4.05556 -6.72222 4.05556 -6.22222 3.55556 -6.22222 62 | 4.44444 -6.72222 4.94444 -6.72222 4.94444 -6.22222 4.44444 -6.22222 63 | 5.33333 -6.72222 5.83333 -6.72222 5.83333 -6.22222 5.33333 -6.22222 64 | 6.22222 -6.72222 6.72222 -6.72222 6.72222 -6.22222 6.22222 -6.22222 65 | -------------------------------------------------------------------------------- /scripts/blender_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import os 4 | import bpy 5 | from mathutils import Matrix 6 | 7 | 8 | def readKs(path): 9 | with open(path, 'r') as f: 10 | data = f.read().split("\n") 11 | #a_data = data[0].split(",") 12 | #k_data = data[1].split(",") 13 | ks_data = [] 14 | for i in range(2, len(data)-1): 15 | K_data = data[i].split(",") 16 | m = Matrix() 17 | idx = 0 18 | for j in range(0, 3): 19 | for k in range(0, 4): 20 | m[j][k] = float(K_data[idx]) 21 | idx += 1 22 | ks_data.append(m) 23 | print(m) 24 | 25 | return ks_data 26 | 27 | m = readKs("/home/relja/git/camera_calibration/a.out") 28 | bpy.data.objects['camera_test'].matrix_local = m[0] 29 | bpy.data.objects['camera_test'].scale = [1, -1, -1] -------------------------------------------------------------------------------- /scripts/camera.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | import math 3 | 4 | scene = bpy.context.scene 5 | render = bpy.context.scene.render 6 | 7 | #----------------------------------------------- 8 | # view port 9 | 10 | render.engine = 'CYCLES' 11 | render.filepath = '//' 12 | render.resolution_x = 1920 13 | render.resolution_y = 1080 14 | render.resolution_percentage = 100 15 | 16 | scene.cycles.device = 'GPU' 17 | 18 | #----------------------------------------------- 19 | # K 20 | camdata = bpy.data.cameras.new('cameraData') 21 | camdata.lens_unit = 'FOV' 22 | 23 | f = float(1000) 24 | fx = float(1000) 25 | fy = float(1000) 26 | ppx = float(958) 27 | ppy = float(562) 28 | 29 | maxdim = max(render.resolution_x,render.resolution_y) 30 | 31 | #camdata.angle = 2*math.atan(0.5*maxdim/f) 32 | camdata.angle_x=2*math.atan(0.5*render.resolution_x/fx); 33 | camdata.angle_y=2*math.atan(0.5*render.resolution_y/fy); 34 | 35 | # the unit of shiftXY is FOV unit (Lens Shift) 36 | camdata.shift_x = (ppx - render.resolution_x/2.0)/maxdim 37 | camdata.shift_y = (ppy- render.resolution_y/2.0)/maxdim 38 | 39 | camdata.dof_distance = 0.0 40 | camdata.clip_end = 1000.0 41 | 42 | #----------------------------------------- 43 | # OBJECT TYPE 44 | cam = bpy.data.objects.new('camera', camdata) 45 | # 46 | # flip axis to top-left 47 | cam.scale=(1,-1,-1); 48 | 49 | scene.objects.link(cam) 50 | scene.objects.active = cam 51 | cam.select = True -------------------------------------------------------------------------------- /src/calib.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "calib.hpp" 6 | 7 | 8 | cv::vectorr get_vij(const cv::matrixr &h, unsigned i, unsigned j) { 9 | return cv::vectorr { 10 | h(0, i)*h(0, j), h(0, i)*h(1, j) + h(1, i)*h(0, j), h(1, i)*h(1, j), 11 | h(2, i)*h(0, j) + h(0, i)*h(2, j), h(2, i)*h(1, j) + h(1, i)*h(2, j), h(2, i)*h(2, j) 12 | }; 13 | } 14 | 15 | cv::matrixr pack_v(const std::vector &Hs) { 16 | cv::matrixr v(2*Hs.size(), 6); 17 | 18 | for (unsigned i = 0; i < Hs.size(); ++i) { 19 | 20 | auto h_r_1 = v.row(i*2); 21 | auto h_r_2 = v.row(i*2 + 1); 22 | 23 | auto v12 = get_vij(Hs[i], 0, 1); 24 | auto v11 = get_vij(Hs[i], 0, 0); 25 | auto v22 = get_vij(Hs[i], 1, 1); 26 | auto v11_v22 = v11 - v22; 27 | 28 | std::copy(v12.begin(),v12.end(),h_r_1.begin()); 29 | std::copy(v11_v22.begin(), v11_v22.end(), h_r_2.begin()); 30 | } 31 | 32 | return v; 33 | } 34 | 35 | cv::vectorr solve_b(const cv::matrixr &V) { 36 | 37 | cv::matrixr U, S, Vt; 38 | cv::sv_decomp(V, U, S, Vt); 39 | 40 | return Vt.transposed().col(Vt.cols() - 1); 41 | } 42 | 43 | cv::matrixr get_B_from_b(const cv::vectorr &b) { 44 | return { 45 | {b[0], b[1], b[3]}, 46 | {b[1], b[2], b[4]}, 47 | {b[3], b[4], b[5]} 48 | }; 49 | } 50 | 51 | bool extract_intrinsics_from_B(const cv::matrixr &B, real_t &u0, real_t &v0, 52 | real_t &lambda, real_t &alpha, real_t &beta, real_t &gama) { 53 | auto den = B(0, 0) * B(2, 2) - B(0, 1)*B(0, 1); 54 | 55 | if (fabs(den) < 1e-8) { 56 | std::cout << "Den < 1e-8" << std::endl; 57 | return false; 58 | } 59 | 60 | v0 = (B(0, 1)*B(0, 2) - B(0, 0)*B(1, 2)) / (B(0, 0)*B(1, 1) - B(0, 1)*B(0, 1)); 61 | lambda = B(2, 2) - (B(0, 1)*B(0, 1) + v0*(B(0, 1)*B(0, 2) - B(0, 0)*B(1, 2))) / B(0, 0); 62 | auto l = (lambda / B(0, 0)); 63 | if (l < .0) { 64 | std::cout << "L < 0: " << l << std::endl; 65 | return false; 66 | } 67 | alpha = sqrt(l); 68 | auto b =(lambda*B(0, 0))/(B(0, 0)*B(1, 1) - B(0, 1)*B(0, 1)); 69 | if (b < .0) { 70 | std::cout << "beta < 0: " << b << std::endl; 71 | return false; 72 | } 73 | beta = sqrt(b); 74 | gama = (-1*B(0, 1)*(alpha*alpha)*beta)/lambda; 75 | u0 = (gama*v0)/alpha - (B(0, 2)*(alpha*alpha))/lambda; 76 | 77 | return true; 78 | } 79 | 80 | cv::matrixr get_intrinsic_mat(const cv::matrixr &B) { 81 | 82 | real_t u0, v0, a, b, c, lambda; 83 | if (extract_intrinsics_from_B(B, u0, v0, lambda, a, b, c)) { 84 | return { 85 | {a, c, u0}, 86 | {0., b, v0}, 87 | {0., 0., 1.} 88 | }; 89 | } else { 90 | std::cerr << "Failure calculation A'" << std::endl; 91 | return cv::matrixr(); 92 | } 93 | } 94 | 95 | std::vector calculate_object_points(unsigned rows, unsigned cols, real_t square_size) { 96 | 97 | std::vector obj_pts; 98 | obj_pts.reserve(rows*cols); 99 | 100 | for(unsigned i = 0; i < rows; ++i) { 101 | for(unsigned j = 0; j < cols; ++j) { 102 | obj_pts.push_back({static_cast(j*square_size), static_cast(i*square_size), 1.}); 103 | } 104 | } 105 | 106 | return obj_pts; 107 | } 108 | 109 | cv::matrixr normalize_image_points(std::vector > &patterns, unsigned w, unsigned h) { 110 | 111 | real_t sx = 2. / w; 112 | real_t sy = 2. / h; 113 | real_t x0 = w / 2.; 114 | real_t y0 = h / 2.; 115 | 116 | for(unsigned i = 0; i < patterns.size(); ++i) { 117 | for(unsigned j = 0; j < patterns[i].size(); ++j) { 118 | patterns[i][j][0] = sx*(patterns[i][j][0]-x0); 119 | patterns[i][j][1] = sy*(patterns[i][j][1]-y0); 120 | } 121 | } 122 | 123 | return { 124 | {sx, 0., -sx*x0}, 125 | {0., sy, -sy*y0}, 126 | {0., 0., 1.} 127 | }; 128 | } 129 | 130 | cv::vectorr reproject_point(const cv::vectorr &world_ptn, const cv::matrixr &A, const cv::matrixr &K, const cv::vectorr &k) { 131 | ASSERT(world_ptn.length() == 4); 132 | 133 | auto proj_ptn = K * world_ptn; 134 | proj_ptn /= proj_ptn[2]; 135 | 136 | if (k.length() == 2) { 137 | real_t r2 = proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1] + 1; 138 | real_t d_r = (1 + k[0]*r2 + k[1]*(r2*r2)); // radial distortion 139 | proj_ptn[0] = proj_ptn[0]*d_r; 140 | proj_ptn[1] = proj_ptn[1]*d_r; 141 | } else if (k.length() == 4) { 142 | real_t r2 = proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1] + 1; 143 | real_t d_r = (1 + k[0]*r2 + k[1]*(r2*r2)); // radial distortion 144 | real_t d_t = 2 * k[2]*proj_ptn[0]*proj_ptn[1] + k[3]*(r2 + 2*(proj_ptn[0]*proj_ptn[0])); // tan distortion 145 | proj_ptn[0] = proj_ptn[0]*d_r+ d_t; 146 | proj_ptn[1] = proj_ptn[1]*d_r+ d_t; 147 | } else if (k.length() == 8) { 148 | real_t r2 = proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1] + 1; 149 | real_t r3 = proj_ptn[0]*proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1]*proj_ptn[1] + 1; 150 | real_t k_u = 1 + k[0]*r2 + k[1]*(r2*r2) + k[2]*(r3*r3); 151 | real_t k_d = 1 + k[3]*r2 + k[4]*(r2*r2) + k[5]*(r3*r3); 152 | real_t d_r = (k_d) ? k_u / k_d : 0.; // radial distortion 153 | real_t d_t = 2 * k[2]*proj_ptn[0]*proj_ptn[1] + k[3]*(r2 + 2*(proj_ptn[0]*proj_ptn[0])); // tan distortion 154 | proj_ptn[0] = proj_ptn[0]*d_r+ d_t; 155 | proj_ptn[1] = proj_ptn[1]*d_r+ d_t; 156 | } 157 | 158 | auto pp_vec = A * cv::vectorr{proj_ptn[0], proj_ptn[1], proj_ptn[2]}; 159 | 160 | return {pp_vec[0] / pp_vec[2], pp_vec[1] / pp_vec[2] }; 161 | } 162 | 163 | cv::matrixr denormalize_intrinsics(const cv::matrixr &A_p, const cv::matrixr &N) { 164 | auto N_inv = N.clone(); 165 | cv::invert(N_inv); 166 | return (N_inv*A_p); 167 | } 168 | 169 | real_t calc_reprojection(const cv::matrixr &A, const cv::matrixr &K, 170 | const std::vector &model_pts, const std::vector &image_pts, 171 | std::vector &image_pts_proj, const cv::vectorr &k) { 172 | ASSERT(model_pts.size() == image_pts.size()); 173 | 174 | auto m = model_pts.size(); 175 | 176 | image_pts_proj = std::vector(m); 177 | 178 | cv::vectorr model(4); 179 | 180 | real_t err = 0.; 181 | for(unsigned i = 0; i < m; i++) { 182 | 183 | model[0] = model_pts[i][0]; 184 | model[1] = model_pts[i][1]; 185 | model[2] = 0.0; 186 | model[3] = 1.0; 187 | 188 | auto proj_ptn = reproject_point(model, A, K, k); 189 | image_pts_proj[i] = {proj_ptn[0], proj_ptn[1]}; 190 | 191 | // calculate projection error 192 | auto x_d = image_pts[i][0] - proj_ptn[0]; 193 | auto y_d = image_pts[i][1] - proj_ptn[1]; 194 | 195 | x_d*=x_d; 196 | y_d*=y_d; 197 | 198 | err += sqrt(x_d + y_d); 199 | } 200 | 201 | return err / m; 202 | } 203 | 204 | cv::matrix3b draw_reprojection(const std::vector &image_pts, 205 | const std::vector &image_pts_proj, unsigned im_w, unsigned im_h, real_t scale) { 206 | 207 | ASSERT(image_pts.size() == image_pts_proj.size()); 208 | 209 | cv::matrix3b reprojection = cv::matrix3b::zeros(im_h*scale,im_w*scale); 210 | 211 | for (unsigned i = 0; i < image_pts.size(); ++i) { 212 | cv::draw_circle(reprojection, image_pts[i]*scale, 5, cv::vec3b(255, 255, 255)); 213 | cv::draw_circle(reprojection, image_pts_proj[i]*scale, 8, cv::vec3b(0, 255, 0)); 214 | } 215 | 216 | return reprojection; 217 | } 218 | 219 | cv::matrixr compute_intrisics(const std::vector &Hs) { 220 | 221 | auto V = pack_v(Hs); 222 | auto b = solve_b(V); 223 | auto B = get_B_from_b(b); 224 | 225 | return get_intrinsic_mat(B); 226 | } 227 | 228 | cv::matrixr compute_extrinsics(const cv::matrixr &A, const cv::matrixr &H) { 229 | 230 | auto Ainv = A.clone(); 231 | cv::invert(Ainv); 232 | 233 | cv::matrixr K(3, 4); 234 | 235 | auto h1 = H.col(0); 236 | auto h2 = H.col(1); 237 | auto h3 = H.col(2); 238 | 239 | auto r1 = Ainv * h1; 240 | auto r2 = Ainv * h2; 241 | 242 | real_t l1 = 1. / r1.norm(); 243 | real_t l2 = 1. / r2.norm(); 244 | real_t l3 = (l1 + l2) / 2.; 245 | 246 | r1 *= l1; 247 | r2 *= l2; 248 | auto r3 = r1.cross(r2); 249 | 250 | auto t = (Ainv * h3) * l3; 251 | 252 | cv::matrixr R = { 253 | {r1[0], r2[0], r3[0]}, 254 | {r1[1], r2[1], r3[1]}, 255 | {r1[2], r2[2], r3[2]} 256 | }; 257 | 258 | // reorthogonalize R 259 | cv::matrixr U, S, Vt, Rt; 260 | cv::sv_decomp(R, U, S, Vt); 261 | 262 | R = U * Vt; 263 | 264 | r1 = R.col(0); 265 | r2 = R.col(1); 266 | r3 = R.col(2); 267 | 268 | auto c1 = K.col(0); 269 | auto c2 = K.col(1); 270 | auto c3 = K.col(2); 271 | auto c4 = K.col(3); 272 | 273 | std::copy(r1.begin(), r1.end(), c1.begin()); 274 | std::copy(r2.begin(), r2.end(), c2.begin()); 275 | std::copy(r3.begin(), r3.end(), c3.begin()); 276 | std::copy(t.begin(), t.end(), c4.begin()); 277 | 278 | return K; 279 | } 280 | 281 | cv::vectorr compute_distortion(const std::vector> &image_pts, const std::vector> &image_pts_nrm, 282 | const std::vector> &image_pts_proj, const cv::matrixr &A) { 283 | 284 | ASSERT(!image_pts.empty() && !image_pts_nrm.empty() && !image_pts_proj.empty()); 285 | ASSERT(image_pts.front().size() == image_pts_nrm.front().size() && 286 | image_pts.front().size() == image_pts_proj.front().size()); 287 | 288 | cv::vectorr k = {0., 0., 0., 0., 0., 0., 0., 0.}; 289 | real_t Uo,Vo,u_uo,v_vo, x2_y2; 290 | 291 | unsigned n_pts = image_pts.front().size(); 292 | 293 | cv::matrixr D(image_pts.size()*n_pts*2, 2); 294 | cv::matrixr d(image_pts.size()*n_pts*2, 1); 295 | 296 | Uo = A(0, 2); 297 | Vo = A(1, 2); 298 | 299 | for (unsigned b = 0; b < image_pts.size(); ++b) { 300 | for (unsigned i = 0; i < n_pts; i++) { 301 | 302 | x2_y2 = (image_pts_nrm[b][i] * image_pts_nrm[b][i]).sum(); 303 | u_uo = image_pts_proj[b][i][0] - Uo; 304 | v_vo = image_pts_proj[b][i][1] - Vo; 305 | 306 | D(i*2, 0) = (u_uo)*(x2_y2); 307 | D(i*2, 1) = (u_uo)*(x2_y2)*(x2_y2); 308 | 309 | D(i*2 + 1, 0) = (v_vo)*(x2_y2); 310 | D(i*2 + 1, 1) = (v_vo)*(x2_y2)*(x2_y2); 311 | 312 | d(i*2, 0) = image_pts[b][i][0] - image_pts_proj[b][i][0]; 313 | d(i*2+1, 0) = image_pts[b][i][1] - image_pts_proj[b][i][1]; 314 | } 315 | } 316 | 317 | cv::matrixr K; 318 | cv::lu_solve(D, d, K); 319 | 320 | k[0] = K.data()[0]; 321 | k[1] = K.data()[1]; 322 | 323 | return k; 324 | } 325 | 326 | 327 | -------------------------------------------------------------------------------- /src/calib.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CALIB_HPP_Q5H9DDXY 3 | #define CALIB_HPP_Q5H9DDXY 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /*! 12 | * @brief Calculate object points for chessboard pattern used as calibration object. 13 | * 14 | * @param rows rows of corners present in the chessboard pattern. 15 | * @param cols columns of corners present in the chessboard pattern. 16 | * @param square_size real world size of the single chessboard square in generic units. 17 | * 18 | * @return 19 | * std::vector world points of chessboard pattern with Z = 1, where X, Y is 2D homogenious point. 20 | */ 21 | std::vector calculate_object_points(unsigned rows, unsigned cols, real_t square_size); 22 | 23 | /*! 24 | * @brief Normalize image points used in calibration process. 25 | * 26 | * @param patterns vector of vector, as in list of chessboard pattern image point corners. 27 | * @param w width of the image from which the pattern is extracted. 28 | * @param h height of the image from which the pattern is extracted. 29 | * 30 | * @return 31 | * Returns normalization matrix: 32 | * [2/w 0 -1] 33 | * [0 2/h -1 34 | * [0 0 1] 35 | */ 36 | cv::matrixr normalize_image_points(std::vector > &patterns, unsigned w, unsigned h); 37 | 38 | /*! 39 | * @brief Denormalize intrinsic matrix. 40 | * 41 | * @param A_p intrincis matrix calculated using normalized image points. 42 | * @param N Normalization matrix composed using normalize_image_points function. 43 | * 44 | * @return 45 | * De-normalized intrinsic matrix. 46 | */ 47 | cv::matrixr denormalize_intrinsics(const cv::matrixr &A_p, const cv::matrixr &N); 48 | 49 | /*! 50 | * @brief Calculate reprojection for given world (model) point. 51 | * 52 | * @param world_ptn 4D model point. 53 | * @param A intrinsic matrix. (3x3) 54 | * @param K extrinsic matrix [R | t] (3x4) 55 | * @param k radial and tangential distortion cofficients. [k1, k2, (k3, k4, k5, k6), p1, p2] 56 | */ 57 | cv::vectorr reproject_point(const cv::vectorr &world_ptn, const cv::matrixr &A, const cv::matrixr &K, const cv::vectorr &k); 58 | /*! 59 | * @brief Calculate reprojection error using given intrinsic and extrinsic matrices, and image and world points 60 | * used to calculate those. 61 | * 62 | * @param A intrinsic 3x3 matrix 63 | * @param K extrinsic [r1 r2 r3 t] 3x4 matrix. 64 | * @param model_pts world points of the pattern used for calibration. 65 | * @param image_pts image points of the pattern used for calibration. 66 | * @param image_pts_proj vector of points where reprojected points will be stored. 67 | * 68 | * @return 69 | * square error of reprojection. 70 | */ 71 | real_t calc_reprojection(const cv::matrixr &A, const cv::matrixr &K, 72 | const std::vector &model_pts, const std::vector &image_pts, 73 | std::vector &image_pts_proj, const cv::vectorr &k = cv::vectorr()); 74 | 75 | /*! 76 | * @brief Compute intrinsic 3x3 matrix A from set of homography matrices calculated using calibration patterns. 77 | * 78 | * @param Hs vector of 3x3 homography matrices. 79 | * 80 | * @return 81 | * 3x3 intrinsic matrix A. 82 | */ 83 | cv::matrixr compute_intrisics(const std::vector &Hs); 84 | 85 | /*! 86 | * @brief Compute extrinsic 3x4 matrix using intrisic matrix and homogaphy matrix. 87 | * 88 | * @param A intrinsic 3x3 matrix. 89 | * @param H homography which relates one of pattern image corner points to world points of the pattern. 90 | * 91 | * @return 92 | * 3x4 extrinsic matrix. 93 | */ 94 | cv::matrixr compute_extrinsics(const cv::matrixr &A, const cv::matrixr &H); 95 | 96 | /*! 97 | * @brief Compute lens distortion parameters k1, and k2. 98 | * 99 | * @param image_pts vector of calibration pattern corners. 100 | * @param image_pts_nrm normalized copy of image_pts, used originally for calibration. 101 | * @param image_pts_proj reprojected image points, calculated using calc_reprojection function. 102 | * @param A intrinsic matrix of the camera. 103 | * 104 | * @return 105 | * 2d real vector with [k1, k2] as values. 106 | */ 107 | cv::vectorr compute_distortion(const std::vector> &image_pts, const std::vector> &image_pts_nrm, 108 | const std::vector> &image_pts_proj, const cv::matrixr &A); 109 | 110 | /*! 111 | * @brief Draw the reprojected points, from world to image plane, using calculated camera parameters. 112 | * 113 | * Draws image points with smaller blue circle, and reprojection with larger red circles. 114 | * 115 | * @param image_pts image points from calibration pattern 116 | * @param image_pts_proj reprojected points calculated using calc_reprojection function 117 | * @param im_w image width 118 | * @param im_h image height 119 | */ 120 | cv::matrix3b draw_reprojection(const std::vector &image_pts, 121 | const std::vector &image_pts_proj, unsigned im_w, unsigned im_h, real_t scale = 1.0); 122 | 123 | 124 | #endif /* end of include guard: CALIB_HPP_Q5H9DDXY */ 125 | 126 | -------------------------------------------------------------------------------- /src/calibpattern.cpp: -------------------------------------------------------------------------------- 1 | #include "calibpattern.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // debug 11 | #include 12 | #include 13 | 14 | #ifdef LINE_DEBUG 15 | cv::matrix3r draw_image; 16 | #endif 17 | 18 | // forward declaration 19 | std::vector > find_nns(std::vector &features, unsigned nncount); 20 | 21 | std::vector detect_lines(std::vector &features, std::vector > &nns, real_t angleThresh, real_t magThresh, unsigned rows, unsigned cols); 22 | 23 | cv::contouri detect_line(unsigned startIdx, unsigned queryIdx, std::vector &features, std::vector< 24 | std::vector >&nns, real_t angleThreshold, real_t magThreshold, unsigned rows, unsigned cols); 25 | 26 | 27 | std::vector detect_chessboard(const std::vector &contours, unsigned rows, unsigned cols); 28 | 29 | // Implementation 30 | template 31 | bool is_aproximation(const _Tp &query, const _Tp &source, const _Tp &error) { 32 | return (fabs(source - query) < error); 33 | } 34 | 35 | std::vector > find_nns(std::vector &features, unsigned nncount) { 36 | 37 | std::vector > nns(features.size()); 38 | 39 | cv::kd_tree2i kd; 40 | std::vector data; 41 | 42 | for (auto & f : features) { 43 | data.push_back(f); 44 | } 45 | 46 | kd.set_data(data); 47 | kd.build(); 48 | 49 | for (unsigned i = 0; i < features.size(); ++i) { 50 | auto &f = features[i]; 51 | 52 | kd.knn_index(f, nncount, nns[i]); 53 | 54 | auto pos = std::find(nns[i].begin(), nns[i].end(), i); 55 | if (pos != nns[i].end()) { 56 | nns[i].erase(pos); 57 | } 58 | std::sort(nns[i].begin(), nns[i].end()); 59 | nns[i].erase(std::unique(nns[i].begin(), nns[i].end()), nns[i].end()); 60 | } 61 | 62 | return nns; 63 | } 64 | 65 | std::vector detect_lines(std::vector &features, std::vector > &nns, real_t angleThresh, real_t magThresh, unsigned rows, unsigned cols) { 66 | 67 | std::vector lines; 68 | 69 | for (unsigned i = 0; i < features.size(); i++) { 70 | for (unsigned j = 0; j < nns[i].size(); j++) { 71 | cv::contouri c = detect_line(i, nns[i][j], features, nns, angleThresh, magThresh, rows, cols); 72 | if (!c.empty()) { 73 | lines.push_back(c); 74 | } 75 | } 76 | } 77 | 78 | return lines; 79 | } 80 | 81 | cv::contouri detect_line(unsigned startIdx, unsigned queryIdx, std::vector &features, std::vector< 82 | std::vector >&nns, real_t angleThreshold, real_t magThreshold, unsigned rows, unsigned cols) { 83 | 84 | cv::contouri line; 85 | line.add_points( { features[startIdx], features[queryIdx] }); 86 | 87 | 88 | #ifdef LINE_DEBUG 89 | auto im = draw_image.clone(); 90 | 91 | cv::vec3r line_color = {255., 255., 0.}; 92 | cv::vec3r nn_color = {0., 0., 255.}; 93 | cv::vec3r hit_color = {0., 255., 0.}; 94 | cv::vec3r break_color = {255., 0., 0.}; 95 | 96 | cv::draw_circle(im, features[startIdx], 6, line_color); 97 | cv::draw_contour(im, line, line_color); 98 | #endif 99 | 100 | while (true) { 101 | 102 | auto edgeVec = features[queryIdx] - features[startIdx]; 103 | 104 | int bestId = -1; 105 | real_t bestAngle = angleThreshold; 106 | real_t bestMagnitureError = magThreshold; 107 | 108 | #ifdef LINE_DEBUG 109 | for (auto nn : nns[queryIdx]) { 110 | cv::draw_circle(im, features[nn], 3, nn_color); 111 | } 112 | cv::draw_circle(im, features[queryIdx], 6, line_color); 113 | #endif 114 | 115 | for (auto nn : nns[queryIdx]) { 116 | 117 | if (nn == queryIdx || nn == startIdx) { 118 | continue; 119 | } 120 | 121 | auto queryVec = features[nn] - features[queryIdx]; 122 | 123 | real_t ang = RAD_TO_DEG(edgeVec.angle(queryVec)); 124 | real_t mag = 1.0 - ((edgeVec.norm() < queryVec.norm()) ? (edgeVec.norm() / queryVec.norm()) : (queryVec.norm() / edgeVec.norm())); 125 | 126 | if (ang < angleThreshold && mag < magThreshold && ang < bestAngle && mag < bestMagnitureError) { 127 | bestId = nn; 128 | bestAngle = ang; 129 | bestMagnitureError = mag; 130 | #ifdef LINE_DEBUG 131 | cv::draw_circle(im, features[bestId], 3, hit_color); 132 | #endif 133 | } else { 134 | #ifdef LINE_DEBUG 135 | cv::draw_circle(im, features[nn], 6, break_color); 136 | cv::imshow("line detect", im); 137 | auto c = cv::wait_key(); 138 | if (c == 'q') 139 | break; 140 | #endif 141 | } 142 | } 143 | 144 | if (bestId != -1) { 145 | startIdx = queryIdx; 146 | queryIdx = bestId; 147 | line.add_point(features[bestId]); 148 | 149 | #ifdef LINE_DEBUG 150 | cv::draw_contour(im, line, line_color); 151 | for (auto p : line) { 152 | cv::draw_circle(im, p, 5, line_color); 153 | } 154 | #endif 155 | } else { 156 | #ifdef LINE_DEBUG 157 | cv::draw_contour(im, line, break_color); 158 | #endif 159 | break; 160 | } 161 | 162 | #ifdef LINE_DEBUG 163 | cv::imshow("line detect", im); 164 | cv::wait_key(); 165 | #endif 166 | } 167 | 168 | unsigned line_size = line.point_length(); 169 | 170 | if (line_size == rows || line_size == cols) { 171 | #ifdef LINE_DEBUG 172 | cv::draw_contour(im, line, hit_color); 173 | cv::imshow("line detect", im); 174 | cv::wait_key(); 175 | #endif 176 | return line; 177 | } else { 178 | unsigned lesser = std::min(rows, cols); 179 | unsigned larger = std::max(rows, cols); 180 | if (line_size > lesser && line_size < larger) { 181 | line = cv::contouri(line.begin(), line.begin() + lesser); 182 | #ifdef LINE_DEBUG 183 | cv::draw_contour(im, line, hit_color); 184 | cv::imshow("line detect", im); 185 | cv::wait_key(); 186 | #endif 187 | return line; 188 | } else { 189 | #ifdef LINE_DEBUG 190 | cv::draw_contour(im, line, line_color); 191 | cv::imshow("line detect", im); 192 | cv::wait_key(); 193 | #endif 194 | return cv::contouri(); 195 | } 196 | } 197 | } 198 | 199 | std::vector sub_pixel_detect(const std::vector &corners, const cv::matrixr &src, const cv::vec2i &win, real_t eps, unsigned maxIters) { 200 | 201 | std::vector outCorners(corners.size()); 202 | 203 | const int MAX_ITERS = 100; 204 | const cv::matrixr drv_x = {{-1., 0, 1.}}; 205 | const cv::matrixr drv_y = drv_x.transposed(); 206 | cv::matrixr gx; 207 | cv::matrixr gy; 208 | cv::matrixr src_d = src; 209 | cv::matrixr scr_kernel; 210 | real_t coeff; 211 | int i, j, k, pt_i; 212 | int win_w = win[1] * 2 + 1, win_h = win[0] * 2 + 1; 213 | 214 | if (eps < 0.) 215 | eps = 0.; 216 | eps *= eps; /* use square of error in comparsion operations. */ 217 | 218 | unsigned max_iters = std::max((int) maxIters, 1); 219 | max_iters = std::min((int) max_iters, MAX_ITERS); 220 | 221 | coeff = 1. / (win[0] * win[1]); 222 | 223 | cv::vector maskX(win_w), maskY(win_h); 224 | /* calculate mask */ 225 | for (i = -win[1], k = 0; i <= win[1]; i++, k++) { 226 | maskX[k] = (real_t) exp(-i * i * coeff); 227 | } 228 | if (win[0] == win[1]) { 229 | maskY = maskX; 230 | } else { 231 | for (i = -win[0], k = 0; i <= win[0]; i++, k++) { 232 | maskY[k] = (real_t) exp(-i * i * coeff); 233 | } 234 | } 235 | 236 | cv::matrixr mask(win_h, win_w); 237 | 238 | for (i = 0; i < win_h; i++) { 239 | for (j = 0; j < win_w; j++) { 240 | mask(i, j) = maskX[j] * maskY[i]; 241 | } 242 | } 243 | 244 | /* do optimization loop for all the points */ 245 | for (pt_i = 0; pt_i < corners.size(); pt_i++) { 246 | cv::vec2r cT = (cv::vec2r) corners[pt_i], cI = cT; 247 | 248 | int iter = 0; 249 | real_t err; 250 | 251 | real_t a, b, c, bb1, bb2; 252 | 253 | do { 254 | cv::vec2r cI2; 255 | scr_kernel.create(cI[1] - win_h / 2, cI[0] - win_w / 2, win_h, win_w, src_d); 256 | 257 | /* calc derivatives */ 258 | gx = cv::conv(scr_kernel, drv_x); 259 | gy = cv::conv(scr_kernel, drv_y); 260 | 261 | a = b = c = bb1 = bb2 = 0; 262 | 263 | for (i = 0; i < win_w; i++) { 264 | real_t py = i - win[0]; 265 | 266 | for (j = 0; j < win_h; j++) { 267 | real_t m = mask(i, j); 268 | real_t tgx = gx(i, j); 269 | real_t tgy = gy(i, j); 270 | real_t gxx = tgx * tgx * m; 271 | real_t gxy = tgx * tgy * m; 272 | real_t gyy = tgy * tgy * m; 273 | real_t px = j - win[1]; 274 | 275 | a += gxx; 276 | b += gxy; 277 | c += gyy; 278 | 279 | bb1 += gxx * px + gxy * py; 280 | bb2 += gxy * px + gyy * py; 281 | } 282 | } 283 | 284 | real_t det = a * c - b * b; 285 | if (fabs(det) > std::numeric_limits::epsilon() * std::numeric_limits::epsilon()) { 286 | real_t scale = 1.0 / det; 287 | cI2[0] = cI[0] + c * scale * bb1 - b * scale * bb2; 288 | cI2[1] = cI[1] - b * scale * bb1 + a * scale * bb2; 289 | } else { 290 | cI2 = cI; 291 | } 292 | 293 | err = (cI2[0] - cI[0]) * (cI2[0] - cI[0]) + (cI2[1] - cI[1]) * (cI2[1] - cI[1]); 294 | cI = cI2; 295 | } while (++iter < max_iters && err > eps); 296 | if (fabs(cI[0] - cT[0]) > win[1] || fabs(cI[1] - cT[1]) > win[0]) { 297 | cI = cT; 298 | } 299 | outCorners[pt_i] = cI; /* store result */ 300 | } 301 | 302 | return outCorners; 303 | } 304 | 305 | std::vector detect_chessboard(const std::vector &contours, unsigned rows, unsigned cols) { 306 | std::vector chessboard_corners; 307 | 308 | std::vector hip_chess; 309 | for (auto c : contours) { 310 | if (c.point_length() == rows) { 311 | hip_chess.clear(); 312 | 313 | cv::contouri sorted_c(c); 314 | sorted_c.sort_by_axis(1); // sort by y 315 | 316 | for (auto p : sorted_c) { 317 | for (unsigned i = 0; i < contours.size(); ++i) { 318 | if (contours[i].point_length() != cols) { 319 | continue; 320 | } 321 | cv::vec2r c_q_vec = contours[i].get_contour_vector(); 322 | if ((p == contours[i][0] || p == contours[i][contours[i].point_length()-1])) { 323 | if (hip_chess.empty()) { 324 | hip_chess.push_back(contours[i]); 325 | } else { 326 | real_t mean_mag = 0.0; 327 | for (auto hip : hip_chess) { 328 | mean_mag += hip.get_contour_vector().norm(); 329 | } 330 | mean_mag /= (real_t) hip_chess.size(); 331 | if (is_aproximation(c_q_vec.norm(), mean_mag, mean_mag / 5.0)) { 332 | hip_chess.push_back(contours[i]); 333 | } 334 | } 335 | break; 336 | } 337 | } 338 | } 339 | if (hip_chess.size() == rows) 340 | break; 341 | } 342 | } 343 | 344 | if (hip_chess.size() == rows) { 345 | for (unsigned i = 0; i < rows; i++) { 346 | std::vector row_corners; 347 | for (unsigned j = 0; j < cols; j++) { 348 | row_corners.push_back(hip_chess[i][j]); 349 | } 350 | std::sort(row_corners.begin(), row_corners.end(), cv::internal::idx_cmp(0)); 351 | for (auto rc : row_corners) { 352 | chessboard_corners.push_back(rc); 353 | } 354 | } 355 | } 356 | 357 | return chessboard_corners; 358 | } 359 | 360 | std::vector model_points, corner_points; 361 | 362 | void generate_model_points(unsigned p_rows, unsigned p_cols) { 363 | 364 | // get corner point bounding box 365 | cv::vec4i bb = {std::numeric_limits::max(), std::numeric_limits::max(), 366 | std::numeric_limits::min(), std::numeric_limits::min()}; 367 | 368 | for (auto ptn : corner_points) { 369 | if (ptn[0] < bb[0]) bb[0] = ptn[0]; 370 | if (ptn[0] > bb[2]) bb[2] = ptn[0]; 371 | if (ptn[1] < bb[1]) bb[1] = ptn[1]; 372 | if (ptn[1] > bb[3]) bb[3] = ptn[1]; 373 | } 374 | 375 | int x_start = bb[0]; 376 | int y_start = bb[1]; 377 | 378 | int width = bb[2] - bb[0]; 379 | int height = bb[3] - bb[1]; 380 | 381 | int x_step = width / p_cols; 382 | int y_step = height / p_rows; 383 | 384 | model_points.clear(); 385 | model_points.reserve(p_rows*p_cols); 386 | 387 | // pack model points bordered by the bb 388 | for (unsigned i = 0; i < p_rows; ++i) { 389 | for (unsigned j = 0; j < p_cols; ++j) { 390 | model_points.push_back(cv::vec3r(x_start + x_step*j, y_start + y_step*i, 1.)); 391 | } 392 | } 393 | } 394 | 395 | void calib_fix_fcn(int m, int n, real_t* x, real_t* fvec,int *iflag) { 396 | if (*iflag == 0) 397 | return; 398 | 399 | cv::matrixr p_transform(3, 3, x); 400 | 401 | for (unsigned i = 0; i < model_points.size(); ++i) { 402 | 403 | // transform point 404 | auto m_ptn = p_transform * model_points[i]; 405 | m_ptn /= m_ptn[2]; 406 | 407 | // find nearest point in image corners 408 | real_t b_dist = m_ptn.distance(corner_points[0]); 409 | int b_idx = 0; 410 | 411 | for (unsigned j = 1; j < corner_points.size(); ++j) { 412 | auto this_dist = m_ptn.distance(corner_points[j]); 413 | if (this_dist < b_dist) { 414 | b_dist = this_dist; 415 | b_idx = j; 416 | } 417 | } 418 | fvec[i] = b_dist; 419 | } 420 | } 421 | 422 | std::vector optmize_calib_pattern(std::vector &image_corner_points, 423 | unsigned p_rows, unsigned p_cols, real_t ftol = 1e-14) { 424 | 425 | ASSERT(image_corner_points.size() >= p_rows*p_cols); 426 | 427 | int info; 428 | std::vector model_opt(p_rows*p_cols); 429 | 430 | corner_points.clear(); 431 | for (unsigned i = 0; i < image_corner_points.size(); ++i) { 432 | corner_points.push_back({image_corner_points[i][0], image_corner_points[i][1], 1.}); 433 | } 434 | 435 | generate_model_points(p_rows, p_cols); 436 | 437 | int m = p_rows*p_cols; 438 | int n = 9; 439 | 440 | cv::matrixr p_transform = cv::matrixr::eye(3); 441 | 442 | info = cv::lmdif1(calib_fix_fcn, m, n, p_transform.data(), ftol); 443 | 444 | for (unsigned i = 0; i < p_rows*p_cols; ++i) { 445 | 446 | auto m_ptn = p_transform * model_points[i]; 447 | 448 | auto h_div = m_ptn[2] ? 1. / m_ptn[2] : 1.; 449 | 450 | model_opt[i][0] = m_ptn[0] * h_div; 451 | model_opt[i][1] = m_ptn[1] * h_div; 452 | } 453 | 454 | return model_opt; 455 | } 456 | 457 | std::vector detect_pattern(const cv::matrixr &image, unsigned p_rows, unsigned p_cols, real_t angThresh, real_t magThresh, unsigned nnCount) { 458 | 459 | std::vector pattern; 460 | std::vector > nns; 461 | std::vector ctns; 462 | std::vector features; 463 | 464 | auto h_c = cv::good_features(image, 7); 465 | cv::filter_non_maximum(h_c, 15); 466 | features = cv::extract_features(h_c, p_cols*p_rows*1.5); 467 | 468 | #ifdef LINE_DEBUG 469 | draw_image = image; 470 | #endif 471 | 472 | nns = find_nns(features, nnCount); 473 | ctns = detect_lines(features, nns, angThresh, magThresh, p_rows, p_cols); 474 | pattern = detect_chessboard(ctns, p_rows, p_cols); 475 | 476 | return pattern; 477 | } 478 | 479 | -------------------------------------------------------------------------------- /src/calibpattern.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CALIBPATTERN_HPP_ORZQNP5Z 2 | #define CALIBPATTERN_HPP_ORZQNP5Z 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | std::vector detect_pattern(const cv::matrixr &image, unsigned patternRows, unsigned patternCols, 12 | real_t angThresh = 15., real_t magThresh = 0.15, unsigned nnCount = 10); 13 | 14 | std::vector sub_pixel_detect(const std::vector &corners, const cv::matrixr &src, 15 | const cv::vec2i &win = {10, 10}, real_t eps = 10e-6, unsigned maxIters = 100); 16 | 17 | template 18 | void draw_chessboard(cv::matrix<_Tp> &image, const std::vector &pattern, const _Tp &color) { 19 | 20 | ASSERT(image && !pattern.empty()); 21 | 22 | for (unsigned i = 1; i < pattern.size(); ++i) { 23 | cv::draw_line(image, pattern[i-1], pattern[i], color); 24 | } 25 | } 26 | 27 | 28 | #endif /* end of include guard: CALIBPATTERN_HPP_ORZQNP5Z */ 29 | 30 | -------------------------------------------------------------------------------- /src/homography.cpp: -------------------------------------------------------------------------------- 1 | #include "homography.hpp" 2 | 3 | #include 4 | #include 5 | 6 | 7 | cv::matrixr homography_8_point(const std::vector &image_points, const std::vector &model_points) { 8 | 9 | cv::matrixr H; 10 | 11 | auto n = image_points.size(); 12 | ASSERT(model_points.size() == n); 13 | cv::matrixr L = cv::matrixr::zeros(2*n, 9); 14 | 15 | for(unsigned k = 0; k < n; k++) { 16 | 17 | real_t X=model_points[k][0]; /* X coord of model point k */ 18 | real_t Y=model_points[k][1]; /* Y coord of model point k */ 19 | real_t W=model_points[k][2]; /* W coord of model point k */ 20 | real_t u=image_points[k][0]; /* u coord of image point k */ 21 | real_t v=image_points[k][1]; /* v coord of image point k */ 22 | 23 | int i = 2*k; /* line number in matrix L */ 24 | 25 | L(i,0) = X; 26 | L(i, 1) = Y; 27 | L(i, 2) = W; 28 | L(i, 3) = 0; 29 | L(i, 4) = 0; 30 | L(i, 5) = 0; 31 | L(i, 6) = -u*X; 32 | L(i, 7) = -u*Y; 33 | L(i, 8) = -u*W; 34 | 35 | i++; 36 | 37 | L(i, 0) = 0; 38 | L(i, 1) = 0; 39 | L(i, 2) = 0; 40 | L(i, 3) = X; 41 | L(i, 4) = Y; 42 | L(i, 5) = W; 43 | L(i, 6) = -v*X; 44 | L(i, 7) = -v*Y; 45 | L(i, 8) = -v*W; 46 | } 47 | 48 | cv::null_solve(L, H); 49 | H.reshape(3, 3); 50 | 51 | H *= 1. / H(2, 2); 52 | 53 | return H; 54 | } 55 | 56 | // Similarity estimation for normalization process. 57 | template 58 | cv::matrixr homography_dlt_sim_estimation(const std::vector > &features) { 59 | cv::matrixr transform = cv::matrixr::eye(3); 60 | 61 | cv::vec2r centroid(0, 0); 62 | cv::matrixr S; 63 | 64 | for (auto feat : features) { 65 | centroid += feat; 66 | } 67 | centroid /= features.size(); 68 | 69 | real_t sum_dist = 0; 70 | 71 | for (auto feat : features) { 72 | sum_dist+= centroid.distance(feat); 73 | } 74 | centroid *= -1; 75 | 76 | real_t scale_v = std::sqrt(2.) / (sum_dist / features.size()); 77 | 78 | transform(0, 0) = scale_v; 79 | transform(1, 1) = scale_v; 80 | transform(0, 2) = centroid[0]; 81 | transform(1, 2) = centroid[1]; 82 | 83 | return transform; 84 | } 85 | 86 | template 87 | void homography_dlt_normalize(std::vector > &features, const cv::matrixr &S) { 88 | ASSERT(S && S.rows() == 3 && S.cols() == 3); 89 | cv::matrixr x(3, 1), xp(3, 1); 90 | for (unsigned i = 0; i < features.size(); ++i) { 91 | x(0, 0) = features[i][0]; 92 | x(1, 0) = features[i][1]; 93 | x(2, 0) = (_size == 3) ? features[i][2] : 1.; 94 | cross(S, x, xp); 95 | features[i][0] = xp(0, 0) / xp(2, 0); 96 | features[i][1] = xp(1, 0) / xp(2, 0); 97 | if(_size == 3) 98 | features[i][2] = 1.; 99 | } 100 | } 101 | 102 | cv::matrixr homography_dlt(const std::vector &src_pts, const std::vector &tgt_pts) { 103 | ASSERT(src_pts.size() >= 4 && src_pts.size() == tgt_pts.size()); 104 | 105 | cv::matrixr H; 106 | 107 | // 0. Prepare data; 108 | cv::matrixr srcS, tgtS, invTgtS; 109 | cv::matrixr A = cv::matrixr::zeros(2 * src_pts.size(), 9); 110 | 111 | // 1. Perform normalization; 112 | srcS = homography_dlt_sim_estimation<2>(src_pts); 113 | tgtS = homography_dlt_sim_estimation<3>(tgt_pts); 114 | 115 | auto src_n = src_pts; // source normalized points 116 | auto tgt_n = tgt_pts; // target normalized points 117 | 118 | invTgtS = tgtS.clone(); 119 | invert(invTgtS); 120 | 121 | homography_dlt_normalize<2>(src_n, srcS); 122 | homography_dlt_normalize<3>(tgt_n, tgtS); 123 | 124 | // 2. Pack matrix A; 125 | for (unsigned i = 0; i < src_pts.size(); ++i) { 126 | A(i * 2 + 0, 0) = -1 * src_n[i][0]; 127 | A(i * 2 + 0, 1) = -1 * src_n[i][1]; 128 | A(i * 2 + 0, 2) = -1; 129 | A(i * 2 + 0, 6) = tgt_n[i][0] * src_n[i][0]; 130 | A(i * 2 + 0, 7) = tgt_n[i][0] * src_n[i][1]; 131 | A(i * 2 + 0, 8) = tgt_n[i][0]; 132 | 133 | A(i * 2 + 1, 3) = -1 * src_n[i][0]; 134 | A(i * 2 + 1, 4) = -1 * src_n[i][1]; 135 | A(i * 2 + 1, 5) = -1; 136 | A(i * 2 + 1, 6) = tgt_n[i][1] * src_n[i][0]; 137 | A(i * 2 + 1, 7) = tgt_n[i][1] * src_n[i][1]; 138 | A(i * 2 + 1, 8) = tgt_n[i][1]; 139 | } 140 | 141 | // 3. solve nullspace of A for H; 142 | cv::null_solve(A, H); 143 | 144 | H.reshape(3, 3); 145 | 146 | // 4. denormalize the homography. 147 | H = invTgtS * H * srcS; 148 | 149 | return H; 150 | } 151 | 152 | /* 153 | * Pack homography matrices A and B by the form used for least squares solving. 154 | */ 155 | void pack_ab(const std::vector &src_pts, const std::vector &tgt_pts, cv::matrixr &A, cv::matrixr &B) { 156 | 157 | ASSERT(src_pts.size() && src_pts.size() == tgt_pts.size()); 158 | 159 | // construct matrices 160 | A = cv::matrixr::zeros(src_pts.size() * 2, 8); 161 | B.create(src_pts.size() * 2, 1); 162 | 163 | // populate matrices with data. 164 | for (unsigned i = 0; i < src_pts.size(); i++) { 165 | 166 | auto &src = src_pts[i]; 167 | auto &tgt = tgt_pts[i]; 168 | 169 | B(i * 2, 0) = tgt[0]; 170 | B(i * 2 + 1, 0) = tgt[1]; 171 | 172 | A(i * 2, 0) = src[0]; 173 | A(i * 2, 1) = src[1]; 174 | A(i * 2, 2) = 1; 175 | A(i * 2 + 1, 3) = src[0]; 176 | A(i * 2 + 1, 4) = src[1]; 177 | A(i * 2 + 1, 5) = 1; 178 | 179 | A(i * 2, 6) = -1 * src[0] * tgt[0]; 180 | A(i * 2, 7) = -1 * src[1] * tgt[0]; 181 | A(i * 2 + 1, 6) = -1 * src[0] * tgt[1]; 182 | A(i * 2 + 1, 7) = -1 * src[1] * tgt[1]; 183 | } 184 | } 185 | 186 | /* 187 | * Solve homography using least squares method. 188 | */ 189 | cv::matrixr homography_least_squares(const std::vector &src_pts, const std::vector &tgt_pts) { 190 | 191 | cv::matrixr A, B, H; 192 | pack_ab(src_pts, tgt_pts, A, B); 193 | cv::matrixr _H(8, 1); 194 | 195 | cv::matrixr At = A.transposed(); 196 | lu_solve(At * A, At * B, _H); 197 | 198 | if (!_H) { 199 | throw std::runtime_error("Internal error!~ failure occurred calculating homography.\n"); 200 | } 201 | 202 | H.create(1, 9); 203 | std::copy(_H.begin(), _H.end(), H.begin()); 204 | H.reshape(3, 3); 205 | H(2, 2) = 1; 206 | 207 | return H; 208 | } 209 | 210 | cv::matrixr homography_solve(const std::vector &image_points, const std::vector &model_points, H_calc_alg alg) { 211 | switch (alg) { 212 | case HOMOGRAPHY_8_POINT: 213 | return homography_8_point(image_points, model_points); 214 | case HOMOGRAPHY_LEAST_SQUARES: 215 | return homography_least_squares(image_points, model_points); 216 | case HOMOGRAPHY_DLT: 217 | return homography_dlt(image_points, model_points); 218 | }; 219 | } 220 | 221 | std::vector source_pts; 222 | std::vector target_pts; 223 | 224 | void reprojection_fcn(int m, int n, real_t* x, real_t* fvec,int *iflag) { 225 | 226 | if (*iflag == 0) 227 | return; 228 | 229 | // calculate m_projected 230 | cv::matrixr _H(3, 3, x); // borrow x and form matrix 231 | cv::matrixr ptn(3, 1), p_ptn(3, 1), res_ptn(3, 1); 232 | 233 | for (int i = 0; i < m; ++i) { 234 | ptn(0, 0) = target_pts[i][0]; // model point 235 | ptn(1, 0) = target_pts[i][1]; 236 | ptn(2, 0) = target_pts[i][2]; 237 | 238 | p_ptn(0, 0) = source_pts[i][0]; // photo projection point 239 | p_ptn(1, 0) = source_pts[i][1]; 240 | p_ptn(2, 0) = 1.; 241 | 242 | cv::cross( _H, ptn, res_ptn); 243 | 244 | res_ptn(0, 0) /= res_ptn(2, 0); 245 | res_ptn(1, 0) /= res_ptn(2, 0); 246 | res_ptn(2, 0) = 1.; 247 | 248 | fvec[i] = sqrt(pow(p_ptn(0, 0) - res_ptn(0, 0), 2) + pow(p_ptn(1, 0) - res_ptn(1, 0), 2)); 249 | } 250 | } 251 | 252 | int homography_optimize(const std::vector &image_points, const std::vector &model_points, 253 | cv::matrixr &H, real_t tol) { 254 | 255 | source_pts = image_points; 256 | target_pts = model_points; 257 | 258 | ASSERT(source_pts.size() > 9); 259 | 260 | int m = source_pts.size(); 261 | int n = 9; 262 | 263 | int info = 0; 264 | 265 | auto *_H = new real_t[n]; 266 | 267 | for (int i = 0; i < 9; ++i) { 268 | _H[i] = H.data_begin()[i]; 269 | } 270 | 271 | info = cv::lmdif(reprojection_fcn, m, n, _H, 1000, tol, 1.e-5, 0, 1e-8); 272 | 273 | for (int i = 0; i < 9; ++i) { 274 | H.data_begin()[i] = _H[i]; 275 | } 276 | 277 | H /= H(2, 2); 278 | 279 | delete [] _H; 280 | 281 | return info; 282 | } 283 | 284 | real_t calc_h_reprojection_error(const cv::matrixr &H, const std::vector &source_pts, const std::vector &target_pts) { 285 | 286 | ASSERT(source_pts.size() == target_pts.size() && H && H.rows() == 3 && H.cols() == 3); 287 | 288 | unsigned ptn_count = source_pts.size(); 289 | real_t err = 0.0; 290 | 291 | // calculate m_projected 292 | cv::matrixr ptn(3, 1), p_ptn(3, 1), res_ptn(3, 1); 293 | 294 | for (unsigned i = 0; i < ptn_count; ++i) { 295 | ptn(0, 0) = source_pts[i][0]; 296 | ptn(1, 0) = source_pts[i][1]; 297 | ptn(2, 0) = 1.; 298 | 299 | p_ptn(0, 0) = target_pts[i][0]; 300 | p_ptn(1, 0) = target_pts[i][1]; 301 | p_ptn(2, 0) = target_pts[i][2]; 302 | 303 | cv::cross( H, ptn, res_ptn); 304 | 305 | res_ptn(0, 0) /= res_ptn(2, 0); 306 | res_ptn(1, 0) /= res_ptn(2, 0); 307 | res_ptn(2, 0) = 1; 308 | 309 | err += cv::distance(res_ptn, p_ptn, cv::Norm::L2); 310 | } 311 | 312 | return err / ptn_count; 313 | } 314 | 315 | 316 | 317 | 318 | -------------------------------------------------------------------------------- /src/homography.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HOMOGRAPHY_HPP_ERDRJZXL 2 | #define HOMOGRAPHY_HPP_ERDRJZXL 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | enum H_calc_alg { 12 | HOMOGRAPHY_8_POINT, //!< 8-point algorithm. 13 | HOMOGRAPHY_LEAST_SQUARES, //!< Least squares homography solver. 14 | HOMOGRAPHY_DLT //!< Normalized direct linear transformation homography solver. 15 | }; 16 | 17 | /* 18 | * @brief Solve homography using non-normalized 8-point algorithm. 19 | * 20 | * Solve homography transform matrix which relates image points with world points, using non-normalized 8-point algorithm. 21 | * 22 | * m - image 2D point 23 | * M - world 3D point 24 | * H - homography matrix 25 | * 26 | * m = H*M 27 | * 28 | * @param image_points 2D image points. 29 | * @param model_points 3D world points. 30 | * @param alg Algorithm used to estimate homography. 31 | * 32 | * @return 33 | * cv::matrixr 3x3 homography matrix. 34 | */ 35 | cv::matrixr homography_solve(const std::vector &image_points, const std::vector &model_points, H_calc_alg alg = HOMOGRAPHY_8_POINT); 36 | 37 | //! Evaluate optmization for given data set with given function. 38 | int homography_optimize(const std::vector &image_points, const std::vector &model_points, 39 | cv::matrixr &H, real_t tol = 1e-14); 40 | 41 | /*! 42 | * @brief Calculate reprojection error for homography calculated using given source and target points. 43 | * 44 | * @param H Homography 3x3 matrix 45 | * @param source_pts 2D source image points used to compute given homography. 46 | * @param target_pts 3D target world points used to compute given homography. 47 | * 48 | * @return 49 | * Mean distance error from reprojected points using given homogrphy matrix. 50 | */ 51 | real_t calc_h_reprojection_error(const cv::matrixr &H, const std::vector &source_pts, const std::vector &target_pts); 52 | 53 | #endif /* end of include guard: HOMOGRAPHY_HPP_ERDRJZXL */ 54 | 55 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "calibpattern.hpp" 10 | #include "homography.hpp" 11 | #include "optimize.hpp" 12 | #include "calib.hpp" 13 | 14 | 15 | std::vector split_string(std::string s, const std::string &delimiter = " ") { 16 | std::vector tokens; 17 | 18 | size_t pos = 0; 19 | std::string token; 20 | 21 | while ((pos = s.find(delimiter)) != std::string::npos) { 22 | tokens.push_back(s.substr(0, pos)); 23 | s.erase(0, pos + delimiter.length()); 24 | } 25 | tokens.push_back(s); 26 | 27 | return tokens; 28 | } 29 | 30 | bool write_pattern_results(const std::vector > &patterns, unsigned im_w, unsigned im_h, const char *path) { 31 | 32 | std::ofstream stream(path); 33 | 34 | if (!stream.is_open()) { 35 | return false; 36 | } 37 | 38 | stream << im_w << " " << im_h << std::endl; 39 | 40 | for (unsigned i = 0; i < patterns.size(); ++i) { 41 | stream << patterns[i][0]; 42 | for (unsigned j = 1; j < patterns[i].size(); ++j) { 43 | stream << "," << patterns[i][j]; 44 | } 45 | stream << std::endl; 46 | } 47 | 48 | stream.close(); 49 | 50 | return true; 51 | } 52 | 53 | std::vector > read_pattern_results(const char *path, unsigned &im_w, unsigned &im_h) { 54 | std::vector > patterns; 55 | 56 | std::ifstream stream(path); 57 | 58 | if(!stream.is_open()) { 59 | return patterns; 60 | } 61 | 62 | std::string line; 63 | if(std::getline(stream, line)) { 64 | auto l = split_string(line, " "); 65 | if (l.size() == 2) { 66 | im_w = std::atoi(l[0].c_str()); 67 | im_h = std::atoi(l[1].c_str()); 68 | } 69 | } else { 70 | im_w = im_h = 0; 71 | return patterns; 72 | } 73 | 74 | while(std::getline(stream, line)) { 75 | patterns.push_back(std::vector()); 76 | auto &p = patterns.back(); 77 | for (auto &v : split_string(line, ",")) { 78 | auto vec = split_string(v, " "); 79 | if (vec.size() == 2) { 80 | p.push_back(cv::vec2r(static_cast(std::atof(vec[0].c_str())), static_cast(std::atof(vec[1].c_str())))); 81 | } 82 | } 83 | } 84 | 85 | stream.close(); 86 | 87 | return patterns; 88 | } 89 | 90 | void pattern_detection(const std::vector &pattern_ims, const std::string &out_path, unsigned p_rows, unsigned p_cols, real_t ang_thresh, real_t mag_thresh, unsigned nn_count) { 91 | 92 | std::vector > patterns; 93 | 94 | unsigned im_w = 0, im_h = 0; 95 | 96 | for (auto image: pattern_ims) { 97 | 98 | im_w = image.cols(); 99 | im_h = image.rows(); 100 | 101 | cv::matrixr im_r = image, im_rb; 102 | cv::matrixr gauss_k = cv::gauss({3, 3}, 3); 103 | 104 | im_rb = cv::conv(im_r, gauss_k); 105 | 106 | auto pattern = detect_pattern(im_rb, p_rows, p_cols, ang_thresh, mag_thresh, nn_count); 107 | 108 | if (pattern.size() == p_rows*p_cols) { 109 | pattern = sub_pixel_detect(pattern, im_r, {5, 5}); 110 | 111 | cv::matrix3r im_draw = im_r.clone(); 112 | draw_chessboard(im_draw, pattern, cv::vec3r(255.f, 0.f, 0.f)); 113 | 114 | #ifndef CV_IGNORE_GUI 115 | std::cout << "Accept pattern? (Y/n)" << std::endl; 116 | 117 | cv::imshow("pattern", im_draw); 118 | auto r = cv::wait_key(); 119 | 120 | if (r == 'n') { 121 | std::cout << "Pattern rejected." << std::endl; 122 | continue; 123 | } else { 124 | std::cout << "Pattern accepted." << std::endl; 125 | patterns.push_back(pattern); 126 | } 127 | #else 128 | std::cout << "Pattern found." << std::endl; 129 | patterns.push_back(pattern); 130 | #endif 131 | } else { 132 | std::cout << "Pattern not found" << std::endl; 133 | continue; 134 | } 135 | } 136 | 137 | if (write_pattern_results(patterns, im_w, im_h, out_path.c_str())) { 138 | std::cout << "Writing results to " << out_path << " successfull!" << std::endl; 139 | } else { 140 | std::cout << "Writing results to " << out_path << " failed!" << std::endl; 141 | } 142 | } 143 | 144 | bool read_zhang_data(const std::string &folderpath, std::vector > &image_points, 145 | std::vector &model_points, unsigned &im_w, unsigned &im_h) { 146 | int i,n=0; 147 | FILE* fpm = fopen((folderpath + "/model.txt").c_str(),"rt"); 148 | FILE* fpi1 = fopen((folderpath + "/data1.txt").c_str(),"rt"); 149 | FILE* fpi2 = fopen((folderpath + "/data2.txt").c_str(),"rt"); 150 | FILE* fpi3 = fopen((folderpath + "/data3.txt").c_str(),"rt"); 151 | FILE* fpi4 = fopen((folderpath + "/data4.txt").c_str(),"rt"); 152 | FILE* fpi5 = fopen((folderpath + "/data5.txt").c_str(),"rt"); 153 | 154 | if (fpi1==NULL ||fpi2==NULL ||fpi3==NULL ||fpi4==NULL ||fpi5==NULL || fpm==NULL) { 155 | printf("Arq error\n"); 156 | return 1; 157 | } 158 | 159 | for (n=0; !feof(fpm); n++ ) { 160 | double x, y; 161 | fscanf(fpm,"%lf %lf ",&x,&y); 162 | model_points.push_back(cv::vec3r(x, y, 1.)); 163 | } 164 | 165 | fclose(fpm); 166 | 167 | image_points.resize(5); 168 | for (i=0; i read_image_collection(const std::string &file) { 195 | 196 | std::vector im_files; 197 | std::ifstream stream(file.c_str()); 198 | 199 | if (stream.is_open()) { 200 | std::string line; 201 | while (std::getline(stream, line)) { 202 | im_files.push_back(line); 203 | } 204 | stream.close(); 205 | } 206 | 207 | return im_files; 208 | } 209 | 210 | bool read_custom_data(const std::string &filepath, std::vector > &image_points, 211 | std::vector &model_points, unsigned &im_w, unsigned &im_h, double model_size) { 212 | image_points = read_pattern_results(filepath.c_str(), im_w, im_h); 213 | model_points = calculate_object_points(6, 9, model_size); 214 | 215 | return true; 216 | } 217 | 218 | cv::image_array undistort_image(const cv::image_array &image, const cv::matrixr &A, const cv::vectorr &k) { 219 | 220 | cv::image_array undist = cv::matrix3b::zeros(image.rows(), image.cols()); 221 | 222 | auto fx = A(0, 0); 223 | auto fy = A(1, 1); 224 | auto cx = A(0, 2); 225 | auto cy = A(1, 2); 226 | 227 | #pragma omp parallel for schedule(dynamic) 228 | for (unsigned i = 0; i < image.rows(); ++i) { 229 | for (unsigned j = 0; j < image.cols(); ++j) { 230 | 231 | cv::vec3r proj_ptn = {(static_cast(j) - cx)/fx, (static_cast(i) - cy)/fy, 1.}; 232 | 233 | if (k.length() == 4) { 234 | real_t r2 = proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1] + 1; 235 | real_t d_r = (1 + k[0]*r2 + k[1]*(r2*r2)); // radial distortion 236 | real_t d_t = 2 * k[2]*proj_ptn[0]*proj_ptn[1] + k[3]*(r2 + 2*(proj_ptn[0]*proj_ptn[0])); // tan distortion 237 | proj_ptn[0] = proj_ptn[0]*d_r+ d_t; 238 | proj_ptn[1] = proj_ptn[1]*d_r+ d_t; 239 | } else if (k.length() == 8) { 240 | real_t r2 = proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1] + 1; 241 | real_t r3 = proj_ptn[0]*proj_ptn[0]*proj_ptn[0] + proj_ptn[1]*proj_ptn[1]*proj_ptn[1] + 1; 242 | real_t k_u = 1 + k[0]*r2 + k[1]*(r2*r2) + k[2]*(r3*r3); 243 | real_t k_d = 1 + k[3]*r2 + k[4]*(r2*r2) + k[5]*(r3*r3); 244 | real_t d_r = (k_d) ? k_u / k_d : 0.; // radial distortion 245 | real_t d_t = 2 * k[2]*proj_ptn[0]*proj_ptn[1] + k[3]*(r2 + 2*(proj_ptn[0]*proj_ptn[0])); // tan distortion 246 | proj_ptn[0] = proj_ptn[0]*d_r+ d_t; 247 | proj_ptn[1] = proj_ptn[1]*d_r+ d_t; 248 | } 249 | 250 | /* 251 | auto pp_vec = A * cv::vectorr{proj_ptn[0], proj_ptn[1], proj_ptn[2]}; 252 | cv::vec2r norm_pp_vec = {pp_vec[0] / pp_vec[2], pp_vec[1] / pp_vec[2] }; 253 | */ 254 | 255 | auto x_undist = proj_ptn[0]*fx + cx; 256 | auto y_undist = proj_ptn[1]*fy + cy; 257 | 258 | if (x_undist < 0 || x_undist >= image.cols() || 259 | y_undist < 0 || y_undist >= image.rows()) { 260 | continue; 261 | } 262 | 263 | undist.at(i, j, 0) = image.at(y_undist, x_undist, 0); 264 | undist.at(i, j, 1) = image.at(y_undist, x_undist, 1); 265 | undist.at(i, j, 2) = image.at(y_undist, x_undist, 2); 266 | } 267 | } 268 | 269 | return undist; 270 | } 271 | 272 | void write_results(const cv::matrixr &A, const cv::vectorr &k, const std::vector Ks, const std::string &path = ".") { 273 | 274 | std::ofstream a_stream(path + "/a.out"); 275 | a_stream << std::setprecision(std::numeric_limits::digits10+1); 276 | 277 | auto a = A.data(); 278 | unsigned i; 279 | 280 | a_stream << a[0]; 281 | for (i = 1; i < 9; ++i) { 282 | a_stream << "," << a[i]; 283 | } 284 | 285 | a_stream << std::endl; 286 | 287 | if (k) { 288 | a_stream << k[0]; 289 | for (i = 1; i < k.length(); ++i) { 290 | a_stream << "," << k[i]; 291 | } 292 | } 293 | 294 | a_stream << std::endl; 295 | 296 | for (auto K : Ks) { 297 | auto k = K.data(); 298 | a_stream << k[0]; 299 | for (i = 1; i < 12; ++i) { 300 | a_stream << "," << k[i]; 301 | } 302 | 303 | a_stream << std::endl; 304 | } 305 | } 306 | 307 | int main(int argc, char **argv) { 308 | 309 | std::cout << "********************************************" << std::endl; 310 | 311 | std::cout << "Program ran using flags:" << std::endl; 312 | for (int i = 0; i < argc; ++i) { 313 | std::cout << argv[i] << " "; 314 | } 315 | std::cout << "\n********************************************" << std::endl << std::endl; 316 | 317 | std::string pattern_file = ""; 318 | bool fixed_aspect = false; 319 | bool no_skew = false; 320 | bool skip_optimization = false; 321 | bool skip_extrinsic_optmization = false; 322 | bool skip_distortion_optimization = false; 323 | double ftol = 1e-05; 324 | double model_square_size = 3.; // 3cm is default size of the chessboard calibration pattern printed on A4 325 | int p_rows = 6; 326 | int p_cols = 9; 327 | bool no_distortion = false; 328 | 329 | // ================= PARSE ARGUMENTS, INITIALIZE PROGRAM ================== // 330 | 331 | if (argc < 2) { 332 | std::cout << "Invalid arguments:\n" << std::endl; 333 | std::cout << "Flags:\n--detection: pattern detection program;\n" 334 | << "--zhang: calibrate using zhang experimental data;\n" 335 | << "path to pattern file generated by --detection program." << std::endl; 336 | } 337 | 338 | // Read string to double with error proofing. 339 | auto string_to_double = [](double &val, int argc, char **argv, int i, const std::string &val_name) { 340 | if (i + 1 >= argc) { 341 | std::cout << "Argument error: " << val_name << " flag needs to have float value following." << std::endl; 342 | exit(EXIT_FAILURE); 343 | } 344 | try { 345 | val = std::stod(argv[i + 1]); 346 | } catch (std::invalid_argument &e) { 347 | std::cout << "Argument error: " << val_name << " flag needs to have float value following." << std::endl; 348 | exit(EXIT_FAILURE); 349 | } catch (std::out_of_range &e) { 350 | std::cout << "Argument error: " << val_name << " cannot be converted to double value - out of range.\n" << std::endl; 351 | exit(EXIT_FAILURE); 352 | } 353 | }; 354 | 355 | // Read string to int with error proofing. 356 | auto string_to_int = [](int &val, int argc, char **argv, int i, const std::string &val_name) { 357 | if (i + 1 >= argc) { 358 | std::cout << "Argument error: " << val_name << " flag needs to have float value following." << std::endl; 359 | exit(EXIT_FAILURE); 360 | } 361 | try { 362 | val = std::stoi(argv[i + 1]); 363 | } catch (std::invalid_argument &e) { 364 | std::cout << "Argument error: " << val_name << " flag needs to have float value following." << std::endl; 365 | exit(EXIT_FAILURE); 366 | } catch (std::out_of_range &e) { 367 | std::cout << "Argument error: " << val_name << " cannot be converted to double value - out of range.\n" << std::endl; 368 | exit(EXIT_FAILURE); 369 | } 370 | }; 371 | 372 | if (argv[1] == std::string("--detection")) { 373 | 374 | double ang_thresh = 5.; 375 | double mag_thresh = 0.15; 376 | int nn_count = 8; 377 | std::vector im_files; 378 | 379 | if (argc > 2) { 380 | for (int i = 2; i < argc; ++i) { 381 | if (argv[i] == std::string("--ang-thresh")) { 382 | string_to_double(ang_thresh, argc, argv, i, "ang-thresh"); 383 | if (ang_thresh <= 0) { 384 | std::cout << "Invalid value for ang-thresh - should be non-negative, non-zero." << std::endl; 385 | ang_thresh = 15.; 386 | } 387 | } else if (argv[i] == std::string("--mag-thresh")) { 388 | string_to_double(mag_thresh, argc, argv, i, "mag-thresh"); 389 | if (mag_thresh <= 0) { 390 | std::cout << "Invalid value for mag-thresh - should be non-negative, non-zero." << std::endl; 391 | mag_thresh = 0.15; 392 | } 393 | } else if (argv[i] == std::string("--nn-count")) { 394 | string_to_int(nn_count, argc, argv, i, "nn-count"); 395 | if (nn_count <= 0) { 396 | std::cout << "Invalid value for nn-count - should be non-negative, non-zero." << std::endl; 397 | nn_count = 10; 398 | } 399 | } else if (argv[i] == std::string("--im-files")) { 400 | if (i + 1 >= argc) 401 | std::cout << "Invalid image file collection argument - should have path to the file." << std::endl; 402 | 403 | im_files = read_image_collection(argv[i + 1]); 404 | 405 | if (im_files.empty()) { 406 | std::cout << "Image files not read properly." << std::endl; 407 | } else { 408 | std::cout << "Read " << im_files.size() << " paths to image files from " 409 | << argv[i + 1] << " file." << std::endl; 410 | } 411 | } else if (argv[i] == std::string ("--p-rows")) { 412 | string_to_int(p_rows, argc, argv, i, "p-rows"); 413 | if (p_rows <= 2) { 414 | std::cout << "Pattern rows must be > 2" << std::endl; 415 | p_rows = 6; 416 | } 417 | } else if (argv[i] == std::string ("--p-cols")) { 418 | string_to_int(p_cols, argc, argv, i, "p-cols"); 419 | if (p_cols <= 2) { 420 | std::cout << "Pattern cols must be > 2" << std::endl; 421 | p_cols = 6; 422 | } 423 | } 424 | } 425 | } 426 | 427 | std::vector pattern_ims; 428 | 429 | if (im_files.empty()) { 430 | std::cout << "=========================================" << std::endl; 431 | std::cout << "Enter image files with captured patterns," << std::endl; 432 | std::cout << "* For end write \"end\"\n* For clear last entry type \"cl\"" << std::endl; 433 | std::cout << "=========================================" << std::endl; 434 | 435 | std::string in; 436 | std::string path; 437 | 438 | std::cout << "1. Enter root folder for images:" << std::endl; 439 | std::cin >> path; 440 | 441 | std::cout << "2. Enter image filenames:" << std::endl; 442 | 443 | while(true) { 444 | std::cin >> in; 445 | if (in == "end") { 446 | break; 447 | } else if (in == "cl") { 448 | if (pattern_ims.size()) { 449 | pattern_ims.pop_back(); 450 | } 451 | } 452 | 453 | in = path + "/" + in; 454 | cv::matrixr im; 455 | 456 | try { 457 | im = cv::imread(in, cv::REAL, 1); 458 | } catch (std::runtime_error &e) { 459 | std::cout << "Unexpected error occurred while reading image:\n" << in << std::endl; 460 | std::cout << "Error message: " << e.what() << std::endl; 461 | continue; 462 | } 463 | 464 | if (!im) { 465 | std::cout << "Failure loading image at: \n" << in << std::endl; 466 | } else { 467 | if (im.cols() > 1500) { 468 | real_t scale_factor = 1500. / im.cols(); 469 | cv::resize(im, im, im.rows()*scale_factor, im.cols()*scale_factor); 470 | } 471 | if (!pattern_ims.empty()) { 472 | // check pattern size 473 | if (im.size() != pattern_ims.back().size()) { 474 | std::cout << "Error - pattern not of the same size as previous - pattern rejected!" << std::endl; 475 | continue; 476 | } 477 | } 478 | pattern_ims.push_back(im); 479 | std::cout << "Image at " << in << " accepted." << std::endl; 480 | } 481 | } 482 | } else { 483 | #pragma omp parallel for 484 | for (int i = 0; i < im_files.size(); ++i) { 485 | cv::matrixr im; 486 | std::string &in = im_files[i]; 487 | try { 488 | im = cv::imread(in, cv::REAL, 1); 489 | } catch (std::runtime_error &e) { 490 | std::cout << "Unexpected error occurred while reading image:\n" << in << std::endl; 491 | std::cout << "Error message: " << e.what() << std::endl; 492 | continue; 493 | } 494 | if (!im) { 495 | #pragma omp critical 496 | std::cout << "Failure loading image at: \n" << in << std::endl; 497 | } else { 498 | if (im.cols() > 800) { 499 | real_t scale_factor = 800. / im.cols(); 500 | cv::resize(im, im, im.rows()*scale_factor, im.cols()*scale_factor); 501 | } 502 | if (!pattern_ims.empty()) { 503 | // check pattern size 504 | if (im.size() != pattern_ims.back().size()) { 505 | std::cout << "Error - pattern not of the same size as previous - pattern rejected!" << std::endl; 506 | continue; 507 | } 508 | } 509 | 510 | #pragma omp critical 511 | { 512 | pattern_ims.push_back(im); 513 | std::cout << "Image at " << in << " accepted." << std::endl; 514 | } 515 | } 516 | } 517 | } 518 | 519 | if (pattern_ims.empty()) { 520 | std::cout << "Pattern data empty - detection exiting..." << std::endl; 521 | return EXIT_SUCCESS; 522 | } 523 | 524 | std::string out; 525 | std::cout << "Where to write detected pattern point data?" << std::endl; 526 | std::cin >> out; 527 | 528 | std::cout << "=========================================" << std::endl; 529 | std::cout << "Running pattern detection..." << std::endl; 530 | 531 | pattern_detection(pattern_ims, out, p_rows, p_cols, ang_thresh, mag_thresh, nn_count); 532 | 533 | std::cout << "Pattern detection finished successfully..." << std::endl; 534 | std::cout << "=========================================" << std::endl; 535 | return EXIT_SUCCESS; 536 | 537 | 538 | } else if (argv[1] == std::string("--zhang")) { 539 | pattern_file = "zhang"; 540 | } else { 541 | pattern_file = argv[1]; 542 | } 543 | 544 | if (argc > 2) { 545 | for (int i = 1; i < argc; ++i) { 546 | std::string _arg = argv[i]; 547 | if (_arg == "--no-skew") { 548 | no_skew = true; 549 | } else if (_arg == "--fixed-aspect") { 550 | fixed_aspect = true; 551 | } else if (_arg == "--ftol") { 552 | string_to_double(ftol, argc, argv, i, "ftol"); 553 | } else if (_arg == "--model-square-size") { 554 | string_to_double(model_square_size, argc, argv, i, "model-square-size"); 555 | } else if (_arg == "--skip-opt") { 556 | skip_optimization = true; 557 | } else if (_arg == "--skip-ext-opt") { 558 | skip_extrinsic_optmization = true; 559 | } else if (_arg == "--skip-dist-opt") { 560 | skip_distortion_optimization = true; 561 | } else if (argv[i] == std::string ("--no-dist")) { 562 | no_distortion = true; 563 | } 564 | 565 | } 566 | } 567 | 568 | // =================== INITIALIZE CALIBRATION ============================= // 569 | 570 | unsigned im_w, im_h; 571 | 572 | std::vector> image_points_nrm; 573 | std::vector model_points; 574 | 575 | if (pattern_file == "zhang") { 576 | read_zhang_data("/home/relja/git/camera_calibration/calib_data/zhang_data", image_points_nrm, model_points, im_w, im_h); 577 | } else { 578 | if (!read_custom_data(pattern_file, image_points_nrm, model_points, im_w, im_h, model_square_size) ) { 579 | std::cout << "Error while reading pattern file at: " << pattern_file << std::endl; 580 | return EXIT_FAILURE; 581 | } 582 | } 583 | 584 | auto image_points_orig = image_points_nrm; 585 | 586 | auto N = normalize_image_points(image_points_nrm, im_w, im_h); 587 | auto N_inv = N.clone(); 588 | cv::invert(N_inv); 589 | 590 | auto image_points_count = image_points_nrm.size(); 591 | 592 | std::vector Hs(image_points_count); 593 | 594 | for (unsigned i = 0; i < image_points_count; ++i) { 595 | ASSERT(image_points_nrm[i].size() == model_points.size()); 596 | Hs[i] = homography_solve(image_points_nrm[i], model_points); 597 | homography_optimize(image_points_nrm[i], model_points, Hs[i], ftol); 598 | } 599 | 600 | auto A_p = compute_intrisics(Hs); 601 | 602 | if (!A_p) { 603 | std::cout << "Failure calculating intrinsic parameters." << std::endl; 604 | return EXIT_FAILURE; 605 | } 606 | 607 | std::cout << "Intrinsics matrix A':" << std::endl; 608 | std::cout << A_p << std::endl; 609 | 610 | auto A = denormalize_intrinsics(A_p, N); 611 | 612 | if (fixed_aspect) { 613 | auto asp = (A(0, 0) + A(1, 1)) / 2.; 614 | A(0, 0) = A(1, 1) = asp; 615 | } 616 | 617 | if (no_skew) { 618 | A(0, 1) = 0.0; 619 | } 620 | 621 | std::cout << "Denormalized intrinsics matrix A:" << std::endl; 622 | std::cout << A << std::endl; 623 | 624 | std::vector> image_points_proj(image_points_count); 625 | std::vector> camera_points(image_points_count); 626 | 627 | std::vector Ks; 628 | 629 | for (unsigned i = 0; i < image_points_count; ++i) { 630 | auto K = compute_extrinsics(A, N_inv*Hs[i]); 631 | auto err = calc_reprojection(A, K, model_points, image_points_orig[i], image_points_proj[i]); 632 | std::cout << "Extrinsics " << i << std::endl; 633 | std::cout << "\nReprojection error: " << err << std::endl; 634 | std::cout << "K:\n" << K << std::endl; 635 | 636 | Ks.push_back(K); 637 | } 638 | 639 | cv::vectorr k; 640 | 641 | if (!skip_optimization) 642 | optimize_calib(image_points_orig, model_points, A, Ks, k, fixed_aspect, no_skew, ftol); 643 | 644 | if (!no_distortion) { 645 | k = compute_distortion(image_points_orig, image_points_nrm, image_points_proj, A)(0, 1); 646 | std::cout << "k:\n" << k << std::endl << std::endl; 647 | 648 | if (!skip_distortion_optimization) { 649 | optimize_calib(image_points_orig, model_points, A, Ks, k, fixed_aspect, no_skew, ftol); 650 | } 651 | } else { 652 | std::cout << "Distortion skipped" << std::endl; 653 | } 654 | 655 | std::cout << "\n\n**********************************************************" << std::endl; 656 | std::cout << "Final Optimization Results:" << std::endl; 657 | std::cout << "A:\n" << A << std::endl; 658 | std::cout << "k:\n" << k << std::endl << std::endl; 659 | 660 | real_t mean_err = 0.; 661 | 662 | for (unsigned i = 0; i < image_points_count; ++i) { 663 | std::cout << "------------ K no." << i << " --------------\n" << Ks[i] << std::endl; 664 | auto err = calc_reprojection(A, Ks[i], model_points, image_points_orig[i], image_points_proj[i], k); 665 | mean_err += err; 666 | std::cout << "Reprojection error: " << err << std::endl << std::endl; 667 | 668 | real_t scale = (im_w > 1000) ? 1000. / im_w : 1.; 669 | auto reproj = draw_reprojection(image_points_orig[i], image_points_proj[i], im_w, im_h, scale); 670 | 671 | cv::imwrite(reproj, "reprojection_" + std::to_string(i) + ".png"); 672 | 673 | #ifndef CV_IGNORE_GUI 674 | cv::imshow("reprojection",reproj); 675 | cv::wait_key(); 676 | #endif 677 | } 678 | 679 | /* 680 | auto img = cv::imread("/home/relja/CalibIm3.jpg"); 681 | 682 | if (img) { 683 | 684 | auto undist = undistort_image(img, A, k); 685 | cv::imwrite(undist, "/home/relja/CalibIm3_undistort.jpg"); 686 | } 687 | */ 688 | 689 | write_results(A, k, Ks); 690 | 691 | std::cout << "Mean reprojection error for all patterns: " << (mean_err/image_points_count) << std::endl; 692 | 693 | std::cout << "**********************************************************" << std::endl; 694 | 695 | return EXIT_SUCCESS; 696 | } 697 | 698 | -------------------------------------------------------------------------------- /src/optimize.cpp: -------------------------------------------------------------------------------- 1 | #include "optimize.hpp" 2 | 3 | std::vector > image_all_pts; 4 | std::vector > image_all_norm_pts; 5 | std::vector K_mats; 6 | cv::vec2r *image_pts; 7 | cv::vec3r *model_pts; 8 | real_t *A_mat; 9 | real_t *K_mat; 10 | real_t *k_vec; 11 | 12 | bool g_no_skew; 13 | bool g_fixed_aspect; 14 | unsigned a_param_count; 15 | unsigned k_param_count; 16 | 17 | void ext_reprojection_fcn(int m, int n, real_t* x, real_t* fvec,int *iflag) { 18 | 19 | if (*iflag == 0) 20 | return; 21 | 22 | // calculate m_projected 23 | cv::matrixr A(3, 3, A_mat); 24 | cv::matrixr K(3, 4, x); 25 | 26 | cv::vec2r image_pt_proj; 27 | 28 | for (int i = 0; i < m; ++i) { 29 | 30 | // pack model (world) 3D point. 31 | cv::vectorr model = { model_pts[i][0], model_pts[i][1], 0.0, 1.0}; 32 | auto proj_ptn = (A*K) * model; 33 | proj_ptn /= proj_ptn[2]; 34 | 35 | // calculate projection error 36 | auto x_d = image_pts[i][0] - proj_ptn[0]; 37 | auto y_d = image_pts[i][1] - proj_ptn[1]; 38 | 39 | x_d*=x_d; 40 | y_d*=y_d; 41 | 42 | fvec[i] = sqrt(x_d + y_d); 43 | } 44 | } 45 | 46 | int optimize_extrinsics(const std::vector &image_points, const std::vector &model_points, 47 | const cv::matrixr &A, cv::matrixr &K, real_t tol) 48 | { 49 | ASSERT(image_points.size() == model_points.size() && !image_points.empty()); 50 | 51 | image_pts = const_cast(image_points.data()); 52 | model_pts = const_cast(model_points.data()); 53 | A_mat = const_cast(A.data_begin()); 54 | 55 | int m = image_points.size(); 56 | int n = 12; // K.size 57 | int info; 58 | 59 | cv::vectorr _K(12); 60 | 61 | for (int i = 0; i < 12; ++i) { 62 | _K[i] = K.data_begin()[i]; 63 | } 64 | 65 | if((info = cv::lmdif1(ext_reprojection_fcn, m, n, _K.data(), tol))) { 66 | for (int i = 0; i < 12; ++i) { 67 | K.data_begin()[i] = _K[i]; 68 | } 69 | } else { 70 | std::cout << "Extrinsic optimization failed." << std::endl; 71 | } 72 | 73 | return info; 74 | } 75 | 76 | inline void pack_k_data(const cv::vectorr &k, real_t data[8]) { 77 | switch(k.length()) { 78 | case 2: 79 | data[0] = k[0]; 80 | data[1] = k[1]; 81 | break; 82 | case 4: 83 | data[0] = k[0]; 84 | data[1] = k[1]; 85 | data[2] = k[2]; // p[0] 86 | data[3] = k[3]; // p[1] 87 | break; 88 | case 8: 89 | data[0] = k[0]; 90 | data[1] = k[1]; 91 | data[2] = k[2]; // k[2] 92 | data[3] = k[3]; // k[3] 93 | data[4] = k[4]; // k[4] 94 | data[5] = k[5]; // k[5] 95 | data[6] = k[6]; // p[0] 96 | data[7] = k[7]; // p[1] 97 | break; 98 | default: 99 | break; 100 | } 101 | } 102 | 103 | cv::vectorr unpack_k_data(real_t *data) { 104 | 105 | if (k_param_count) { 106 | cv::vectorr k(k_param_count); 107 | switch(k.length()) { 108 | case 2: 109 | k[0] = data[0]; 110 | k[1] = data[1]; 111 | break; 112 | case 4: 113 | k[0] = data[0]; 114 | k[1] = data[1]; 115 | k[2] = data[2]; 116 | k[3] = data[3]; 117 | break; 118 | case 8: 119 | k[0] = data[0]; 120 | k[1] = data[1]; 121 | k[2] = data[2]; 122 | k[3] = data[3]; 123 | k[4] = data[4]; 124 | k[5] = data[5]; 125 | k[6] = data[6]; 126 | k[7] = data[7]; 127 | break; 128 | default: 129 | break; 130 | } 131 | 132 | return k; 133 | } else { 134 | return cv::vectorr(); 135 | } 136 | } 137 | 138 | void distorion_reprojection_fcn(int m, int n, real_t* x, real_t* fvec,int *iflag) { 139 | 140 | if (*iflag == 0) 141 | return; 142 | 143 | // calculate m_projected 144 | cv::matrixr A(3, 3, A_mat); 145 | cv::vectorr k(x, x, 8, 1); 146 | 147 | unsigned f_i = 0; 148 | for (unsigned i = 0; i < image_all_pts.size(); ++i) { 149 | for (unsigned j = 0; j < image_all_pts[i].size(); ++j, ++f_i) { 150 | 151 | // pack model (world) 3D point. 152 | cv::vectorr model = { model_pts[j][0], model_pts[j][1], 0.0, 1.0}; 153 | auto proj_ptn = reproject_point(model, A, K_mats[i], k); 154 | 155 | // calculate projection error 156 | auto x_d = image_all_pts[i][j][0] - proj_ptn[0]; 157 | auto y_d = image_all_pts[i][j][1] - proj_ptn[1]; 158 | 159 | x_d*=x_d; 160 | y_d*=y_d; 161 | 162 | fvec[f_i] = sqrt(x_d + y_d); 163 | } 164 | } 165 | } 166 | 167 | int optimize_distortion(const std::vector> &image_points, const std::vector &model_points, 168 | const cv::matrixr &A, const std::vector &K, cv::vectorr &k, real_t tol) 169 | { 170 | 171 | ASSERT(k.length() == 2 || k.length() == 4 || k.length() == 8); 172 | 173 | image_all_pts = image_points; 174 | model_pts = const_cast(model_points.data()); 175 | A_mat = const_cast(A.data_begin()); 176 | K_mats = K; 177 | 178 | int m = image_points.size()*image_points[0].size(); 179 | int n = 2; 180 | 181 | int info = 0; 182 | 183 | real_t data[8]; 184 | pack_k_data(k, data); 185 | 186 | if((info = cv::lmdif1(distorion_reprojection_fcn, m, n, data, tol))) { 187 | k = unpack_k_data(data); 188 | } else { 189 | std::cout << "Distortion optimization did not converge" << std::endl; 190 | } 191 | 192 | return info; 193 | } 194 | 195 | cv::matrixr construct_a(real_t *x) { 196 | 197 | cv::matrixr A(3, 3); 198 | 199 | if (g_fixed_aspect) { 200 | 201 | if (g_no_skew) { 202 | A(0, 0) = x[0]; 203 | A(1, 1) = x[0]; 204 | A(0, 2) = x[1]; 205 | A(1, 2) = x[2]; 206 | A(0, 1) = 0; 207 | } else { 208 | A(0, 0) = x[0]; 209 | A(1, 1) = x[0]; 210 | A(0, 1) = x[1]; 211 | A(0, 2) = x[2]; 212 | A(1, 2) = x[3]; 213 | } 214 | } else { 215 | if (g_no_skew) { 216 | A(0, 0) = x[0]; 217 | A(0, 2) = x[1]; 218 | A(1, 1) = x[2]; 219 | A(1, 2) = x[3]; 220 | A(0, 1) = 0; 221 | } else { 222 | A(0, 0) = x[0]; 223 | A(0, 1) = x[1]; 224 | A(0, 2) = x[2]; 225 | A(1, 1) = x[3]; 226 | A(1, 2) = x[4]; 227 | } 228 | } 229 | 230 | A(1, 0) = A(2, 0) = A(2, 1) = 0; 231 | A(2, 2) = 1; 232 | 233 | return A; 234 | } 235 | 236 | void all_reprojection_fcn(int m, int n, real_t* x, real_t* fvec,int *iflag) { 237 | 238 | if (*iflag == 0) { 239 | return; 240 | } 241 | 242 | // calculate m_projected 243 | auto A = construct_a(x); 244 | 245 | auto k_x = x + n - k_param_count; 246 | cv::vectorr k; 247 | 248 | if (k_param_count) 249 | k = cv::vectorr(k_x, k_x, k_param_count, 1); 250 | 251 | unsigned f_i = 0; 252 | 253 | for (unsigned i = 0; i < image_all_pts.size(); ++i) { 254 | cv::matrixr K(3, 4, (x + a_param_count + (i * 12))); 255 | for (unsigned j = 0; j < image_all_pts[i].size(); ++j, ++f_i) { 256 | 257 | // pack model (world) 3D point. 258 | cv::vectorr model = { model_pts[j][0], model_pts[j][1], 0.0, 1.0}; 259 | auto proj_ptn = reproject_point(model, A, K, k); 260 | 261 | // calculate projection error 262 | auto x_d = image_all_pts[i][j][0] - proj_ptn[0]; 263 | auto y_d = image_all_pts[i][j][1] - proj_ptn[1]; 264 | 265 | x_d*=x_d; 266 | y_d*=y_d; 267 | 268 | fvec[f_i] = sqrt(x_d + y_d); 269 | } 270 | } 271 | } 272 | 273 | int optimize_calib(const std::vector> &image_points, const std::vector &model_points, 274 | cv::matrixr &A, std::vector &K, cv::vectorr &k, bool fixed_aspect, bool no_skew, real_t tol) 275 | { 276 | image_all_pts = image_points; 277 | model_pts = const_cast(model_points.data()); 278 | A_mat = const_cast(A.data_begin()); 279 | 280 | g_fixed_aspect = fixed_aspect; 281 | g_no_skew = no_skew; 282 | 283 | a_param_count = fixed_aspect ? 3 : 4; 284 | a_param_count += no_skew ? 0 : 1; 285 | k_param_count = k.length(); 286 | 287 | int m = image_points.size()*image_points[0].size(); 288 | int n = a_param_count + (K.size()*12) + k.length(); // A{a, b, c, u0, v0} + K + k; 289 | int info = 0; 290 | 291 | auto *data = new real_t[n]; 292 | 293 | if (fixed_aspect) { 294 | if (no_skew) { 295 | data[0] = (A(0, 0) + A(1, 1)) / 2; 296 | data[1] = A(0, 2); 297 | data[2] = A(1, 2); 298 | } else { 299 | data[0] = (A(0, 0) + A(1, 1)) / 2; 300 | data[1] = A(0, 1); 301 | data[2] = A(0, 2); 302 | data[3] = A(1, 2); 303 | } 304 | } else { 305 | if (no_skew) { 306 | data[0] = A(0, 0); 307 | data[1] = A(0, 2); 308 | data[2] = A(1, 1); 309 | data[3] = A(1, 2); 310 | } else { 311 | data[0] = A(0, 0); 312 | data[1] = A(0, 1); 313 | data[2] = A(0, 2); 314 | data[3] = A(1, 1); 315 | data[4] = A(1, 2); 316 | } 317 | } 318 | 319 | for (unsigned b = 0; b < K.size(); ++b) { 320 | for (unsigned i = 0; i < 12; ++i) { 321 | data[a_param_count + (b * 12) + i] = K[b].data_begin()[i]; 322 | } 323 | } 324 | 325 | auto k_str = data + (n - k.length()); 326 | pack_k_data(k, k_str); 327 | 328 | if((info = cv::lmdif1(all_reprojection_fcn, m, n, data, tol))) { 329 | A = construct_a(data); 330 | for (unsigned b = 0; b < K.size(); ++b) { 331 | cv::matrixr K_(3, 4, (data + a_param_count + (b * 12))); 332 | K[b] = K_.clone(); 333 | } 334 | k = unpack_k_data(k_str); 335 | } else { 336 | std::cout << "Optimization failed." << std::endl; 337 | } 338 | 339 | delete [] data; 340 | 341 | return info; 342 | } 343 | 344 | -------------------------------------------------------------------------------- /src/optimize.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OPTIMIZE_HPP_OBWEIHS0 2 | #define OPTIMIZE_HPP_OBWEIHS0 3 | 4 | #include 5 | 6 | #include "calib.hpp" 7 | 8 | /*! 9 | * @brief Optimize extrinsic matrix K (3x4) by minimizing reprojection error while ignoring distortion. 10 | * 11 | * @param image_points Image 2D points from calibration pattern used to extract extrinsic matrix. 12 | * @param model_points World 3D points from calibration pattern. 13 | * @param A Intrinsic matrix 3x3. 14 | * @param K Initial extrinsic matrix. 15 | * @param tol Error tolerance used in Levenberg-Marquard optimization algorithm. 16 | */ 17 | int optimize_extrinsics(const std::vector &image_points, const std::vector &model_points, 18 | const cv::matrixr &A, cv::matrixr &K, real_t tol = 1e-14); 19 | 20 | /*! 21 | * @brief Optimize distortion parameters by minimizing reprojection. 22 | * 23 | * @param image_points Image 2D points from calibration patterns used for calibration. 24 | * @param model_points World 3D points from calibration pattern. 25 | * @param A Intrinsic matrix 3x3. 26 | * @param K Initial extrinsic matrices. 27 | * @param k Initial value for radial and tangential distortion parameters. As input can be 2, 4, and 8 dimension vector: 28 | * 2 - [k1, k2] 29 | * 4 - [k1, k2, p1, p2] 30 | * 8 - [k1, k2, k3, k4, k5, k6, p1, p2] 31 | * Returned value is always 8 point vector with all parameters. For every non-given parameter zero is set as initial value. 32 | * @param tol Error tolerance used in Levenberg-Marquard optimization algorithm. 33 | */ 34 | int optimize_distortion(const std::vector> &image_points, const std::vector &model_points, 35 | const cv::matrixr &A, const std::vector &K, cv::vectorr&k, real_t tol = 1e-14); 36 | /*! 37 | * @brief Optimize all calibration parameters. 38 | * 39 | * @param image_points Image 2D points from calibration patterns used for calibration. 40 | * @param model_points World 3D points from calibration pattern. 41 | * @param A Intrinsic matrix 3x3. 42 | * @param K Extrinsic matrices. 43 | * @param k Initial value for radial and tangential distortion parameters. As input can be 2, 4, and 8 dimension vector: 44 | * 2 - [k1, k2] 45 | * 4 - [k1, k2, p1, p2] 46 | * 8 - [k1, k2, k3, k4, k5, k6, p1, p2] 47 | * @param fixed_aspect Force fixed aspect ration (alpha = beta) in optimization. 48 | * @param no_skew Force zero skew (c) in optimization. 49 | * @param tol Error tolerance used in Levenberg-Marquard optimization algorithm. 50 | */ 51 | int optimize_calib(const std::vector> &image_points, const std::vector &model_points, 52 | cv::matrixr &A, std::vector &K, cv::vectorr &k, bool fixed_aspect = false, bool no_skew = false, real_t tol = 1e-14); 53 | 54 | #endif /* end of include guard: OPTIMIZE_HPP_OBWEIHS0 */ 55 | -------------------------------------------------------------------------------- /tests/600D/600D_1.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration tests/600D/pattern.txt --model-square-size 1.9 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 4.19528 -0.00861 -0.00433 8 | 0.00000 6.29626 0.00509 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 10874.15677 -22.30784 2580.77597 13 | 0.00000 10879.93630 1736.80160 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 1.391995 19 | K: 20 | 0.98013 0.12604 -0.15315 -19.91499 21 | 0.01990 0.70573 0.70820 -9.00937 22 | 0.19735 -0.69718 0.68920 128.39506 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 1.031376 27 | K: 28 | 0.82308 0.22137 -0.52300 -13.02956 29 | 0.08780 0.86023 0.50229 -13.31227 30 | 0.56110 -0.45934 0.68860 112.27037 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 1.180610 35 | K: 36 | 0.86745 -0.26570 0.42063 -12.77095 37 | -0.02770 0.81834 0.57406 -11.02196 38 | -0.49675 -0.50962 0.70251 124.44372 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 1.424698 43 | K: 44 | 0.73120 -0.06661 0.67891 -10.43838 45 | -0.02174 0.99244 0.12078 -11.96739 46 | -0.68182 -0.10307 0.72422 124.81790 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 0.879795 51 | K: 52 | 0.62360 0.04412 -0.78050 -11.26692 53 | -0.03302 0.99900 0.03009 -11.67377 54 | 0.78105 0.00701 0.62443 93.44771 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 1.282389 59 | K: 60 | 0.99908 -0.04277 0.00103 -16.15227 61 | 0.04269 0.99826 0.04060 -12.24521 62 | -0.00277 -0.04052 0.99918 102.45942 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 2.123212 67 | K: 68 | 0.86014 0.42043 -0.28880 -15.62274 69 | -0.03393 0.61211 0.79004 -9.23112 70 | 0.50893 -0.66975 0.54076 111.93529 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 1.179010 75 | K: 76 | 0.74529 -0.66559 0.03903 -5.65456 77 | 0.31836 0.40670 0.85630 -12.49534 78 | -0.58582 -0.62577 0.51501 122.95053 79 | 80 | k: 81 | -0.000014 -0.000005 82 | 83 | 84 | 85 | ********************************************************** 86 | Final Optimization Results: 87 | A: 88 | 10872.47541 -23.41507 2580.65279 89 | 0.00000 10879.74805 1736.77713 90 | 0.00000 0.00000 1.00000 91 | 92 | k: 93 | -0.000010 -0.000011 94 | 95 | ------------ K no.0 -------------- 96 | 0.97970 0.12650 -0.15315 -19.91530 97 | 0.02029 0.70623 0.70820 -9.00694 98 | 0.19651 -0.69462 0.68920 128.38325 99 | 100 | Reprojection error: 0.971820 101 | 102 | ------------ K no.1 -------------- 103 | 0.82297 0.22160 -0.52300 -13.02883 104 | 0.08785 0.86048 0.50229 -13.31042 105 | 0.56015 -0.45849 0.68860 112.27588 106 | 107 | Reprojection error: 0.932588 108 | 109 | ------------ K no.2 -------------- 110 | 0.86734 -0.26532 0.42063 -12.76928 111 | -0.02767 0.81810 0.57406 -11.02456 112 | -0.49593 -0.51022 0.70251 124.40743 113 | 114 | Reprojection error: 1.183048 115 | 116 | ------------ K no.3 -------------- 117 | 0.73119 -0.06697 0.67891 -10.43802 118 | -0.02246 0.99269 0.12078 -11.96890 119 | -0.67955 -0.10445 0.72422 124.76135 120 | 121 | Reprojection error: 0.989169 122 | 123 | ------------ K no.4 -------------- 124 | 0.62351 0.04421 -0.78050 -11.26709 125 | -0.03292 0.99906 0.03009 -11.67335 126 | 0.78037 0.00689 0.62443 93.45232 127 | 128 | Reprojection error: 0.876254 129 | 130 | ------------ K no.5 -------------- 131 | 0.99919 -0.04234 0.00103 -16.15050 132 | 0.04290 0.99813 0.04060 -12.24303 133 | -0.00342 -0.04039 0.99918 102.45415 134 | 135 | Reprojection error: 1.032141 136 | 137 | ------------ K no.6 -------------- 138 | 0.86037 0.41948 -0.28880 -15.62826 139 | -0.03459 0.61204 0.79004 -9.23169 140 | 0.50889 -0.66908 0.54076 111.94621 141 | 142 | Reprojection error: 1.035962 143 | 144 | ------------ K no.7 -------------- 145 | 0.74524 -0.66544 0.03903 -5.65296 146 | 0.31841 0.40675 0.85630 -12.49512 147 | -0.58467 -0.62500 0.51501 122.91622 148 | 149 | Reprojection error: 1.188411 150 | 151 | Mean reprojection error for all patterns: 1.026174 152 | ********************************************************** 153 | -------------------------------------------------------------------------------- /tests/600D/im_files.txt: -------------------------------------------------------------------------------- 1 | /home/relja/Desktop/600d/IMG_4521.JPG 2 | /home/relja/Desktop/600d/IMG_4522.JPG 3 | /home/relja/Desktop/600d/IMG_4523.JPG 4 | /home/relja/Desktop/600d/IMG_4524.JPG 5 | /home/relja/Desktop/600d/IMG_4525.JPG 6 | /home/relja/Desktop/600d/IMG_4526.JPG 7 | /home/relja/Desktop/600d/IMG_4527.JPG 8 | /home/relja/Desktop/600d/IMG_4528.JPG 9 | /home/relja/Desktop/600d/IMG_4529.JPG 10 | -------------------------------------------------------------------------------- /tests/600D/real_data.txt: -------------------------------------------------------------------------------- 1 | sensor size - 22.3mm x 14.9mm 2 | image size - 5184x3456 3 | focal length - 50.0mm 4 | 5 | focal width in pixels = 5184*50/28.7 = 9031.358885 6 | focal height in pixels = 3456*50/19.1 = 9047.12041885 7 | -------------------------------------------------------------------------------- /tests/600D/reprojection_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_0.png -------------------------------------------------------------------------------- /tests/600D/reprojection_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_1.png -------------------------------------------------------------------------------- /tests/600D/reprojection_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_2.png -------------------------------------------------------------------------------- /tests/600D/reprojection_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_3.png -------------------------------------------------------------------------------- /tests/600D/reprojection_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_4.png -------------------------------------------------------------------------------- /tests/600D/reprojection_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_5.png -------------------------------------------------------------------------------- /tests/600D/reprojection_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_6.png -------------------------------------------------------------------------------- /tests/600D/reprojection_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_7.png -------------------------------------------------------------------------------- /tests/600D/reprojection_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/600D/reprojection_8.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/GT-I9300_3.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration tests/GT-I9300/pattern.txt --model-square-size 1.9 --fixed-aspect 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.68092 -0.00099 -0.02273 8 | 0.00000 2.24096 0.02300 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 2743.09687 -1.61926 1594.91177 13 | 0.00000 2743.09687 1252.15169 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 1.184626 19 | K: 20 | 0.97832 0.16103 -0.13020 -16.28114 21 | -0.08904 0.89476 0.43759 -10.53971 22 | 0.18696 -0.41651 0.88970 42.47707 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.750771 27 | K: 28 | 0.89270 -0.41797 0.16850 -12.87787 29 | 0.30135 0.83165 0.46642 -18.53098 30 | -0.33508 -0.36559 0.86837 54.81682 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 1.124680 35 | K: 36 | 0.96343 0.02343 0.26692 -18.42136 37 | 0.01659 0.98905 -0.14667 -8.82173 38 | -0.26744 0.14573 0.95249 50.95347 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 1.349936 43 | K: 44 | 0.95892 0.03689 -0.28126 -13.72338 45 | -0.11646 0.95529 -0.27176 -8.08188 46 | 0.25866 0.29335 0.92035 34.05519 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 1.058561 51 | K: 52 | 0.85829 0.11277 -0.50062 -9.95564 53 | -0.01604 0.98098 0.19346 -12.30117 54 | 0.51291 -0.15802 0.84377 38.62966 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 0.687692 59 | K: 60 | 0.84300 -0.05721 0.53486 -16.73224 61 | -0.04905 0.98201 0.18235 -10.10928 62 | -0.53567 -0.17996 0.82503 56.03530 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 1.496362 67 | K: 68 | 0.99837 -0.05614 0.00992 -16.01983 69 | 0.03394 0.72510 0.68780 -10.84523 70 | -0.04581 -0.68635 0.72583 54.82543 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 1.328426 75 | K: 76 | 0.99740 -0.06572 -0.02959 -16.58455 77 | 0.04810 0.91268 -0.40582 -7.52737 78 | 0.05367 0.40334 0.91347 34.73659 79 | 80 | Extrinsics 8 81 | 82 | Reprojection error: 0.849744 83 | K: 84 | 0.93378 0.33004 -0.13833 -14.39569 85 | -0.14848 0.70903 0.68937 -6.70629 86 | 0.32560 -0.62318 0.71108 46.74424 87 | 88 | Extrinsics 9 89 | 90 | Reprojection error: 2.166239 91 | K: 92 | 0.86529 -0.49906 0.04694 -10.86424 93 | 0.32775 0.63414 0.70032 -16.75844 94 | -0.37927 -0.59060 0.71229 64.02586 95 | 96 | k: 97 | 0.000000 0.000000 98 | 99 | 100 | 101 | ********************************************************** 102 | Final Optimization Results: 103 | A: 104 | 2742.77731 -2.14116 1594.72745 105 | 0.00000 2742.77731 1252.11996 106 | 0.00000 0.00000 1.00000 107 | 108 | k: 109 | 0.000000 0.000000 110 | 111 | ------------ K no.0 -------------- 112 | 0.97869 0.16030 -0.13020 -16.28036 113 | -0.08953 0.89451 0.43759 -10.53869 114 | 0.18674 -0.41595 0.88970 42.45821 115 | 116 | Reprojection error: 0.858502 117 | 118 | ------------ K no.1 -------------- 119 | 0.89293 -0.41748 0.16850 -12.88477 120 | 0.30123 0.83124 0.46642 -18.52725 121 | -0.33497 -0.36585 0.86837 54.81555 122 | 123 | Reprojection error: 0.738100 124 | 125 | ------------ K no.2 -------------- 126 | 0.96426 0.02343 0.26692 -18.42136 127 | 0.01730 0.98905 -0.14667 -8.82451 128 | -0.26682 0.14573 0.95249 50.93858 129 | 130 | Reprojection error: 0.741469 131 | 132 | ------------ K no.3 -------------- 133 | 0.95896 0.03806 -0.28126 -13.72692 134 | -0.11598 0.95535 -0.27176 -8.08740 135 | 0.25867 0.29376 0.92035 34.05446 136 | 137 | Reprojection error: 1.007376 138 | 139 | ------------ K no.4 -------------- 140 | 0.85769 0.11341 -0.50062 -9.95470 141 | -0.01568 0.98181 0.19346 -12.30117 142 | 0.51058 -0.15668 0.84377 38.62966 143 | 144 | Reprojection error: 0.867382 145 | 146 | ------------ K no.5 -------------- 147 | 0.84329 -0.05721 0.53486 -16.73224 148 | -0.04944 0.98201 0.18235 -10.10651 149 | -0.53569 -0.18047 0.82503 56.03782 150 | 151 | Reprojection error: 0.649568 152 | 153 | ------------ K no.6 -------------- 154 | 0.99754 -0.05614 0.00992 -16.01983 155 | 0.03308 0.72554 0.68780 -10.84877 156 | -0.04623 -0.68635 0.72583 54.82543 157 | 158 | Reprojection error: 0.951028 159 | 160 | ------------ K no.7 -------------- 161 | 0.99749 -0.06572 -0.02959 -16.58561 162 | 0.04763 0.91194 -0.40582 -7.52980 163 | 0.05335 0.40248 0.91347 34.74225 164 | 165 | Reprojection error: 0.953672 166 | 167 | ------------ K no.8 -------------- 168 | 0.93402 0.32983 -0.13833 -14.39874 169 | -0.14885 0.70916 0.68937 -6.71285 170 | 0.32502 -0.61934 0.71108 46.72353 171 | 172 | Reprojection error: 1.159079 173 | 174 | ------------ K no.9 -------------- 175 | 0.86396 -0.49930 0.04694 -10.87416 176 | 0.32666 0.63557 0.70032 -16.76354 177 | -0.37867 -0.59395 0.71229 64.04874 178 | 179 | Reprojection error: 0.790006 180 | 181 | Mean reprojection error for all patterns: 0.871618 182 | ********************************************************** 183 | -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_0.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_1.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_2.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_3.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_4.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_5.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_6.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_7.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_8.png -------------------------------------------------------------------------------- /tests/GT-I9300/apect_ratio_fixed/reprojection_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/apect_ratio_fixed/reprojection_9.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/GT-I9300_2.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration tests/GT-I9300/pattern.txt --model-square-size 1.9 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.68092 -0.00099 -0.02273 8 | 0.00000 2.24096 0.02300 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 2743.26368 -1.61926 1594.91177 13 | 0.00000 2742.93006 1252.15169 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 1.170890 19 | K: 20 | 0.97832 0.16102 -0.13021 -16.28023 21 | -0.08904 0.89477 0.43757 -10.54040 22 | 0.18696 -0.41649 0.88971 42.47730 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.726126 27 | K: 28 | 0.89270 -0.41796 0.16851 -12.87717 29 | 0.30135 0.83167 0.46639 -18.53221 30 | -0.33508 -0.36557 0.86838 54.81714 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 1.075572 35 | K: 36 | 0.96343 0.02342 0.26694 -18.42021 37 | 0.01659 0.98905 -0.14666 -8.82225 38 | -0.26745 0.14573 0.95249 50.95339 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 1.350335 43 | K: 44 | 0.95892 0.03689 -0.28128 -13.72255 45 | -0.11646 0.95530 -0.27174 -8.08238 46 | 0.25868 0.29333 0.92035 34.05519 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 1.072992 51 | K: 52 | 0.85828 0.11276 -0.50064 -9.95497 53 | -0.01604 0.98098 0.19345 -12.30184 54 | 0.51293 -0.15801 0.84376 38.62941 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 0.657071 59 | K: 60 | 0.84299 -0.05721 0.53488 -16.73110 61 | -0.04905 0.98201 0.18234 -10.10981 62 | -0.53569 -0.17995 0.82502 56.03487 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 1.530431 67 | K: 68 | 0.99837 -0.05614 0.00992 -16.01908 69 | 0.03394 0.72512 0.68778 -10.84605 70 | -0.04581 -0.68633 0.72585 54.82622 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 1.308544 75 | K: 76 | 0.99740 -0.06572 -0.02959 -16.58362 77 | 0.04810 0.91269 -0.40580 -7.52786 78 | 0.05367 0.40332 0.91348 34.73677 79 | 80 | Extrinsics 8 81 | 82 | Reprojection error: 0.867124 83 | K: 84 | 0.93378 0.33004 -0.13834 -14.39501 85 | -0.14848 0.70905 0.68935 -6.70679 86 | 0.32560 -0.62316 0.71110 46.74489 87 | 88 | Extrinsics 9 89 | 90 | Reprojection error: 2.186096 91 | K: 92 | 0.86529 -0.49906 0.04694 -10.86374 93 | 0.32776 0.63416 0.70030 -16.75971 94 | -0.37926 -0.59058 0.71231 64.02681 95 | 96 | k: 97 | 0.000000 0.000000 98 | 99 | 100 | 101 | ********************************************************** 102 | Final Optimization Results: 103 | A: 104 | 2742.82614 -2.57976 1594.76414 105 | 0.00000 2742.60441 1252.15770 106 | 0.00000 0.00000 1.00000 107 | 108 | k: 109 | 0.000000 0.000000 110 | 111 | ------------ K no.0 -------------- 112 | 0.97858 0.16042 -0.13021 -16.27581 113 | -0.08954 0.89446 0.43757 -10.53866 114 | 0.18677 -0.41590 0.88971 42.47590 115 | 116 | Reprojection error: 0.824519 117 | 118 | ------------ K no.1 -------------- 119 | 0.89278 -0.41754 0.16851 -12.88199 120 | 0.30115 0.83182 0.46639 -18.53112 121 | -0.33455 -0.36531 0.86838 54.80073 122 | 123 | Reprojection error: 0.757711 124 | 125 | ------------ K no.2 -------------- 126 | 0.96343 0.02439 0.26694 -18.41885 127 | 0.01659 0.98833 -0.14666 -8.81565 128 | -0.26745 0.14558 0.95249 50.93591 129 | 130 | Reprojection error: 0.728643 131 | 132 | ------------ K no.3 -------------- 133 | 0.95883 0.03816 -0.28128 -13.72678 134 | -0.11526 0.95535 -0.27174 -8.08089 135 | 0.25953 0.29324 0.92035 34.05189 136 | 137 | Reprojection error: 0.961092 138 | 139 | ------------ K no.4 -------------- 140 | 0.85844 0.11353 -0.50064 -9.95908 141 | -0.01521 0.98125 0.19345 -12.30029 142 | 0.51272 -0.15612 0.84376 38.61939 143 | 144 | Reprojection error: 0.738087 145 | 146 | ------------ K no.5 -------------- 147 | 0.84299 -0.05701 0.53488 -16.72887 148 | -0.04905 0.98168 0.18234 -10.10954 149 | -0.53549 -0.18038 0.82502 56.01872 150 | 151 | Reprojection error: 0.605238 152 | 153 | ------------ K no.6 -------------- 154 | 0.99837 -0.05651 0.00992 -16.03252 155 | 0.03259 0.72553 0.68778 -10.85090 156 | -0.04581 -0.68777 0.72585 54.85312 157 | 158 | Reprojection error: 1.174448 159 | 160 | ------------ K no.7 -------------- 161 | 0.99740 -0.06566 -0.02959 -16.58547 162 | 0.04723 0.91281 -0.40580 -7.52902 163 | 0.05344 0.40271 0.91348 34.73385 164 | 165 | Reprojection error: 0.854574 166 | 167 | ------------ K no.8 -------------- 168 | 0.93343 0.32927 -0.13834 -14.39795 169 | -0.14886 0.70992 0.68935 -6.71155 170 | 0.32521 -0.61999 0.71110 46.73607 171 | 172 | Reprojection error: 1.306928 173 | 174 | ------------ K no.9 -------------- 175 | 0.86436 -0.49997 0.04694 -10.87357 176 | 0.32711 0.63528 0.70030 -16.76573 177 | -0.38014 -0.59197 0.71231 64.07672 178 | 179 | Reprojection error: 0.681850 180 | 181 | Mean reprojection error for all patterns: 0.863309 182 | ********************************************************** 183 | -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_0.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_1.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_2.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_3.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_4.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_5.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_6.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_7.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_8.png -------------------------------------------------------------------------------- /tests/GT-I9300/aspect_ratio_free/reprojection_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GT-I9300/aspect_ratio_free/reprojection_9.png -------------------------------------------------------------------------------- /tests/GT-I9300/im_files.txt: -------------------------------------------------------------------------------- 1 | /home/relja/Desktop/GT-I9300/IMG_20151123_190255.jpg 2 | /home/relja/Desktop/GT-I9300/IMG_20151123_190300.jpg 3 | /home/relja/Desktop/GT-I9300/IMG_20151123_190305.jpg 4 | /home/relja/Desktop/GT-I9300/IMG_20151123_190309.jpg 5 | /home/relja/Desktop/GT-I9300/IMG_20151123_190315.jpg 6 | /home/relja/Desktop/GT-I9300/IMG_20151123_190320.jpg 7 | /home/relja/Desktop/GT-I9300/IMG_20151123_190328.jpg 8 | /home/relja/Desktop/GT-I9300/IMG_20151123_190336.jpg 9 | /home/relja/Desktop/GT-I9300/IMG_20151123_190346.jpg 10 | /home/relja/Desktop/GT-I9300/IMG_20151123_190351.jpg 11 | -------------------------------------------------------------------------------- /tests/GT-I9300/real_data.txt: -------------------------------------------------------------------------------- 1 | sensor size - 4.80mm x 3.60mm 2 | image size - 3264x2448 3 | focal length - 3.7mm 4 | 5 | focal width in pixels = 3264*3.7/4.8 = 2516 6 | focal height in pixels = 2448*3.7/3.6 = 2516 7 | -------------------------------------------------------------------------------- /tests/GoPro/dist_2/GoPro_2.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration tests/GoPro/pattern.txt --model-square-size 1.9 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 0.78807 -0.01435 -0.00762 8 | 0.00000 1.07218 0.16462 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 1210.47232 -22.04241 1524.29686 13 | 0.00000 1235.14645 1341.63691 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 21.961436 19 | K: 20 | 0.97367 -0.17151 0.15019 -19.22835 21 | 0.09198 0.89833 0.42958 -12.94944 22 | -0.20860 -0.40446 0.89045 35.64661 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 20.823481 27 | K: 28 | 0.90856 0.35585 -0.21885 -12.06795 29 | -0.20558 0.83688 0.50731 -9.27966 30 | 0.36368 -0.41593 0.83351 29.43973 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 22.448402 35 | K: 36 | 0.90827 0.02946 0.41735 -17.69545 37 | 0.05438 0.98074 -0.18758 -10.52236 38 | -0.41484 0.19306 0.88918 36.68241 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 24.077810 43 | K: 44 | 0.86839 0.04888 -0.49347 -6.56375 45 | -0.09262 0.99361 -0.06457 -10.19926 46 | 0.48716 0.10178 0.86736 22.72682 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 34.102741 51 | K: 52 | 0.99963 0.01246 0.02406 -11.80838 53 | -0.00264 0.92846 -0.37141 -9.28995 54 | -0.02697 0.37121 0.92816 22.77291 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 33.984075 59 | K: 60 | 0.84117 -0.03583 0.53958 -24.52971 61 | -0.13734 0.95093 0.27725 -4.67967 62 | -0.52304 -0.30732 0.79498 41.98635 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 26.858123 67 | K: 68 | 0.99601 0.05368 -0.07129 -14.19499 69 | -0.02708 0.94298 0.33173 -12.58429 70 | 0.08503 -0.32848 0.94068 24.41208 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 12.925186 75 | K: 76 | 0.90310 0.10826 -0.41555 -12.26144 77 | -0.02175 0.97799 0.20752 -12.30663 78 | 0.42887 -0.17838 0.88558 22.83102 79 | 80 | Extrinsics 8 81 | 82 | Reprojection error: 14.169549 83 | K: 84 | 0.82991 0.03515 -0.55679 -13.10406 85 | -0.16323 0.96964 -0.18209 -5.79776 86 | 0.53349 0.24201 0.81045 21.09215 87 | 88 | Extrinsics 9 89 | 90 | Reprojection error: 26.022614 91 | K: 92 | 0.92050 0.10536 0.37626 -29.52453 93 | -0.02761 0.97809 -0.20633 -4.42704 94 | -0.38976 0.17954 0.90325 31.67750 95 | 96 | Extrinsics 10 97 | 98 | Reprojection error: 21.512276 99 | K: 100 | 0.99613 0.07366 0.04788 -24.77174 101 | -0.07191 0.99671 -0.03740 -11.66532 102 | -0.05048 0.03381 0.99815 25.52927 103 | 104 | k: 105 | -0.000529 -0.000124 106 | 107 | 108 | 109 | ********************************************************** 110 | Final Optimization Results: 111 | A: 112 | 1280.27027 -15.29664 1519.49373 113 | 0.00000 1285.78643 1336.59873 114 | 0.00000 0.00000 1.00000 115 | 116 | k: 117 | -0.017707 -0.040149 118 | 119 | ------------ K no.0 -------------- 120 | 0.99439 -0.16081 0.15019 -19.20349 121 | 0.10295 0.91032 0.42958 -12.86995 122 | -0.18542 -0.40587 0.89045 34.67555 123 | 124 | Reprojection error: 12.162438 125 | 126 | ------------ K no.1 -------------- 127 | 0.91656 0.32323 -0.21885 -11.87952 128 | -0.21506 0.83032 0.50731 -9.33024 129 | 0.31967 -0.40565 0.83351 29.20762 130 | 131 | Reprojection error: 7.040607 132 | 133 | ------------ K no.2 -------------- 134 | 0.91121 0.04518 0.41735 -17.84990 135 | 0.07129 1.00473 -0.18758 -10.34225 136 | -0.38810 0.20260 0.88918 35.89639 137 | 138 | Reprojection error: 13.436240 139 | 140 | ------------ K no.3 -------------- 141 | 0.89149 0.02764 -0.49347 -6.47121 142 | -0.10606 0.98150 -0.06457 -10.24209 143 | 0.49280 0.09846 0.86736 22.59387 144 | 145 | Reprojection error: 18.915091 146 | 147 | ------------ K no.4 -------------- 148 | 1.00586 0.04979 0.02406 -11.95703 149 | 0.02940 0.90545 -0.37141 -8.94727 150 | -0.07990 0.39252 0.92816 22.90594 151 | 152 | Reprojection error: 14.740021 153 | 154 | ------------ K no.5 -------------- 155 | 0.85790 -0.03415 0.53958 -24.19651 156 | -0.13579 0.92073 0.27725 -4.52362 157 | -0.48674 -0.34957 0.79498 40.51323 158 | 159 | Reprojection error: 11.804584 160 | 161 | ------------ K no.6 -------------- 162 | 0.98910 0.04835 -0.07129 -14.35314 163 | -0.03712 0.97168 0.33173 -12.56578 164 | 0.09511 -0.29462 0.94068 23.73177 165 | 166 | Reprojection error: 40.833012 167 | 168 | ------------ K no.7 -------------- 169 | 0.89376 0.09078 -0.41555 -12.22120 170 | -0.02345 1.00046 0.20752 -12.38512 171 | 0.41107 -0.15436 0.88558 22.16967 172 | 173 | Reprojection error: 13.401831 174 | 175 | ------------ K no.8 -------------- 176 | 0.81879 0.03060 -0.55679 -13.10237 177 | -0.16370 1.01201 -0.18209 -5.70497 178 | 0.54783 0.22639 0.81045 20.51030 179 | 180 | Reprojection error: 10.887205 181 | 182 | ------------ K no.9 -------------- 183 | 0.95299 0.11926 0.37626 -29.68758 184 | -0.02616 0.95375 -0.20633 -4.39495 185 | -0.33804 0.12276 0.90325 29.49972 186 | 187 | Reprojection error: 16.169385 188 | 189 | ------------ K no.10 -------------- 190 | 1.02587 0.07790 0.04788 -25.04775 191 | -0.06867 1.02569 -0.03740 -11.72484 192 | 0.03733 0.08733 0.99815 22.85081 193 | 194 | Reprojection error: 18.007462 195 | 196 | Mean reprojection error for all patterns: 16.127080 197 | ********************************************************** 198 | -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_0.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_1.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_10.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_2.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_3.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_4.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_5.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_6.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_7.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_8.png -------------------------------------------------------------------------------- /tests/GoPro/dist_2/reprojection_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_2/reprojection_9.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/GoPro_2.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration tests/GoPro/pattern.txt --model-square-size 1.9 --skip-opt 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 0.78555 -0.01418 -0.00983 8 | 0.00000 1.06806 0.16410 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 1206.61087 -21.77719 1520.89450 13 | 0.00000 1230.39970 1341.04304 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 21.333357 19 | K: 20 | 0.97363 -0.17197 0.14991 -11.07684 21 | 0.09277 0.89876 0.42852 -7.49471 22 | -0.20842 -0.40331 0.89101 20.57897 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 21.051484 27 | K: 28 | 0.90911 0.35475 -0.21833 -6.93856 29 | -0.20547 0.83785 0.50576 -5.36830 30 | 0.36235 -0.41493 0.83459 16.99130 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 21.057755 35 | K: 36 | 0.91110 0.02982 0.41110 -10.29118 37 | 0.05253 0.98085 -0.18757 -6.04750 38 | -0.40882 0.19249 0.89208 21.03656 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 24.007742 43 | K: 44 | 0.86938 0.04899 -0.49172 -3.75986 45 | -0.09241 0.99364 -0.06439 -5.89915 46 | 0.48543 0.10142 0.86837 13.10823 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 34.480119 51 | K: 52 | 0.99963 0.01287 0.02396 -6.79767 53 | -0.00309 0.92895 -0.37019 -5.37483 54 | -0.02702 0.36998 0.92865 13.14123 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 33.073029 59 | K: 60 | 0.84140 -0.03591 0.53922 -14.14536 61 | -0.13689 0.95108 0.27696 -2.70181 62 | -0.52278 -0.30685 0.79533 24.25226 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 27.039015 67 | K: 68 | 0.99606 0.05305 -0.07111 -8.17609 69 | -0.02664 0.94341 0.33057 -7.28261 70 | 0.08462 -0.32737 0.94110 14.08608 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 12.862769 75 | K: 76 | 0.90385 0.10748 -0.41414 -7.05731 77 | -0.02165 0.97818 0.20662 -7.12009 78 | 0.42731 -0.17779 0.88645 13.17004 79 | 80 | Extrinsics 8 81 | 82 | Reprojection error: 14.250222 83 | K: 84 | 0.83115 0.03581 -0.55489 -7.54834 85 | -0.16287 0.96983 -0.18137 -3.35154 86 | 0.53166 0.24112 0.81191 12.16716 87 | 88 | Extrinsics 9 89 | 90 | Reprojection error: 25.374901 91 | K: 92 | 0.92075 0.10546 0.37562 -17.04791 93 | -0.02807 0.97819 -0.20582 -2.55695 94 | -0.38913 0.17897 0.90363 18.28828 95 | 96 | Extrinsics 10 97 | 98 | Reprojection error: 21.412260 99 | K: 100 | 0.99614 0.07361 0.04772 -14.29466 101 | -0.07187 0.99672 -0.03727 -6.74910 102 | -0.05031 0.03370 0.99817 14.72878 103 | 104 | k: 105 | 0.091427 -0.241017 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 106 | 107 | 108 | 109 | ********************************************************** 110 | Final Optimization Results: 111 | A: 112 | 2461.19297 4.37250 1545.79338 113 | 0.00000 2458.26415 1142.10337 114 | 0.00000 0.00000 1.00000 115 | 116 | k: 117 | -0.172385 0.292792 -0.000175 0.000242 0.632938 -0.000831 0.000000 0.000000 118 | 119 | ------------ K no.0 -------------- 120 | 1.43541 -0.24511 0.14991 -16.45701 121 | 0.10852 1.20308 0.42852 -6.16877 122 | -0.32906 -1.01082 0.89101 39.80790 123 | 124 | Reprojection error: 0.568901 125 | 126 | ------------ K no.1 -------------- 127 | 0.90719 0.32440 -0.21833 -7.20101 128 | -0.16563 0.75797 0.50576 -2.64070 129 | 0.41364 -0.65787 0.83459 23.89507 130 | 131 | Reprojection error: 0.463288 132 | 133 | ------------ K no.2 -------------- 134 | 1.06535 0.03524 0.41110 -12.42798 135 | 0.01125 1.18507 -0.18757 -3.14307 136 | -0.65647 0.13609 0.89208 33.48699 137 | 138 | Reprojection error: 0.478197 139 | 140 | ------------ K no.3 -------------- 141 | 0.89646 0.01083 -0.49172 -3.98679 142 | -0.03194 1.01173 -0.06439 -3.88989 143 | 0.59393 0.05789 0.86837 18.68170 144 | 145 | Reprojection error: 0.405157 146 | 147 | ------------ K no.4 -------------- 148 | 0.93671 0.02013 0.02396 -6.69875 149 | 0.02358 0.89471 -0.37019 -2.91842 150 | -0.16605 0.39746 0.92865 17.65547 151 | 152 | Reprojection error: 0.534219 153 | 154 | ------------ K no.5 -------------- 155 | 0.88147 -0.04171 0.53922 -14.44283 156 | -0.22245 0.87480 0.27696 1.18523 157 | -0.55669 -0.64720 0.79533 31.45586 158 | 159 | Reprojection error: 0.486472 160 | 161 | ------------ K no.6 -------------- 162 | 1.18363 0.03995 -0.07111 -10.09351 163 | -0.02723 1.07627 0.33057 -6.02183 164 | 0.06286 -0.62270 0.94110 22.79030 165 | 166 | Reprojection error: 0.669096 167 | 168 | ------------ K no.7 -------------- 169 | 0.88992 0.08810 -0.41414 -7.22386 170 | 0.04263 0.96642 0.20662 -5.10489 171 | 0.58807 -0.33105 0.88645 17.75486 172 | 173 | Reprojection error: 0.513872 174 | 175 | ------------ K no.8 -------------- 176 | 0.79987 0.00184 -0.55489 -7.57802 177 | -0.08087 1.02488 -0.18137 -1.44043 178 | 0.81644 0.15404 0.81191 15.83307 179 | 180 | Reprojection error: 0.521665 181 | 182 | ------------ K no.9 -------------- 183 | 0.98855 0.09845 0.37562 -18.00225 184 | -0.08770 1.02420 -0.20582 0.27694 185 | -0.33952 0.05539 0.90363 22.35914 186 | 187 | Reprojection error: 0.700985 188 | 189 | ------------ K no.10 -------------- 190 | 0.97648 0.06127 0.04772 -13.94634 191 | -0.06669 0.98474 -0.03727 -4.34763 192 | 0.15290 0.02479 0.99817 16.21796 193 | 194 | Reprojection error: 0.497865 195 | 196 | Mean reprojection error for all patterns: 0.530884 197 | ********************************************************** 198 | -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_0.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_1.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_10.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_2.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_3.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_4.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_5.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_6.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_7.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_8.png -------------------------------------------------------------------------------- /tests/GoPro/dist_full/reprojection_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/dist_full/reprojection_9.png -------------------------------------------------------------------------------- /tests/GoPro/im_files.txt: -------------------------------------------------------------------------------- 1 | /home/relja/Desktop/GoPro/GOPR0328.JPG 2 | /home/relja/Desktop/GoPro/GOPR0329.JPG 3 | /home/relja/Desktop/GoPro/GOPR0330.JPG 4 | /home/relja/Desktop/GoPro/GOPR0331.JPG 5 | /home/relja/Desktop/GoPro/GOPR0332.JPG 6 | /home/relja/Desktop/GoPro/GOPR0334.JPG 7 | /home/relja/Desktop/GoPro/GOPR0335.JPG 8 | /home/relja/Desktop/GoPro/GOPR0336.JPG 9 | /home/relja/Desktop/GoPro/GOPR0337.JPG 10 | /home/relja/Desktop/GoPro/GOPR0339.JPG 11 | /home/relja/Desktop/GoPro/GOPR0340.JPG 12 | -------------------------------------------------------------------------------- /tests/GoPro/real_data.txt: -------------------------------------------------------------------------------- 1 | sensor size - 5.37mm x 4.04mm 2 | image size - 3072x2304 3 | focal length - 2.8mm 4 | 5 | focal width in pixels = 3072*2.8/5.37 = 1601.7877095 6 | focal height in pixels = 2304*2.8/4.04 = 1596.83168317 7 | -------------------------------------------------------------------------------- /tests/GoPro/reprojection_dist.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/GoPro/reprojection_dist.jpg -------------------------------------------------------------------------------- /tests/old/results.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/old/results.zip -------------------------------------------------------------------------------- /tests/synthetic/results_synthetic.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljubobratovicrelja/camera-calibration/62480f97a435f51ee830d12829fea4fe5df0aca2/tests/synthetic/results_synthetic.tar.gz -------------------------------------------------------------------------------- /tests/synthetic/synthetic_1_3.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration synthetic_1_3.txt --model-square-size 1.1 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.03899 -0.00000 0.00270 8 | 0.00000 1.85422 0.03942 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 997.43331 -0.00333 962.59107 13 | 0.00000 1001.27733 561.28518 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 0.205450 19 | K: 20 | -0.99778 -0.00004 0.06654 4.54597 21 | 0.00002 -1.00000 -0.00041 2.86591 22 | 0.06654 -0.00041 0.99778 11.16667 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.187624 27 | K: 28 | -0.82185 -0.00036 0.56970 3.52999 29 | -0.00018 -1.00000 -0.00090 2.24664 30 | 0.56970 -0.00085 0.82185 12.96390 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 0.193404 35 | K: 36 | -0.99905 -0.02571 0.03515 5.42372 37 | 0.04024 -0.85362 0.51933 1.43266 38 | 0.01665 0.52026 0.85385 13.06833 39 | 40 | k: 41 | -0.000045 -0.000079 42 | 43 | 44 | 45 | ********************************************************** 46 | Final Optimization Results: 47 | A: 48 | 997.46414 -1.23668 962.63939 49 | 0.00000 1000.99451 561.27825 50 | 0.00000 0.00000 1.00000 51 | 52 | k: 53 | -0.000045 -0.000079 54 | 55 | ------------ K no.0 -------------- 56 | -0.99763 -0.00132 0.06654 4.54764 57 | 0.00002 -0.99971 -0.00041 2.86585 58 | 0.06598 -0.00018 0.99778 11.16467 59 | 60 | Reprojection error: 0.215382 61 | 62 | ------------ K no.1 -------------- 63 | -0.82154 -0.00126 0.56970 3.53144 64 | 0.00034 -1.00007 -0.00090 2.24699 65 | 0.56923 -0.00079 0.82185 12.96012 66 | 67 | Reprojection error: 0.160727 68 | 69 | ------------ K no.2 -------------- 70 | -0.99875 -0.02716 0.03515 5.42422 71 | 0.03992 -0.85382 0.51933 1.43278 72 | 0.01661 0.52010 0.85385 13.06873 73 | 74 | Reprojection error: 0.162051 75 | 76 | Mean reprojection error for all patterns: 0.179386 77 | ********************************************************** 78 | -------------------------------------------------------------------------------- /tests/synthetic/synthetic_1_4.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration synthetic_1_4.txt --model-square-size 1.1 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.03897 -0.00009 0.00243 8 | 0.00000 1.85431 0.03966 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 997.41045 -0.09108 962.33394 13 | 0.00000 1001.32761 561.41885 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 0.212117 19 | K: 20 | -0.99778 -0.00008 0.06654 4.54930 21 | 0.00006 -1.00000 -0.00042 2.86434 22 | 0.06654 -0.00041 0.99778 11.16692 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.173726 27 | K: 28 | -0.82181 -0.00039 0.56976 3.53389 29 | -0.00019 -1.00000 -0.00095 2.24497 30 | 0.56976 -0.00089 0.82181 12.96490 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 0.188792 35 | K: 36 | -0.99905 -0.02568 0.03515 5.42724 37 | 0.04022 -0.85363 0.51932 1.43082 38 | 0.01667 0.52025 0.85385 13.06809 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 0.174826 43 | K: 44 | -0.99561 0.03330 0.08743 4.37513 45 | -0.06846 -0.89621 -0.43831 2.59665 46 | 0.06376 -0.44238 0.89456 14.85487 47 | 48 | k: 49 | 0.000000 -0.000003 50 | 51 | 52 | 53 | ********************************************************** 54 | Final Optimization Results: 55 | A: 56 | 999.13439 0.36235 962.33436 57 | 0.00000 1003.02904 561.44297 58 | 0.00000 0.00000 1.00000 59 | 60 | k: 61 | 0.000000 -0.003382 62 | 63 | ------------ K no.0 -------------- 64 | -0.99795 0.00031 0.06654 4.54995 65 | 0.00001 -1.00019 -0.00042 2.86479 66 | 0.06499 -0.00038 0.99778 11.14105 67 | 68 | Reprojection error: 0.253486 69 | 70 | ------------ K no.1 -------------- 71 | -0.82160 0.00035 0.56976 3.53324 72 | 0.00026 -1.00072 -0.00095 2.24644 73 | 0.56902 -0.00249 0.82181 12.94581 74 | 75 | Reprojection error: 0.168939 76 | 77 | ------------ K no.2 -------------- 78 | -0.99905 -0.02542 0.03515 5.42884 79 | 0.04022 -0.85399 0.51932 1.43138 80 | 0.01792 0.51913 0.85385 13.07271 81 | 82 | Reprojection error: 0.564588 83 | 84 | ------------ K no.3 -------------- 85 | -0.99552 0.03398 0.08743 4.37594 86 | -0.06827 -0.89666 -0.43831 2.59686 87 | 0.06376 -0.44257 0.89456 14.83086 88 | 89 | Reprojection error: 0.220578 90 | 91 | Mean reprojection error for all patterns: 0.301898 92 | ********************************************************** 93 | -------------------------------------------------------------------------------- /tests/synthetic/synthetic_1_5.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration synthetic_1_5.txt --model-square-size 1.1 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.03908 -0.00024 0.00221 8 | 0.00000 1.85449 0.03954 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 997.51982 -0.23280 962.12374 13 | 0.00000 1001.42222 561.35162 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 0.219300 19 | K: 20 | -0.99778 -0.00016 0.06655 4.55206 21 | 0.00013 -1.00000 -0.00043 2.86513 22 | 0.06655 -0.00042 0.99778 11.16813 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.169847 27 | K: 28 | -0.82174 -0.00050 0.56986 3.53702 29 | -0.00011 -1.00000 -0.00103 2.24593 30 | 0.56986 -0.00091 0.82174 12.96664 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 0.190825 35 | K: 36 | -0.99905 -0.02569 0.03516 5.43019 37 | 0.04022 -0.85360 0.51938 1.43172 38 | 0.01667 0.52030 0.85382 13.06951 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 0.163518 43 | K: 44 | -0.99562 0.03318 0.08743 4.37852 45 | -0.06836 -0.89620 -0.43835 2.59763 46 | 0.06381 -0.44241 0.89454 14.85614 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 0.198771 51 | K: 52 | -0.96327 0.06953 0.25936 3.84288 53 | -0.09703 -0.99076 -0.09478 3.28618 54 | 0.25037 -0.11647 0.96112 13.88119 55 | 56 | k: 57 | 0.000671 0.000065 58 | 59 | 60 | 61 | ********************************************************** 62 | Final Optimization Results: 63 | A: 64 | 998.36735 -0.10972 962.16105 65 | 0.00000 1002.23504 561.38530 66 | 0.00000 0.00000 1.00000 67 | 68 | k: 69 | -0.000032 -0.001452 70 | 71 | ------------ K no.0 -------------- 72 | -0.99824 -0.00019 0.06655 4.55300 73 | -0.00001 -1.00011 -0.00043 2.86541 74 | 0.06636 -0.00023 0.99778 11.15780 75 | 76 | Reprojection error: 0.201051 77 | 78 | ------------ K no.1 -------------- 79 | -0.82173 -0.00016 0.56986 3.53708 80 | 0.00015 -1.00044 -0.00103 2.24615 81 | 0.56909 -0.00158 0.82174 12.95909 82 | 83 | Reprojection error: 0.145845 84 | 85 | ------------ K no.2 -------------- 86 | -0.99924 -0.02590 0.03516 5.43101 87 | 0.03987 -0.85411 0.51938 1.43257 88 | 0.01775 0.51966 0.85382 13.05789 89 | 90 | Reprojection error: 0.157573 91 | 92 | ------------ K no.3 -------------- 93 | -0.99580 0.03342 0.08743 4.37924 94 | -0.06821 -0.89647 -0.43835 2.59732 95 | 0.06336 -0.44217 0.89454 14.84725 96 | 97 | Reprojection error: 0.148427 98 | 99 | ------------ K no.4 -------------- 100 | -0.96354 0.07005 0.25936 3.84279 101 | -0.09674 -0.99090 -0.09478 3.28680 102 | 0.24958 -0.11675 0.96112 13.87341 103 | 104 | Reprojection error: 0.144514 105 | 106 | Mean reprojection error for all patterns: 0.159482 107 | ********************************************************** 108 | -------------------------------------------------------------------------------- /tests/synthetic/synthetic_1_6.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration synthetic_1_6.txt --model-square-size 1.1 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.03886 -0.00020 0.00254 8 | 0.00000 1.85390 0.03984 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 997.30532 -0.19155 962.43926 13 | 0.00000 1001.10427 561.51410 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 0.213560 19 | K: 20 | -0.99778 -0.00013 0.06653 4.54813 21 | 0.00010 -1.00000 -0.00042 2.86344 22 | 0.06653 -0.00042 0.99778 11.16505 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.166603 27 | K: 28 | -0.82186 -0.00043 0.56970 3.53251 29 | -0.00017 -1.00000 -0.00101 2.24385 30 | 0.56970 -0.00093 0.82186 12.96268 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 0.205888 35 | K: 36 | -0.99905 -0.02576 0.03515 5.42573 37 | 0.04028 -0.85369 0.51921 1.42967 38 | 0.01663 0.52014 0.85392 13.06606 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 0.170584 43 | K: 44 | -0.99562 0.03329 0.08742 4.37372 45 | -0.06845 -0.89624 -0.43826 2.59548 46 | 0.06376 -0.44232 0.89459 14.85295 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 0.199190 51 | K: 52 | -0.96329 0.06959 0.25929 3.83807 53 | -0.09708 -0.99076 -0.09474 3.28402 54 | 0.25030 -0.11643 0.96114 13.87718 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 0.168674 59 | K: 60 | -0.99740 0.07192 0.00523 5.56849 61 | -0.06923 -0.97536 0.20945 3.41640 62 | 0.02017 0.20854 0.97780 14.45051 63 | 64 | k: 65 | -0.032083 0.003642 66 | 67 | 68 | 69 | ********************************************************** 70 | Final Optimization Results: 71 | A: 72 | 1006.15255 1.21188 962.73594 73 | 0.00000 1011.01203 561.66275 74 | 0.00000 0.00000 1.00000 75 | 76 | k: 77 | -0.026746 0.009064 78 | 79 | ------------ K no.0 -------------- 80 | -0.99771 0.00062 0.06653 4.54865 81 | -0.00001 -1.00122 -0.00042 2.86296 82 | 0.06618 -0.00012 0.99778 11.07965 83 | 84 | Reprojection error: 0.781390 85 | 86 | ------------ K no.1 -------------- 87 | -0.82165 0.00118 0.56970 3.53646 88 | -0.00000 -1.00213 -0.00101 2.24415 89 | 0.56922 -0.00051 0.82186 12.87048 90 | 91 | Reprojection error: 0.836923 92 | 93 | ------------ K no.2 -------------- 94 | -1.00163 -0.02502 0.03515 5.43319 95 | 0.03987 -0.85506 0.51921 1.43005 96 | 0.01673 0.51622 0.85392 12.96194 97 | 98 | Reprojection error: 0.244242 99 | 100 | ------------ K no.3 -------------- 101 | -0.99894 0.03627 0.08742 4.37752 102 | -0.06986 -0.89772 -0.43826 2.60402 103 | 0.06335 -0.44010 0.89459 14.75528 104 | 105 | Reprojection error: 0.359435 106 | 107 | ------------ K no.4 -------------- 108 | -0.96639 0.07153 0.25929 3.84218 109 | -0.09674 -0.99214 -0.09474 3.28715 110 | 0.24807 -0.11533 0.96114 13.78087 111 | 112 | Reprojection error: 0.179139 113 | 114 | ------------ K no.5 -------------- 115 | -1.00077 0.07415 0.00523 5.57520 116 | -0.06987 -0.97706 0.20945 3.42458 117 | 0.02160 0.20769 0.97780 14.34323 118 | 119 | Reprojection error: 0.222696 120 | 121 | Mean reprojection error for all patterns: 0.437304 122 | ********************************************************** 123 | -------------------------------------------------------------------------------- /tests/synthetic/synthetic_1_9.log: -------------------------------------------------------------------------------- 1 | ******************************************** 2 | Program ran using flags: 3 | Build/camera_calibration synthetic_1_9.txt --model-square-size 1.1 4 | ******************************************** 5 | 6 | Intrinsics matrix A': 7 | 1.03967 -0.00012 0.00185 8 | 0.00000 1.85553 0.04029 9 | 0.00000 0.00000 1.00000 10 | 11 | Denormalized intrinsics matrix A: 12 | 998.08358 -0.11074 961.77799 13 | 0.00000 1001.98513 561.75891 14 | 0.00000 0.00000 1.00000 15 | 16 | Extrinsics 0 17 | 18 | Reprojection error: 0.211470 19 | K: 20 | -0.99778 -0.00008 0.06659 4.55562 21 | 0.00005 -1.00000 -0.00042 2.86062 22 | 0.06659 -0.00041 0.99778 11.17454 23 | 24 | Extrinsics 1 25 | 26 | Reprojection error: 0.160529 27 | K: 28 | -0.82152 -0.00032 0.57017 3.54120 29 | -0.00027 -1.00000 -0.00097 2.24063 30 | 0.57017 -0.00095 0.82152 12.97381 31 | 32 | Extrinsics 2 33 | 34 | Reprojection error: 0.196966 35 | K: 36 | -0.99906 -0.02553 0.03516 5.43365 37 | 0.04010 -0.85353 0.51950 1.42617 38 | 0.01675 0.52042 0.85374 13.07476 39 | 40 | Extrinsics 3 41 | 42 | Reprojection error: 0.161662 43 | K: 44 | -0.99561 0.03315 0.08749 4.38352 45 | -0.06838 -0.89607 -0.43862 2.59169 46 | 0.06385 -0.44268 0.89440 14.86510 47 | 48 | Extrinsics 4 49 | 50 | Reprojection error: 0.198963 51 | K: 52 | -0.96322 0.06961 0.25953 3.84745 53 | -0.09714 -0.99074 -0.09481 3.28067 54 | 0.25053 -0.11654 0.96107 13.88959 55 | 56 | Extrinsics 5 57 | 58 | Reprojection error: 0.179917 59 | K: 60 | -0.99739 0.07203 0.00524 5.57783 61 | -0.06933 -0.97532 0.20962 3.41255 62 | 0.02021 0.20871 0.97777 14.46189 63 | 64 | Extrinsics 6 65 | 66 | Reprojection error: 0.201502 67 | K: 68 | -0.91966 0.03804 -0.39087 4.89544 69 | -0.00732 -0.99679 -0.07977 2.73809 70 | -0.39265 -0.07050 0.91698 12.59119 71 | 72 | Extrinsics 7 73 | 74 | Reprojection error: 0.176135 75 | K: 76 | -1.00000 -0.00027 -0.00024 5.39343 77 | 0.00006 -0.78667 0.61737 2.43851 78 | -0.00036 0.61737 0.78667 9.88125 79 | 80 | Extrinsics 8 81 | 82 | Reprojection error: 0.267326 83 | K: 84 | -1.00000 0.00004 -0.00020 4.39716 85 | 0.00005 -0.91034 -0.41385 3.01212 86 | -0.00019 -0.41385 0.91034 9.32275 87 | 88 | k: 89 | 0.000000 0.000015 90 | 91 | 92 | 93 | ********************************************************** 94 | Final Optimization Results: 95 | A: 96 | 999.03844 -0.22375 961.79771 97 | 0.00000 1002.92282 561.77607 98 | 0.00000 0.00000 1.00000 99 | 100 | k: 101 | 0.000236 -0.001827 102 | 103 | ------------ K no.0 -------------- 104 | -0.99778 -0.00036 0.06659 4.55608 105 | 0.00005 -1.00020 -0.00042 2.86112 106 | 0.06617 0.00020 0.99778 11.15914 107 | 108 | Reprojection error: 0.222741 109 | 110 | ------------ K no.1 -------------- 111 | -0.82152 -0.00012 0.57017 3.54138 112 | -0.00027 -1.00070 -0.00097 2.24180 113 | 0.57017 0.00046 0.82152 12.97381 114 | 115 | Reprojection error: 0.220537 116 | 117 | ------------ K no.2 -------------- 118 | -0.99906 -0.02592 0.03516 5.43497 119 | 0.03977 -0.85429 0.51950 1.42722 120 | 0.01675 0.51991 0.85374 13.06558 121 | 122 | Reprojection error: 0.175636 123 | 124 | ------------ K no.3 -------------- 125 | -0.99561 0.03320 0.08749 4.38352 126 | -0.06838 -0.89651 -0.43862 2.59161 127 | 0.06361 -0.44278 0.89440 14.85549 128 | 129 | Reprojection error: 0.178478 130 | 131 | ------------ K no.4 -------------- 132 | -0.96341 0.06990 0.25953 3.84851 133 | -0.09714 -0.99074 -0.09481 3.28139 134 | 0.25001 -0.11623 0.96107 13.87670 135 | 136 | Reprojection error: 0.168736 137 | 138 | ------------ K no.5 -------------- 139 | -0.99766 0.07229 0.00524 5.57824 140 | -0.06912 -0.97515 0.20962 3.41355 141 | 0.02057 0.20932 0.97777 14.44477 142 | 143 | Reprojection error: 0.171447 144 | 145 | ------------ K no.6 -------------- 146 | -0.91985 0.03803 -0.39087 4.89643 147 | -0.00719 -0.99709 -0.07977 2.73836 148 | -0.39210 -0.07038 0.91698 12.57882 149 | 150 | Reprojection error: 0.184241 151 | 152 | ------------ K no.7 -------------- 153 | -1.00026 -0.00045 -0.00024 5.39434 154 | -0.00007 -0.78652 0.61737 2.43856 155 | 0.00016 0.61816 0.78667 9.86497 156 | 157 | Reprojection error: 0.173734 158 | 159 | ------------ K no.8 -------------- 160 | -1.00025 -0.00013 -0.00020 4.39866 161 | -0.00003 -0.91045 -0.41385 3.01246 162 | -0.00029 -0.41402 0.91034 9.31169 163 | 164 | Reprojection error: 0.257644 165 | 166 | Mean reprojection error for all patterns: 0.194799 167 | ********************************************************** 168 | --------------------------------------------------------------------------------