fixstars / libSGM

Stereo Semi Global Matching by cuda
Apache License 2.0
623 stars 189 forks source link

how to set p1/p2? #42

Closed tensorbuffer closed 5 years ago

tensorbuffer commented 5 years ago

Hi, OpenCV uses 4 times square of SAD window size as p1, and 8*p1 as p2. I think this is easy to understand: p1 threshold is within each SAD window (so total square of SAD window size of pixels) on average each pixel differs by 4. For census, each pixel generates 31 bits so the cost is mostly 31. This is a much smaller range than opencv's p1 threshold to adjust. In your code, p1 is 10 and p2 is 120. I wonder what these values come from, especially p2, seems to be too big? In detail, initially, L(p-r,d) is mostly 31, L(p-r, d-1) is mostly 31+p1). I understand that L would might become bigger as the DP goes, but how 120 is get, just from experience?

sotsuka-fixstars commented 5 years ago

Hi, @tensorbuffer

how 120 is get, just from experience?

Yes. We got this parameter while testing KITTI training dataset.

how to set p1/p2?

I thought you can use Hyperparameter Optimization Framework if you have training dataset. For example, Optuna, Hyperopt.

I tried to use Optuna after you opened this issue. Optuna said {'p1': 15, 'p2': 122} as best parameter (where used dataset is KITTI training dataset, objective is minimizing All / All Error, and n_trials=100).

tensorbuffer commented 5 years ago

Thanks very much for your help!