bbenligiray/lens-distortion-rectification

EDPLinesmex.mexw64

Closed this issue · 21 comments

Hi Benligiray,
your result about the radial distortion is more stable than Faisal Bukhari. thank you for your release. Could you release the code in EDPLinesmex.mexw64? I want to transform the code into c++. If you can help me, I'm very appreciate. thank you!

Hi,
You can find the latest implementation of EDPF on here:
https://github.com/CihanTopal/ED_Lib

Ok, Thanks!

Hi Benligiray.
What your EDPFLines inherit from? EDLines or EDPF? Could I use the result of EDPF::getSegments to compute the LineSegment?

Firstly, use the EDPF to detect the edge segment. Then use the EDLines to extract the lines?

I haven't used the repo I've linked, so I'm not sure about the exact function names, but yes, I've extracted edge segments with EDPF and computed line segments on those with EDLines.

Hi
I make it to c++ on linux. But I can't get the right result. My error is from 100 around to about 50.
This is my result every step.And I use the find_min_using_approximate_derivatives() function in dlib to replace the fminsearch in matlab. I get the kParams is always e-29, e-26.
1 - all line segments
2 - filtered line segments
3 - line segment groups
4 - selected line segment groups

Could you give me some advice?
Thank you

The line segments in the final image look good, they should give a good result. You can try playing with the derivative_eps parameter of find_min_using_approximate_derivatives().

In EDLines(), try lowering _max_error from 1.3 towards 0.5. This breaks longer line segments into shorter line segments that fit the edge segments better.

I use: double error = dlib::find_min_using_approximate_derivatives(dlib::bfgs_search_strategy(), dlib::objective_delta_stop_strategy(1e-12).be_verbose(), getDistParamError, starting_point, -1, 1e-10); where starting_point is [0,0].
And I change the _max_error from 1.3 to 0.5 in EDLines() in EDLines.h. the long lines are also long.
following is the output of code. the "iteration: " is the output of dlib.
I find your output of matlab code is k1 almost -1e-6 always, while my is always 1e-30 around. My error is from 99.6882 to 0.2, while yours is from 22 to 0.0002

iteration: 0 objective: 99.6882
iteration: 1 objective: 99.6882
496 starting_point k1 k2: -1.44177e-33 6.78382e-27 error: 99.6882
optimize result k1,k2: -1.69105e-35 8.03793e-29 error: 97.2231 i: 0
optimize result k1,k2: -9.81416e-33 5.1167e-26 error: 84.8663 i: 4
Eliminating line segment group # 4
iteration: 0 objective: 84.8663
iteration: 1 objective: 84.8663
496 starting_point k1 k2: -9.81416e-33 5.1167e-26 error: 84.8663
optimize result k1,k2: -9.23896e-33 4.87125e-26 error: 82.1132 i: 0
optimize result k1,k2: -1.48992e-35 6.65698e-29 error: 80.3982 i: 4
optimize result k1,k2: -7.90878e-33 4.60114e-26 error: 76.3614 i: 9
Eliminating line segment group # 9
iteration: 0 objective: 76.3614
iteration: 1 objective: 76.3614
496 starting_point k1 k2: -7.90878e-33 4.60114e-26 error: 76.3614
optimize result k1,k2: -7.38608e-33 4.35209e-26 error: 73.4174 i: 0
optimize result k1,k2: -8.82297e-33 4.32442e-26 error: 71.6734 i: 4
optimize result k1,k2: -4.44889e-33 4.36661e-26 error: 71.5446 i: 32
Eliminating line segment group # 32
iteration: 0 objective: 71.5446
iteration: 1 objective: 71.5446
496 starting_point k1 k2: -4.44889e-33 4.36661e-26 error: 71.5446
optimize result k1,k2: -4.09592e-33 4.1103e-26 error: 68.4669 i: 0
optimize result k1,k2: -5.45242e-33 4.07746e-26 error: 66.6927 i: 4
Eliminating line segment group # 4
iteration: 0 objective: 66.6927
iteration: 1 objective: 66.6927
496 starting_point k1 k2: -5.45242e-33 4.07746e-26 error: 66.6927
optimize result k1,k2: -1.67223e-33 1.27219e-26 error: 63.4758 i: 0
optimize result k1,k2: -5.34899e-33 3.95675e-26 error: 63.0438 i: 21
optimize result k1,k2: -2.47672e-33 1.26672e-26 error: 62.3484 i: 22
Eliminating line segment group # 22
iteration: 0 objective: 62.3484
iteration: 1 objective: 62.3484
496 starting_point k1 k2: -2.47672e-33 1.26672e-26 error: 62.3484
optimize result k1,k2: -9.37121e-36 4.85017e-29 error: 58.9965 i: 0
optimize result k1,k2: -1.00434e-35 5.02809e-29 error: 58.5568 i: 21
Eliminating line segment group # 21
iteration: 0 objective: 58.5568
iteration: 1 objective: 58.5568
496 starting_point k1 k2: -1.00434e-35 5.02809e-29 error: 58.5568
optimize result k1,k2: -9.17483e-36 4.64938e-29 error: 55.075 i: 0
Eliminating line segment group # 0
iteration: 0 objective: 55.075
iteration: 1 objective: 55.075
496 starting_point k1 k2: -9.17483e-36 4.64938e-29 error: 55.075
optimize result k1,k2: -9.54569e-36 4.63531e-29 error: 55.0015 i: 2
optimize result k1,k2: -8.55774e-36 4.41838e-29 error: 51.8509 i: 7
Eliminating line segment group # 7
iteration: 0 objective: 51.8509
iteration: 1 objective: 51.8509
496 starting_point k1 k2: -8.55774e-36 4.41838e-29 error: 51.8509
optimize result k1,k2: -1.94819e-32 9.62268e-26 error: 51.7153 i: 2
optimize result k1,k2: -9.34359e-36 4.46091e-29 error: 51.0553 i: 9
optimize result k1,k2: -8.72912e-36 4.42331e-29 error: 50.1945 i: 10
optimize result k1,k2: -1.86197e-32 9.36927e-26 error: 48.5511 i: 12
Eliminating line segment group # 12
iteration: 0 objective: 48.5511
iteration: 1 objective: 48.5511
496 starting_point k1 k2: -1.86197e-32 9.36927e-26 error: 48.5511
optimize result k1,k2: -1.93956e-32 9.32142e-26 error: 48.3494 i: 2
optimize result k1,k2: -2.03846e-32 9.45374e-26 error: 47.6767 i: 9
optimize result k1,k2: -1.89982e-32 9.36422e-26 error: 46.7994 i: 10
optimize result k1,k2: -2.0531e-33 1.00469e-26 error: 45.1244 i: 12
Eliminating line segment group # 12
iteration: 0 objective: 45.1244
iteration: 1 objective: 45.1244
496 starting_point k1 k2: -2.0531e-33 1.00469e-26 error: 45.1244
optimize result k1,k2: -2.13993e-33 9.98369e-27 error: 44.8515 i: 2
optimize result k1,k2: -2.25384e-33 1.01283e-26 error: 44.1656 i: 9
optimize result k1,k2: -2.09488e-33 1.00194e-26 error: 43.2711 i: 10
optimize result k1,k2: -1.86707e-33 9.28532e-27 error: 42.4747 i: 31
optimize result k1,k2: -8.89838e-36 3.99282e-29 error: 41.8965 i: 34
Eliminating line segment group # 34
iteration: 0 objective: 41.8965
iteration: 1 objective: 41.8965
496 starting_point k1 k2: -8.89838e-36 3.99282e-29 error: 41.8965
optimize result k1,k2: -9.26508e-36 3.96236e-29 error: 41.5536 i: 2
optimize result k1,k2: -9.77637e-36 4.02091e-29 error: 40.854 i: 9
optimize result k1,k2: -9.09768e-36 3.97185e-29 error: 39.9416 i: 10
optimize result k1,k2: -8.03189e-36 3.66104e-29 error: 39.1293 i: 31
Eliminating line segment group # 31
iteration: 0 objective: 39.1293
iteration: 1 objective: 39.1293
496 starting_point k1 k2: -8.03189e-36 3.66104e-29 error: 39.1293
optimize result k1,k2: -8.34505e-36 3.62382e-29 error: 38.7229 i: 2
optimize result k1,k2: -8.79274e-36 3.67162e-29 error: 38.0091 i: 9
optimize result k1,k2: -8.15619e-36 3.61914e-29 error: 37.078 i: 10
optimize result k1,k2: -7.78205e-36 3.38839e-29 error: 36.872 i: 31
Eliminating line segment group # 31
iteration: 0 objective: 36.872
iteration: 1 objective: 36.872
496 starting_point k1 k2: -7.78205e-36 3.38839e-29 error: 36.872
optimize result k1,k2: -5.87247e-33 2.43894e-26 error: 36.4102 i: 2
optimize result k1,k2: -8.47215e-36 3.38459e-29 error: 35.6814 i: 9
optimize result k1,k2: -1.91165e-33 8.09009e-27 error: 34.731 i: 10
optimize result k1,k2: -7.47567e-36 3.11536e-29 error: 34.5207 i: 31
Eliminating line segment group # 31
iteration: 0 objective: 34.5207
iteration: 1 objective: 34.5207
496 starting_point k1 k2: -7.47567e-36 3.11536e-29 error: 34.5207
optimize result k1,k2: -7.70702e-36 3.06696e-29 error: 33.999 i: 2
optimize result k1,k2: -8.08873e-36 3.09713e-29 error: 33.2548 i: 9
optimize result k1,k2: -7.51359e-36 3.03894e-29 error: 32.2841 i: 10
Eliminating line segment group # 10
iteration: 0 objective: 32.2841
iteration: 1 objective: 32.2841
496 starting_point k1 k2: -7.51359e-36 3.03894e-29 error: 32.2841
optimize result k1,k2: -7.01338e-36 2.97973e-29 error: 32.2397 i: 0
optimize result k1,k2: -7.74694e-36 2.98575e-29 error: 31.7024 i: 2
optimize result k1,k2: -8.14932e-36 3.01519e-29 error: 30.942 i: 9
optimize result k1,k2: -7.54313e-36 2.9522e-29 error: 29.9502 i: 10
Eliminating line segment group # 10
iteration: 0 objective: 29.9502
iteration: 1 objective: 29.9502
496 starting_point k1 k2: -7.54313e-36 2.9522e-29 error: 29.9502
optimize result k1,k2: -7.01545e-36 2.88869e-29 error: 29.853 i: 0
optimize result k1,k2: -7.77621e-36 2.89334e-29 error: 29.3038 i: 2
optimize result k1,k2: -8.2003e-36 2.92152e-29 error: 28.5265 i: 9
optimize result k1,k2: -8.47009e-36 2.8609e-29 error: 27.9698 i: 13
optimize result k1,k2: -6.53484e-36 2.73908e-29 error: 27.6582 i: 22
Eliminating line segment group # 22
iteration: 0 objective: 27.6582
iteration: 1 objective: 27.6582
496 starting_point k1 k2: -6.53484e-36 2.73908e-29 error: 27.6582
optimize result k1,k2: -1.46527e-33 6.49609e-27 error: 27.5067 i: 0
optimize result k1,k2: -1.63569e-33 6.49706e-27 error: 26.945 i: 2
optimize result k1,k2: -7.09588e-36 2.69441e-29 error: 26.15 i: 9
optimize result k1,k2: -1.78592e-33 6.39741e-27 error: 25.5807 i: 13
Eliminating line segment group # 13
iteration: 0 objective: 25.5807
iteration: 1 objective: 25.5807
496 starting_point k1 k2: -1.78592e-33 6.39741e-27 error: 25.5807
optimize result k1,k2: -1.65335e-33 6.22697e-27 error: 25.3774 i: 0
optimize result k1,k2: -1.83044e-33 6.22221e-27 error: 24.8026 i: 2
optimize result k1,k2: -7.94574e-36 2.57814e-29 error: 23.9891 i: 9
Eliminating line segment group # 9
iteration: 0 objective: 23.9891
iteration: 1 objective: 23.9891
496 starting_point k1 k2: -7.94574e-36 2.57814e-29 error: 23.9891
optimize result k1,k2: -7.35322e-36 2.50315e-29 error: 23.7431 i: 0
optimize result k1,k2: -8.12424e-36 2.4997e-29 error: 23.1546 i: 2
optimize result k1,k2: -8.20449e-36 2.56773e-29 error: 22.6238 i: 14
Eliminating line segment group # 14
iteration: 0 objective: 22.6238
iteration: 1 objective: 22.6238
496 starting_point k1 k2: -8.20449e-36 2.56773e-29 error: 22.6238
optimize result k1,k2: -7.55963e-36 2.48678e-29 error: 22.3384 i: 0
optimize result k1,k2: -8.39195e-36 2.48264e-29 error: 21.7356 i: 2
optimize result k1,k2: -7.47314e-36 2.49311e-29 error: 21.4114 i: 34
Eliminating line segment group # 34
iteration: 0 objective: 21.4114
iteration: 1 objective: 21.4114
496 starting_point k1 k2: -7.47314e-36 2.49311e-29 error: 21.4114
optimize result k1,k2: -6.82345e-36 2.40789e-29 error: 21.0886 i: 0
optimize result k1,k2: -7.65049e-36 2.40148e-29 error: 20.4707 i: 2
Eliminating line segment group # 2
iteration: 0 objective: 20.4707
iteration: 1 objective: 20.4707
496 starting_point k1 k2: -7.65049e-36 2.40148e-29 error: 20.4707
optimize result k1,k2: -6.98093e-36 2.31323e-29 error: 20.1155 i: 0
optimize result k1,k2: -8.12887e-36 2.38808e-29 error: 20.0411 i: 6
optimize result k1,k2: -6.97051e-36 2.31186e-29 error: 19.9492 i: 7
optimize result k1,k2: -7.88862e-36 2.41538e-29 error: 19.8813 i: 12
optimize result k1,k2: -6.5885e-36 2.24339e-29 error: 19.5108 i: 34
Eliminating line segment group # 34
iteration: 0 objective: 19.5108
iteration: 1 objective: 19.5108
496 starting_point k1 k2: -6.5885e-36 2.24339e-29 error: 19.5108
optimize result k1,k2: -5.96118e-36 2.15414e-29 error: 19.1209 i: 0
optimize result k1,k2: -6.99408e-36 2.22349e-29 error: 19.0447 i: 6
optimize result k1,k2: -5.9443e-36 2.15161e-29 error: 18.9503 i: 7
optimize result k1,k2: -6.74808e-36 2.2477e-29 error: 18.8806 i: 12
Eliminating line segment group # 12
iteration: 0 objective: 18.8806
iteration: 1 objective: 18.8806
496 starting_point k1 k2: -6.74808e-36 2.2477e-29 error: 18.8806
optimize result k1,k2: -6.07715e-36 2.15302e-29 error: 18.4632 i: 0
optimize result k1,k2: -7.18565e-36 2.22673e-29 error: 18.3849 i: 6
optimize result k1,k2: -6.05998e-36 2.15032e-29 error: 18.288 i: 7
optimize result k1,k2: -6.70461e-36 2.24716e-29 error: 18.2713 i: 21
Eliminating line segment group # 21
iteration: 0 objective: 18.2713
iteration: 1 objective: 18.2713
496 starting_point k1 k2: -6.70461e-36 2.24716e-29 error: 18.2713
optimize result k1,k2: -5.99655e-36 2.14683e-29 error: 17.8254 i: 0
optimize result k1,k2: -7.16728e-36 2.22485e-29 error: 17.7449 i: 6
optimize result k1,k2: -5.97781e-36 2.14392e-29 error: 17.6453 i: 7
Eliminating line segment group # 7
iteration: 0 objective: 17.6453
iteration: 1 objective: 17.6453
496 starting_point k1 k2: -5.97781e-36 2.14392e-29 error: 17.6453
optimize result k1,k2: -5.29673e-36 2.04169e-29 error: 17.1687 i: 0
optimize result k1,k2: -6.39246e-36 2.11646e-29 error: 17.0859 i: 6
optimize result k1,k2: -5.2409e-36 2.03159e-29 error: 17.0712 i: 30
Eliminating line segment group # 30
iteration: 0 objective: 17.0712
iteration: 1 objective: 17.0712
496 starting_point k1 k2: -5.2409e-36 2.03159e-29 error: 17.0712
optimize result k1,k2: -4.59591e-36 1.9282e-29 error: 16.5637 i: 0
optimize result k1,k2: -5.60301e-36 1.99869e-29 error: 16.4785 i: 6
Eliminating line segment group # 6
iteration: 0 objective: 16.4785
iteration: 1 objective: 16.4785
496 starting_point k1 k2: -5.60301e-36 1.99869e-29 error: 16.4785
optimize result k1,k2: -4.91288e-36 1.89022e-29 error: 15.9377 i: 0
optimize result k1,k2: -5.49287e-36 2.01824e-29 error: 15.934 i: 16
optimize result k1,k2: -4.99373e-36 1.9152e-29 error: 15.8985 i: 23
Eliminating line segment group # 23
iteration: 0 objective: 15.8985
iteration: 1 objective: 15.8985
496 starting_point k1 k2: -4.99373e-36 1.9152e-29 error: 15.8985
optimize result k1,k2: -3.15323e-33 1.31508e-26 error: 15.3227 i: 0
optimize result k1,k2: -4.83966e-36 1.92889e-29 error: 15.3188 i: 16
optimize result k1,k2: -3.2025e-33 1.33268e-26 error: 15.2822 i: 23
Eliminating line segment group # 23
iteration: 0 objective: 15.2822
iteration: 1 objective: 15.2822
496 starting_point k1 k2: -3.2025e-33 1.33268e-26 error: 15.2822
optimize result k1,k2: -2.73336e-33 1.24946e-26 error: 14.668 i: 0
optimize result k1,k2: -3.05942e-33 1.33799e-26 error: 14.664 i: 16
Eliminating line segment group # 16
iteration: 0 objective: 14.664
iteration: 1 objective: 14.664
496 starting_point k1 k2: -3.05942e-33 1.33799e-26 error: 14.664
optimize result k1,k2: -2.56369e-33 1.24833e-26 error: 14.0087 i: 0
Eliminating line segment group # 0
iteration: 0 objective: 14.0087
iteration: 1 objective: 14.0087
496 starting_point k1 k2: -2.56369e-33 1.24833e-26 error: 14.0087
optimize result k1,k2: -2.21597e-33 1.16605e-26 error: 13.4754 i: 1
optimize result k1,k2: -2.26583e-33 1.16447e-26 error: 13.3823 i: 14
Eliminating line segment group # 14
iteration: 0 objective: 13.3823
iteration: 1 objective: 13.3823
496 starting_point k1 k2: -2.26583e-33 1.16447e-26 error: 13.3823
optimize result k1,k2: -1.93712e-33 1.08146e-26 error: 12.8076 i: 1
Eliminating line segment group # 1
iteration: 0 objective: 12.8076
iteration: 1 objective: 12.8076
496 starting_point k1 k2: -1.93712e-33 1.08146e-26 error: 12.8076
optimize result k1,k2: -1.82841e-33 1.03424e-26 error: 12.695 i: 4
optimize result k1,k2: -2.27097e-33 1.15018e-26 error: 12.2719 i: 6
optimize result k1,k2: -2.04525e-33 1.11167e-26 error: 12.2223 i: 15
optimize result k1,k2: -1.55825e-33 9.9948e-27 error: 12.1967 i: 23
Eliminating line segment group # 23
iteration: 0 objective: 12.1967
iteration: 1 objective: 12.1967
496 starting_point k1 k2: -1.55825e-33 9.9948e-27 error: 12.1967
optimize result k1,k2: -1.46218e-33 9.52141e-27 error: 12.0563 i: 4
optimize result k1,k2: -1.80473e-33 1.0563e-26 error: 11.6169 i: 6
optimize result k1,k2: -1.61383e-33 1.02048e-26 error: 11.5654 i: 15
Eliminating line segment group # 15
iteration: 0 objective: 11.5654
iteration: 1 objective: 11.5654
496 starting_point k1 k2: -1.61383e-33 1.02048e-26 error: 11.5654
optimize result k1,k2: -1.50525e-33 9.67766e-27 error: 11.3941 i: 4
optimize result k1,k2: -1.90949e-33 1.08835e-26 error: 10.9371 i: 6
Eliminating line segment group # 6
iteration: 0 objective: 10.9371
iteration: 1 objective: 10.9371
496 starting_point k1 k2: -1.90949e-33 1.08835e-26 error: 10.9371
optimize result k1,k2: -1.87551e-33 1.07989e-26 error: 10.92 i: 1
optimize result k1,k2: -1.77026e-33 1.0268e-26 error: 10.7325 i: 4
optimize result k1,k2: -1.57763e-33 1.00785e-26 error: 10.4829 i: 14
optimize result k1,k2: -1.71293e-33 9.96183e-27 error: 10.3819 i: 15
optimize result k1,k2: -1.46924e-33 9.91229e-27 error: 10.2922 i: 19
Eliminating line segment group # 19
iteration: 0 objective: 10.2922
iteration: 1 objective: 10.2922
496 starting_point k1 k2: -1.46924e-33 9.91229e-27 error: 10.2922
optimize result k1,k2: -1.42482e-33 9.79328e-27 error: 10.2463 i: 1
optimize result k1,k2: -1.34941e-33 9.29506e-27 error: 10.0506 i: 4
optimize result k1,k2: -1.17582e-33 9.10228e-27 error: 9.79023 i: 14
optimize result k1,k2: -1.3007e-33 8.98799e-27 error: 9.68484 i: 15
optimize result k1,k2: -9.71793e-33 8.04189e-26 error: 9.5912 i: 19
Eliminating line segment group # 19
iteration: 0 objective: 9.5912
iteration: 1 objective: 9.5912
496 starting_point k1 k2: -9.71793e-33 8.04189e-26 error: 9.5912
optimize result k1,k2: -1.02862e-33 8.78162e-27 error: 9.51135 i: 1
optimize result k1,k2: -8.8162e-33 7.48487e-26 error: 9.30678 i: 4
optimize result k1,k2: -7.42991e-33 7.30831e-26 error: 9.03454 i: 14
optimize result k1,k2: -8.45629e-33 7.20764e-26 error: 8.92436 i: 15
Eliminating line segment group # 15
iteration: 0 objective: 8.92436
iteration: 1 objective: 8.92436
496 starting_point k1 k2: -8.45629e-33 7.20764e-26 error: 8.92436
optimize result k1,k2: -7.98958e-33 7.0398e-26 error: 8.80895 i: 1
optimize result k1,k2: -8.44421e-34 7.38971e-27 error: 8.59465 i: 4
optimize result k1,k2: -7.05691e-34 7.19085e-27 error: 8.30944 i: 14
optimize result k1,k2: -8.05937e-34 7.08162e-27 error: 8.19402 i: 15
Eliminating line segment group # 15
iteration: 0 objective: 8.19402
iteration: 1 objective: 8.19402
496 starting_point k1 k2: -8.05937e-34 7.08162e-27 error: 8.19402
optimize result k1,k2: -7.58095e-34 7.07125e-27 error: 8.16069 i: 0
optimize result k1,k2: -7.53845e-34 6.86246e-27 error: 8.03632 i: 1
optimize result k1,k2: -7.15794e-34 6.46296e-27 error: 7.8113 i: 4
optimize result k1,k2: -5.924e-34 6.26142e-27 error: 7.51184 i: 14
optimize result k1,k2: -6.60566e-34 6.36081e-27 error: 7.39554 i: 17
Eliminating line segment group # 17
iteration: 0 objective: 7.39554
iteration: 1 objective: 7.39554
496 starting_point k1 k2: -6.60566e-34 6.36081e-27 error: 7.39554
optimize result k1,k2: -6.08918e-34 6.3111e-27 error: 7.31843 i: 0
optimize result k1,k2: -6.07098e-34 6.10791e-27 error: 7.18752 i: 1
optimize result k1,k2: -5.18561e-33 5.14974e-26 error: 6.95066 i: 4
optimize result k1,k2: -4.62931e-34 5.51153e-27 error: 6.63543 i: 14
optimize result k1,k2: -5.21178e-34 5.59108e-27 error: 6.51301 i: 17
Eliminating line segment group # 17
iteration: 0 objective: 6.51301
iteration: 1 objective: 6.51301
496 starting_point k1 k2: -5.21178e-34 5.59108e-27 error: 6.51301
optimize result k1,k2: -4.20433e-33 4.94681e-26 error: 6.38259 i: 0
optimize result k1,k2: -6.41289e-37 7.27053e-30 error: 6.2444 i: 1
optimize result k1,k2: -6.0843e-37 6.76352e-30 error: 5.99438 i: 4
optimize result k1,k2: -4.69458e-37 6.46172e-30 error: 5.66164 i: 14
Eliminating line segment group # 14
iteration: 0 objective: 5.66164
iteration: 1 objective: 5.66164
496 starting_point k1 k2: -4.69458e-37 6.46172e-30 error: 5.66164
optimize result k1,k2: -3.96145e-37 6.26364e-30 error: 5.47347 i: 0
optimize result k1,k2: -4.0213e-37 6.01577e-30 error: 5.32715 i: 1
optimize result k1,k2: -8.42681e-34 1.21448e-26 error: 5.06243 i: 4
optimize result k1,k2: -2.9276e-37 5.38742e-30 error: 4.8741 i: 14
Eliminating line segment group # 14
iteration: 0 objective: 4.8741
iteration: 1 objective: 4.8741
496 starting_point k1 k2: -2.9276e-37 5.38742e-30 error: 4.8741
optimize result k1,k2: -2.25111e-37 5.12865e-30 error: 4.62494 i: 0
optimize result k1,k2: -2.34398e-37 4.90022e-30 error: 4.46949 i: 1
optimize result k1,k2: -4.50163e-33 8.81393e-26 error: 4.18822 i: 4
Eliminating line segment group # 4
iteration: 0 objective: 4.18822
iteration: 1 objective: 4.18822
496 starting_point k1 k2: -4.50163e-33 8.81393e-26 error: 4.18822
optimize result k1,k2: -3.31791e-33 8.20393e-26 error: 3.87672 i: 0
optimize result k1,k2: -1.75834e-37 3.95632e-30 error: 3.7109 i: 1
Eliminating line segment group # 1
iteration: 0 objective: 3.7109
iteration: 1 objective: 3.7109
496 starting_point k1 k2: -1.75834e-37 3.95632e-30 error: 3.7109
optimize result k1,k2: -1.18907e-37 3.60346e-30 error: 3.34306 i: 0
optimize result k1,k2: -1.55745e-37 3.49339e-30 error: 3.25834 i: 1
optimize result k1,k2: -1.35175e-37 3.27415e-30 error: 3.17725 i: 12
Eliminating line segment group # 12
iteration: 0 objective: 3.17725
iteration: 1 objective: 3.17725
496 starting_point k1 k2: -1.35175e-37 3.27415e-30 error: 3.17725
optimize result k1,k2: -8.5449e-38 2.88138e-30 error: 2.74006 i: 0
optimize result k1,k2: -7.52733e-34 1.82359e-26 error: 2.64882 i: 1
Eliminating line segment group # 1
iteration: 0 objective: 2.64882
iteration: 1 objective: 2.64882
496 starting_point k1 k2: -7.52733e-34 1.82359e-26 error: 2.64882
optimize result k1,k2: -6.79367e-38 2.33686e-30 error: 2.13117 i: 0
Eliminating line segment group # 0
iteration: 0 objective: 2.13117
iteration: 1 objective: 2.13117
496 starting_point k1 k2: -6.79367e-38 2.33686e-30 error: 2.13117
optimize result k1,k2: -6.25715e-38 2.4198e-30 error: 1.95445 i: 0
optimize result k1,k2: -5.35962e-34 1.63601e-26 error: 1.89221 i: 3
Eliminating line segment group # 3
iteration: 0 objective: 1.89221
iteration: 1 objective: 1.89221
496 starting_point k1 k2: -5.35962e-34 1.63601e-26 error: 1.89221
optimize result k1,k2: -1.53346e-33 5.20567e-26 error: 1.67392 i: 0
optimize result k1,k2: -1.63896e-38 6.94958e-31 error: 1.65938 i: 7
Eliminating line segment group # 7
iteration: 0 objective: 1.65938
iteration: 1 objective: 1.65938
496 starting_point k1 k2: -1.63896e-38 6.94958e-31 error: 1.65938
optimize result k1,k2: -1.26857e-38 7.09686e-31 error: 1.39097 i: 0
optimize result k1,k2: -8.04614e-39 5.58671e-31 error: 1.37481 i: 7
Eliminating line segment group # 7
iteration: 0 objective: 1.37481
iteration: 1 objective: 1.37481
496 starting_point k1 k2: -8.04614e-39 5.58671e-31 error: 1.37481
optimize result k1,k2: -3.37953e-39 5.37681e-31 error: 1.03728 i: 0
Eliminating line segment group # 0
iteration: 0 objective: 1.03728
iteration: 1 objective: 1.03728
496 starting_point k1 k2: -3.37953e-39 5.37681e-31 error: 1.03728
optimize result k1,k2: 3.77783e-39 6.27928e-31 error: 0.861494 i: 6
Eliminating line segment group # 6
iteration: 0 objective: 0.861494
iteration: 1 objective: 0.861494
496 starting_point k1 k2: 3.77783e-39 6.27928e-31 error: 0.861494
optimize result k1,k2: 2.03437e-39 5.35453e-31 error: 0.851732 i: 2
optimize result k1,k2: 1.82372e-32 4.63615e-25 error: 0.627118 i: 6
Eliminating line segment group # 6
iteration: 0 objective: 0.627118
iteration: 1 objective: 0.627118
496 starting_point k1 k2: 1.82372e-32 4.63615e-25 error: 0.627118
optimize result k1,k2: 2.48395e-06 2.56551e-12 error: 0.266875 i: 1
Eliminating line segment group # 1
4 - Selected line segment groups num: 5
iteration: 0 objective: 0.702687
iteration: 1 objective: 0.421246
iteration: 2 objective: 0.266875
iteration: 3 objective: 0.266875
畸变参数 k1, k2: 2.48395e-06 2.56551e-12 error: 0.266875

1 - all line segments
1 - all line segments

2 - filtered line segments
2 - filtered line segments

3 - line segment groups
3 - line segment groups

4 - selected line segment groups
4 - selected line segment groups

Hi
I found the dlib::find_min_using_approximate_derivatives() can't find the minValue of the function. And the optimization result is related with the init value. Maybe the minValue is very small??? Could you suggest some function according the fminSearc() in matlab? And I find the groupLineSegments() make one line in two groups. Is it normal? Thank you for your help

You can try this:
https://docs.opencv.org/3.0-beta/modules/core/doc/optim.html#downhillsolver
However, dlib::find_min_using_approximate_derivatives() should have worked. Have you tried using smaller derivative_eps? Another thing you can check is to save the selected line segments groups to a text file in Matlab, then read that with C++ and optimize with dlib to make sure that the problem is with optimization and not with EDLines or line segment grouping.

Thank you.
I use the selected line segments groups from c++, then add them to matlab to optimize. And I get different result, e-7 in matlab and e-30 in c++. And the result in c++ is easily effected by the initial values. I try the derivative_eps, no help.

I try use to the fminSearch() function in C++

I try the opencv cv::DownhillSolver to solver the getDistParamError. x is (0.0, 0.0), step is (-e-10, -e-10). The result is [-5e-11, -0]; if step is [-e-8, -e-8], the result is [-5e-09, 0]; if step is [-e-7, -e-7], the result is -5e-08. The optimal result is related with the step. while the result of the same data on matlab is [-1.55e-05, 0], the result of same data with dlib is [2.59453e-06, 2.2e-12].
the result with matlab of data 2 is [-8.785e-07,0], while the data with dlib is [-2.47868e-35, 2.76457e-26] with the same init data [0.0, 0.0]. And the result with opencv is related with the step.

Hi,
sorry to disturb you again. I have a problem. You can undistort the image without exact fx,fy,cx,cy; while the function undistortImage() in opencv need the real fx,fy,cx,cy. Why? The k1,k2 are different from the k1, k2, k3, k4 in opencv?

And I find your algorithm of unditorting image is almost same with the opencv. I'm confused with it. If you can help me, I'm very appreciate. Thank you!

Here, we assume that we don't know the internal parameters, we don't want to find the actual k1, k2, we just want to undistort the image. Then, we assume that fx=1, fy=1, cx=width/2, cy=height/2 (https://github.com/bbenligiray/lens-distortion-rectification/blob/master/getDistParamError.m#L3) and estimate k1, k2 according to that. Undistorting the image with these parameters results in a rectified image, but k1, k2 are not the actual distortion parameters.

The calibration in OpenCV estimates the actual camera parameters. However, its undistort function should still work if you give fx=1, fy=1, cx=width/2, cy=height/2 and k1, k2 found by this method.

If you want to find the actual k1, k2 with this method, you need to enter the actual intrinsic parameters at this line https://github.com/bbenligiray/lens-distortion-rectification/blob/master/getDistParamError.m#L3

I haven't worked with fisheye distortion, but as far as I know, it uses a different model. You should use this undistort function https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#undistort

I tried with cv::undistort() with my own data. I use fx = 1, fy =1, cx = width/2, cy = height/2; get k1 = -1.50956e-06, k2 = 1.45705e-12. I undist it on matlab, then I get the figure 1.
l_0_undisti
When I undistort it with cv::undistort() with the fx = 1, fy =1, cx = width/2, cy = height/2, k1 = -1.50956e-06, k2 = 1.45705e-12 , I get figure 2.
undistimg
When I used fx = 369.759, fy = 367.973, cx = 376.7865, cy = 233.2639, I get k1 = -0.216073, k2 = 0.0370588. I undistort it with undistortImage on matlab , then I get the following figure 3.
undisti
When I used fx = 369.759, fy = 367.973, cx = 376.7865, cy = 233.2639, k1 = -0.216073, k2 = 0.0370588. I undistort it with cv::undistort() of opencv. I get the figure 4
undistopencv

And I find that the lines in figure2,3,4 is not so straight with figure 1.

cx should be width/2 and cy should be height/2, that's critical. I don't see much difference between the images though.

sorry , I find a bug. After fix it, the undistorted image result of fx = 1, fy =1,cx = width/2, cy = height/2 is the same with real fx, fy, cx, cy. Thank you very much.

Great to hear that, I wasn't expecting a happy ending :)