gaoxiang12 / slambook2

edition 2 of the slambook
MIT License
5.39k stars 2k forks source link

Two confuses about ch8/direct_method.cpp #246

Open Wedsonlin opened 2 years ago

Wedsonlin commented 2 years ago

1.

In direct_method.cpp, the function GetPixelValue checks the boundary as follow: inline float GetPixelValue(const cv::Mat &img, float x, float y) { // boundary check if (x < 0) x = 0; if (y < 0) y = 0; if (x >= img.cols) x = img.cols - 1; if (y >= img.rows) y = img.rows - 1;

In the case that index x( or index y) crosses the boundary, it will be rectified to img.cols-1( or img.rows-1). However, constructing return value of this function requires the element data[img.step + 1] , and it equals todata[img.cols * img.step + img.rows]` under the circumstance where index x and index y both cross the boundary. I think this will result in segmentation fault.

2.

The program gets different output when runs on multithreading mode and singlethreading mode. When executing DirectPoseEstimationSingleLayer in singlethreading mode, it outputs iteration: 0, cost: 22018.4 iteration: 1, cost: 20808 iteration: 2, cost: 20255.6 iteration: 3, cost: 19935.7 iteration: 4, cost: 19614.4 iteration: 5, cost: 19325.8 iteration: 6, cost: 19222.7 iteration: 7, cost: 19185.9 iteration: 8, cost: 19131 iteration: 9, cost: 19081.2 T21 = 0.999999 -9.92915e-05 0.00132181 -0.0215359 9.49556e-05 0.999995 0.00327994 -0.0148981 -0.00132213 -0.00327981 0.999994 -0.127968 0 0 0 1 When executing DirectPoseEstimationSingleLayer in multithreading mode, it outputs: iteration: 0, cost: 1.02582e+07 iteration: 1, cost: 9.66536e+06 iteration: 2, cost: 9.37424e+06 iteration: 3, cost: 9.1932e+06 iteration: 4, cost: 9.02405e+06 iteration: 5, cost: 8.9014e+06 iteration: 6, cost: 8.84211e+06 iteration: 7, cost: 8.82602e+06 iteration: 8, cost: 8.79197e+06 iteration: 9, cost: 8.74971e+06 T21 = 0.999999 -9.92915e-05 0.00132181 -0.0215359 9.49556e-05 0.999995 0.00327994 -0.0148981 -0.00132213 -0.00327981 0.999994 -0.127968 0 0 0 1 The cost of each iteration has significant difference, but the estimated pose remains the same.