Improve BRISK Initialization#18037
Conversation
13a10a4 to
6a1390a
Compare
|
@danielenricocahall Thanks for the contribution! The patch is very noisy and contains a lot of formatting changes and non-functional changes. Please revert all formatting changes and presume only functional part. |
6a1390a to
04158d4
Compare
@asmorkalov ah sorry! Used the autoformatting in CLion and it looks like it reformatted the whole file. Fixed! |
04158d4 to
6915199
Compare
|
Please pay attention on CI test failure on Windows: |
@asmorkalov Sorry I just saw this - that failure looks like a documented transient error though: #9179. Should I just re-kick off the build? |
b106acc to
02ac64c
Compare
modules/features2d/src/brisk.cpp
Outdated
| { | ||
| points_ += numberList[ring]; | ||
| } | ||
| for (size_t rot = 0; rot < n_rot_; ++rot) |
There was a problem hiding this comment.
n_rot_ is hard-codded constant and I propose to calculate the table once or even replace it with pre-computed values.
There was a problem hiding this comment.
@asmorkalov yes that's pretty much what I did with the trig values - I just don't know if other values in that loop can be precomputed.
02ac64c to
eac4411
Compare
15a018b to
1db2a58
Compare
asmorkalov
left a comment
There was a problem hiding this comment.
Could you share the performance test that you use for the constructor?
| } | ||
| double cosval = 1., sinval = 0.; | ||
| double dcos = cos(2*CV_PI/double(n_rot_)), dsin = sin(2*CV_PI/double(n_rot_)); | ||
| for( size_t rot = 0; rot < n_rot_; ++rot) |
There was a problem hiding this comment.
I propose to add a comment that loop body is approximation of sin and cos. It makes code easier to read.
There was a problem hiding this comment.
sounds good - will add comments later
@asmorkalov the performance evaluation I used is contained in the description. But just for clarity: |
asmorkalov
left a comment
There was a problem hiding this comment.
Well Done! Please squash commits to merge the change as single patch.
reformatting Improve initialization performance of Brisk fix formatting Improve initialization performance of Brisk formatting Improve initialization performance of Brisk make a lookup table for ring use cosine/sine lookup table for theta in brisk and utilize trig identity fix ring lookup table use cosine/sine lookup table for theta in brisk and utilize trig identity formatting use cosine/sine lookup table for theta in brisk and utilize trig identity move scale radius product to ring loop to ensure it's not recomputed for each rot revert change move scale radius product to ring loop to ensure it's not recomputed for each rot remove rings lookup table move scale radius product to ring loop to ensure it's not recomputed for each rot fix formatting of for loop move scale radius product to ring loop to ensure it's not recomputed for each rot use sine/cosine approximations for brisk lookup table. add documentation for sine/cosine lookup tables Improve initialization performance of BRISK
eae90e5 to
ac177b8
Compare
@asmorkalov done! |
-Reorder loops in BRISK to reduce unnecessary values being recomputed
-Utilize lookup tables and a trigonometry identity to reduce the number of calls to sine/cosine
This PR addresses the ideas described in #13390. It's worth noting that this implementation is heavily based off the fork (https://github.com/okriof/opencv/tree/master/modules/features2d/src) from the OP of #13390 - I just omitted the sine/cosine approximation aspect.
Specs:
OS: Linux (Ubuntu 18.04)
Build type: Debug
Compiler: /usr/bin/c++ (ver 7.5.0)
Parallel framework: pthreads (nthreads=8)
CPU features: SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?
Quick Performance Evaluation Test:
Output (original):
0.50843Output (refactor):
0.0477887The refactor is about 10x faster than the original on my machine (specs above), and may yield even better improvements on low power devices.
Update
With @vpisarev suggestion of using sine/cosine approximations for the lookup table, the output time improves to 0.0369674, which is ~13.75x faster.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.